Best way to take screenshots of tests in Selenium 2?

Viewed 69442

I need a way to take screenshots of my functional tests. Right now I'm using Selenium 2 with C# bindings. I pretty much want to take a screenshot at the end of the test to make sure the desired page is displayed. Are there any particular tools you guys know of that I can incorporate into my C# code that will trigger a screenshot? I couldn't find a built-in Selenium 2 solution (without looking it over).

13 Answers
        ScreenCaptureJob scj;
        scj = new ScreenCaptureJob();
        // Specify the path & file name in which you want to save         
        scj.OutputScreenCaptureFileName = @"C:\Users\jpavankumar\Desktop\Screencaptuere\ScreenRecording4.wmv";
        // Start the Screen Capture Job
        scj.Start(); scj.Stop();

Try this code out here ... hope it will be useful to you .... !

Best way to take screenshot and store in the file location in a generic way in python :

def screenShots(self):
        fileName= NewFile + "." + str(round(time.time() * 1000)) + ".png"
        screenshotDirectory = "../screenshot/"  #Move to that directory where you want ot store the screenshot
        relativeFileName = screenshotDirectory + fileName
        currentDirectory = os.path.dirname(__file__)
        destinationFile = os.path.join(currentDirectory,relativeFileName)
        destinationDirectory = os.path.join(currentDirectory,screenshotDirectory)

        try:
            if not os.path.exists(destinationDirectory):
                os.makedirs(destinationDirectory)
            self.driver.save_screenshot(destinationFile)

            self.log.info("Screenshot saved to directory" + destinationFile)

        except:
            self.log.error("Exception Occured")
            print_stack()
Related