Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

How to take screen shot on both test cases "Positive and Negative" results.

NOTE: Currently, iam working in selenium webdriver (junit) and i didnt have an idea about how to code for adding methods to take screen shots.

Thanks in Advance.

share|improve this question

2 Answers 2

Take the screenshot in the @After test tear down method, which is run after every test. This way you will always get a screenshot for both passed and failed tests.

public class TestSample
    static WebDriver driver;

    public void setUp() {
        //start new webdriver session, for eg using firefox
        driver = new FirefoxDriver();

    public void aTest() {
        //more test logic  - test might pass or fail at this point

    public void tearDown() {
        // take the screenshot at the end of every test
        File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        // now save the screenshto to a file some place
        FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

    //quit WebDriver session
share|improve this answer

I am not sure how to do it manually, but there's a testing framework (thucydides) that can do what you need:


This tool in fact integrates Selenium Webdriver with other tools to make your life easier.

You can setup a test maven project quite fast. Since it is open-source, you could check how they capture the screenshots if you don't want to mess with another tool. However, I must say that working with such a tool makes life much easier...

share|improve this answer
Martin, it would help if you explicitly stated that Thucydides extends Webdriver. Someone who has never heard of that particular tool could think your response wasn't relevant to the question. –  Kate Paulk Nov 13 '13 at 18:20
Thanks for the comment, will edit the post... :) –  Martin Nov 14 '13 at 9:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.