Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

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

1 Answer

0 votes
by (62.9k points)

I describe taking a screenshot in Selenium as a three-step process, you can follow the below steps:

 Step 1) Convert web driver object to TakeScreenshot

TakesScreenshot scrShot =((TakesScreenshot)webdriver);

Step 2) Calling getScreenshotAs method which will create an image file

 File SrcFile=scrShot.getScreenshotAs(OutputType.FILE);

Step 3) Copy file to Desired Location

Example: In this example, we will take a screen capture of & save it as C:/Test.png

package IntellipaatScreenshot;



import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class IntellipaatScreenshot {



    public void testIntellipaatScreenShot() throws Exception{


WebDriver driver ;


     driver = new FirefoxDriver();


        //goto url




        //Call take a screenshot function


        this.takeSnapShot(driver, "c://test.png") ;     



   * This function will take a screenshot


     * @param webdriver


     * @param fileWithPath


     * @throws Exception


    public static void takeSnapShot(WebDriver webdriver,String fileWithPath) throws Exception{


        //Convert web driver object to TakeScreenshot


        TakesScreenshot scrShot =((TakesScreenshot)webdriver);


        //Call getScreenshotAs method to create an image file




            //Move image file to the new destination


                File DestFile=new File(fileWithPath);


                //Copy file at the destination


                FileUtils.copyFile(SrcFile, DestFile);






Browse Categories