0
点赞
收藏
分享

微信扫一扫

Selenium的截图方法

婉殇成长笔记 2022-08-02 阅读 89

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 条评论