用 Cucumber 截图 [英] Take a screenshot with Cucumber

查看:20
本文介绍了用 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天全站免登陆