4

I see a post was made for this here How to capture a screenshot after each step in tests with JAVA and Cucumber?

But, what I would like to do is be able to take a screenshot after every single action taken even within a single Cucumber step and embed into the Cucumber report. In other words, there are multiple actions taken in a single step to satisfy that step and I would like to embed the screenshot for all of them. Is this possible? If so, how?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ihossain
  • 343
  • 1
  • 8
  • 19
  • Solved it by doing scenario.embed(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES), "image/png"); in every page object – ihossain Jun 03 '18 at 07:52

1 Answers1

4

You can use the @BeforeStep or @AfterStep cucumber annotation in your hook class and then call you screenshot method inside it.

public class Hooks{
    @BeforeStep
    public void beforeEachStep(){
        takeScreenshot();
    }
}
AleT
  • 90
  • 7