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

API Automation Testing Script to check Response

Login through Data Driven Testing in selenium

Which dependencies needed in pom.xml while doing automation through selenium?

Download Java(JDK) & Eclipse IDE for selenium

What is data driven testing?

How to extract all the links in selenium?