Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
216 views
in Framework-FAQ by The go-to Tester (181 points)

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

We use TestNG Assert to check if step is passed or failed, if step is failed, it comes to catch block and we have method in reports called TestStep and we mark isPassed parameter as failed, in that case it will take screenshot using below line of code.

 

public static String captureScreenshot(WebDriver driver,
String screenshotdir) throws IOException {
String randomUUID = UUID.randomUUID().toString();
String storeFileName = screenshotdir + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
String[] screenshotdirsplit = screenshotdir.split("\\\\");
String fileName = screenshotdirsplit[screenshotdirsplit.length - 1] + "\\"
+ getFileNameFromURL(driver.getCurrentUrl()) + "_"
+ randomUUID + ".png";
File scrFile = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(storeFileName));
return fileName;
}


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...