使用Cucumber截屏 [英] Take a screenshot with Cucumber

查看:109
本文介绍了使用Cucumber截屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是学习如何使用黄瓜。
您能告诉我如何完成此代码吗?

I just learn how to use cucumber. Can you tell me how to complete this code?

您可以使用以下代码段为未定义的步骤实现步骤定义:

You can implement step definitions for undefined steps with these snippets:

Then /^I take a screenshot$/ do
    pending # express the regexp above with the code you wish you had
end


推荐答案

通常在发生意外情况时截屏。您可能还想捕获屏幕快照,以便在测试用例失败时进行报告。在这种情况下,您应该在将在每种情况下执行的@After 方法。 Java,硒版本

Screenshots in general are taken when something unexpected occurs. You may also want to capture a screenshot to report when a test case fails. In this particular case, you should have screenshot capture logic in an @After method that will be executed for every scenario. A Java, selenium version,

@After("@browser")
public void tearDown(Scenario scenario) {
    if (scenario.isFailed()) {
            final byte[] screenshot = ((TakesScreenshot) driver)
                        .getScreenshotAs(OutputType.BYTES);
            scenario.embed(screenshot, "image/png"); //stick it in the report
    }
    driver.close();
}

这篇关于使用Cucumber截屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆