Selenium With Java and Python For Mobile Apps & Web Apps......!

Thursday, 16 April 2015

How to take ScreenShot using Selenium WebDriver.

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.support.events.EventFiringWebDriver;

public class ReportLib {


/**
* To Get Screen Shot If Test case Fail and 
* @throws IOException
*/
public void getsnapShot(String name) throws IOException{
String path="E:\\abc\\xyz\\project1\\TestData\\"+name+".png";

EventFiringWebDriver edriver=new  EventFiringWebDriver(Driver.driver);
File srcimg=edriver.getScreenshotAs(OutputType.FILE);
File dstimg=new File(path);
FileUtils.copyFileToDirectory(srcimg, dstimg);

}

}
For Example:

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews