如何使用Selenium Webdriver获取屏幕截图?

时间:2018-10-05 13:15:38

标签: java selenium webdriver screenshot

我需要逐步获取Selenium Webdriver代码的屏幕截图,但是当我插入getscreenshot代码时,我的测试停止了。

代码:

public class Rule {

protected static WebDriver driver;

public void getscreenshot(String folder, String file) throws Exception {      

    File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     FileUtils.copyFile(screenshotFile, new File("Evidencias\\"+folder+"\\"+file+".png"));
}}

按班上课:

public class Steps extends Execute {

@Given("acessei a url do portal")
public void AcessoUrl() {
       Execute Executar = new Execute();
       Executar.abrirBrowser();
}

@And("cliquei no botao de Login com email")
public void Login() throws Exception {
    Execute Executar = new Execute();
    getscreenshot("Login","01 - Acessando URL"); 
    Executar.Login();

我该如何解决?谢谢

1 个答案:

答案 0 :(得分:0)

您可以将google用于此类常见问题。

您在这里:https://www.guru99.com/take-screenshot-selenium-webdriver.html