behat-screenshot icon indicating copy to clipboard operation
behat-screenshot copied to clipboard

capture on demand

Open zkent opened this issue 8 years ago • 6 comments

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

zkent avatar Sep 16 '16 18:09 zkent

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. :)

tkotosz avatar Sep 16 '16 19:09 tkotosz

How about And I take a screenshot

zkent avatar Sep 19 '16 13:09 zkent

@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.

elvetemedve avatar Sep 19 '16 14:09 elvetemedve

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 avatar Sep 20 '16 14:09 zkent

@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.

tkotosz avatar Sep 21 '16 13:09 tkotosz

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

grasmash avatar Aug 15 '17 15:08 grasmash