How to take screenshot in selenium?

 Using below function (getScreenShot) you can get screenshot.  

MyMethods.java 


import java.io.File;

import java.io.IOException;


import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.io.FileHandler;


public class ScreenShot {


public static String getScreenShot(String imageName, WebDriver driver) {

TakesScreenshot ts = (TakesScreenshot)driver;

File scrFile = ts.getScreenshotAs(OutputType.FILE);

String path = System.getProperty("user.dir")+"/src/main/resources/unicodeTech/screenshots/"+imageName+System.currentTimeMillis()+".png";

//System.out.println(path);

File destination =new File(path);

    try {

   

    FileHandler.copy(scrFile,destination);

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}    

   

    return path;

}

}

Call above method in your program by writing this:


MyMethods.getScreenShot("WelcomePageAfterLogin (Image name) ", driver);

Comments

Popular posts from this blog

For Get Dynamic data & USe it into Postman Body parameters

What is data driven testing?

API Automation Testing Script to check Response

How to handle frame window in selenium?

How to work with mouse hover menu in selenium?

How does Selenium Webdriver handle SSL certificate in Chrome?