Cucumber / Java:如何在失败方案屏幕截图名称中包含要素文件编号

时间:2017-07-30 10:47:44

标签: java selenium-webdriver cucumber cucumber-jvm

我正致力于使用Cucumber + Selenium和Java捕获Passed / Failed场景的最终屏幕的框架。

我已将方案名称嵌入为屏幕截图名称,以便于识别。但是,想要甚至向下钻取并想要捕获功能文件行编号,确切地说发生了故障。请建议我如何将要素文件行号作为屏幕截图名称。

public void tearDown(Scenario scenario) throws InterruptedException {
    if (scenario.isFailed()) {
        Thread.sleep(2000);
        try {
            driver.switchTo().alert().accept();
            // driver.quit();
            Thread.sleep(2000);
        } catch (Exception NoAlertPresentException) {
        }
        try {

         WebDriver augmentedDriver = new Augmenter().augment(driver);
        File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);

        String path = "./target/cucumber/FailedScreenshots/" +  scenario.getName()+".png";
        FileUtils.copyFile(source, new File(path)); 

    } catch (Exception e ){
        e.printStackTrace();
    }

 //driver.quit();
    driver.close();
    Browser_Initilization.driver = null;
} else {
    try {

         WebDriver augmentedDriver = new Augmenter().augment(driver);
        File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
        String path = "./target/cucumber/Passed ScreenShots/" + scenario.getName() +".png";
        FileUtils.copyFile(source, new File(path)); 

    } catch (Exception e ){
        e.printStackTrace();
    }

}


}

}

0 个答案:

没有答案