The capture screen method

There are many ways to capture and name the image of the screen. Using the test method name and a timestamp for the image name is a common practice. This aligns the captured screens with the test methods that created them, putting a date on the filename, and so on:

/**
* screenShot - method that takes iTestResult as parameter
*
* @param result - The result of test
* @return String
*/
public static String screenShot(ITestResult result) throws Exception {
DateFormat stamp = new SimpleDateFormat("MM.dd.yy.HH.mm.ss");
Date date = new Date();

ITestNGMethod method= result.getMethod();
String testName = method.getMethodName();

return captureScreen(testName + "_" + stamp.format(date) + ".png");
}

/**
* captureScreen - method to capture the entire screen of the Browser
* or Mobile App
*
* @param filename - The filename to save it to
*/
public static String captureScreen(String filename) throws Exception {
String bitmapPath = "myPath";
WebDriver driver = CreateDriver.getInstance().getCurrentDriver();
File screen = null;

if
( Global_VARS.DEF_ENVIRONMENT.equalsIgnoreCase("remote") ) {
// cast to Augmenter class for RemoteWebDriver
screen = ((TakesScreenshot)new Augmenter().augment(driver))
.getScreenshotAs(OutputType.FILE);
}

else {
screen = ((TakesScreenshot)driver)
.getScreenshotAs(OutputType.FILE);
}

FileUtils.copyFile(screen, new File(bitmapPath + filename));
return filename;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.221.67