Cucumber Java screenshots(黄瓜 Java 截图)
问题描述
Is there a way to take screenshots in between steps in Java Cucumber ?
I have the following scenario :
@Scenario_1
Given I log into url
And I see the home page is displayed in English //Take screenshot
And I click on 'Edit Profile'
And I see the language set to 'English'
When I change the language to Chinese //Take screenshot
And I navigate to home page
Then everything is displayed in Chinese //Take screenshot
I want to take screenshots for certain steps of the scenario.
I am currently taking a screenshot in the 'After' method.
@After()
public void execute_after_every_scenario(Scenario s) throws InterruptedException
{
Thread.sleep(2000);
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
s.embed(screenshot, "image/png");
driver.quit();
}
As expected, this is capturing the image for the last step only.
How can I capture the images for the other 2 steps and embed the image the same way as in the 'After' method ?
I tried to create a new method to take screenshots and call that method when needed. But can any other method , other than the one specified in 'After' , take scenario as an argument ?
take_screenshot(Scenario_1, driver);
public void take_screenshot(Scenario s,WebDriver driver)
{
final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
s.embed(screenshot, "image/png");
}
How can I go about this ?
Create a screenshot step. Maybe something like this:
public class YourStepDefinitions {
private Scenario myScenario;
@Before()
public void embedScreenshotStep(Scenario scenario) {
myScenario = scenario;
}
@Then ("^I take a screenshot$")
public void i_take_a_screenshot() throws Throwable {
try {
myScenario.write("Current Page URL is " + driver.getCurrentUrl());
byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
myScenario.embed(screenshot, "image/png"); // Stick it in the report
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
log.error(somePlatformsDontSupportScreenshots.getMessage());
} catch (ClassCastException cce) {
cce.printStackTrace();
}
}
}
这篇关于黄瓜 Java 截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:黄瓜 Java 截图
基础教程推荐
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01