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
You can use canned steps (pre-defined) to take screenshot.
There is not need for any step definition. Cucumber also comes with many other pre-defined steps. See other canned steps
If you still need to write step definition.
If you are using watir-webdriver for your testing you can call the screenshot method on your browser object and save it. http://watirwebdriver.com/screenshots/
If you are doing windows controls you could use the win32/screenshot gem to achieve this.https://github.com/jarmo/win32screenshot
I am providing the code which will take the snapshot when scenario is failed, I hope you can modify according to your uses, Comment here if you can't do that. This code is in ruby with Ubuntu system
An improved version of the previous answer. This has error handling, writing out the URL at the failure point. Thought it might be useful.
In Java you can implement this step like so,
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,