elvetemedve/behat-screenshot

capture on demand

Opened this issue · 6 comments

zkent commented

How do I capture a screenshot on demand? I have it working on error.

You can use the 'all_scenarios' option of the screenshot_taking_mode config (see readme) to take combined screenshot of all scenarios regardless of failing or not. This is the only option currenly, but if you have an idea what should be added (maybe a new behat switch like --take-screenshot-on=rownumber) then please let us know and we will implement it or feel free to create a pr. :)

zkent commented

How about
And I take a screenshot

@zkent What is the use case for taking screenshots when no error happened?
This extension is intended to give help in debugging, but if there is no error, I don't see what do you want to debug then.
BTW you are free to throw an exception from any steps to trigger a failing test and therefore a screenshot creation.

zkent commented

Mostly when debugging and creating new scenarios. I guess the exception trick works if I am creating a custom step but not if using built in steps functions.

@zkent when you are using built in steps then you can add a screenshot taking step right after the step which you would like to debug.
You can define a new "And I take a screenshot" step like this in your context file:

   /**
     * @Then I take a screenshot
     */
    public function iTakeAScreenshot()
    {
        throw new \Exception('stop!');
    }

Then if you add the "And I take a screenshot" step after the step which you want to debug then the screenshot will contain the image of the previous step.

It would be nice if the Then I take a screenshot step were non-fatal.