Take a screenshot with Cucumber

后端 未结 6 809
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 17:31

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:



        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 18:01

    An improved version of the previous answer. This has error handling, writing out the URL at the failure point. Thought it might be useful.

    @After("@UI" )
    public void embedScreenshotOnFail(Scenario s) {
        if (s.isFailed()) {
            try {
                byte[] screenshot = ((TakesScreenshot) getDefaultDriver()).getScreenshotAs(OutputType.BYTES);
                s.embed(screenshot, "image/png" );
                s.write("URL at failure: " + getDefaultDriver().getCurrentUrl());
            } catch (WebDriverException wde) {
                s.write("Embed Failed " + wde.getMessage());
            } catch (ClassCastException cce) {
                cce.printStackTrace();
            }
        }
    }
    

提交回复
热议问题