Selenium的截图方法

阅读 89

2022-08-02

package com.gloryroad.Demo;



import java.io.File;



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.firefox.FirefoxDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;







public class CaptureScreenInCurrentWindow {

String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/selection.html";

public WebDriver driver;

@BeforeMethod

public void setUp(){

driver=new FirefoxDriver();

driver.get(url);


}



@AfterMethod

public void tearDown(){

driver.close();

}


@Test

public void capture(){

File scrFile=((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

try {

FileUtils.copyFile(scrFile, new File("test-output/1.png"));

} catch (Exception e) {

// TODO: handle exception

}



}




}

精彩评论(0)

0 0 举报