selenium webdriver 截屏操作

有时候我们需要进行截屏操作,特别是遇到一些比较重要的页面信息(出现错误)或者出现不同需要进行对比时,

我们就需要对正在处理的页面进行截屏!

未经作者允许,禁止转载!

package test_wait20161205;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class screen_shot20161205 {

    public static void main(String[] args) throws InterruptedException, IOException {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chorme.driver", "C:\\Training\\Automation\\Software\\drivers\\chromedriver_win32\\chromedriver.exe");和上面一行是连着的
        WebDriver driver=new ChromeDriver();
        driver.get("https://www.hao123.com/");
        Thread.sleep(1000);
        
        File screenshot=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);-------------------------截屏操作        
        FileUtils.copyFile(screenshot, new File("C:\\Users\\chenjia\\Desktop\\screenshots1.jpg"));----------保存图片
        
        System.out.println("将截屏的图片保存在桌面");
                
    }

}

 

Book Description Selenium WebDriver is an open source automation tool implemented through a browser-specific driver, which sends commands to a browser and retrieves results. The latest version of Selenium 3 brings with it a lot of new features that change the way you use and setup Selenium WebDriver. This book covers all those features along with the source code, including a demo website that allows you to work with an HMTL5 application and other examples throughout the book. Selenium WebDriver 3 Practical Guide will walk you through the various APIs of Selenium WebDriver, which are used in automation tests, followed by a discussion of the various WebDriver implementations available. You will learn to strategize and handle rich web UI using advanced WebDriver API along with real-time challenges faced in WebDriver and solutions to handle them. You will discover different types and domains of testing such as cross-browser testing, load testing, and mobile testing with Selenium. Finally, you will also be introduced to data-driven testing using TestNG to create your own automation framework. By the end of this book, you will be able to select any web application and automate it the way you want. What you will learn Understand what Selenium 3 is and how is has been improved than its predecessor Use different mobile and desktop browser platforms with Selenium 3 Perform advanced actions, such as drag-and-drop and action builders on web page Learn to use Java 8 API and Selenium 3 together Explore remote WebDriver and discover how to use it Perform cross browser and distributed testing with Selenium Grid Use Actions API for performing various keyboard and mouse actions Who this book is for Selenium WebDriver 3 Practical Guide is for software quality assurance/testing professionals, software project managers, or software developers interested in using Selenium for testing their applications. Prior programming experience in Java is necessary. Table of Contents Introducing WebDriver and WebElements Working with Browser Drivers Using Java 8 features along with Selenium Exploring the Features of WebDriver Exploring Advanced Interactions of WebDriver Understanding WebDriver Events Exploring RemoteWebDriver Setting up Selenium Grid The PageObject Pattern Mobile Testing on iOS and Android using Appium Data Driven Testing with TestNG Assessments
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值