Answers for "selenium take screenshot when test fail java"

1

how to take failed screenshot in selenium

HOW TO TAKE SCREENSHOT FOR FAILED SCENARIOS

I have a tearDown method in my Hooks Class. 
I keep my screenshot codes in it. It takes screenshot
as soon as any scenario fails.

	@After
	public void tearDown(Scenario scenario) {
   if(scenario.isFailed()) {
  TakesScreenshot screen=(TakesScreenshot)Driver.getDriver();
  final byte[] screenshot = 
      screen.getScreenshotAs(OutputType.BYTES); ==> taking screenshot
  scenario.embed(screenshot, "image/png"); 
              ==> adding screenshot to the report 
    }
	}
Posted by: Guest on January-14-2021
0

how to take screenshot in failed test scenarios

HOW TO TAKE SCREENSHOT IN ANY TEST CASE WITHOUT FAILURE

 TakesScreenshot screen=(TakesScreenshot)Driver.getDriver();
 File screenshot=screen.getScreenshotAs(OutputType.FILE);
 FileUtils.copyFile(screenshot, new File("<your folder path here>"));
 
 HOW TO TAKE SCREENSHOT FOR FAILED SCENARIOS

I have a tearDown method in my Hooks Class. 
I keep my screenshot codes in it. It takes screenshot
as soon as any scenario fails.

	@After
	public void tearDown(Scenario scenario) {
   if(scenario.isFailed()) {
  TakesScreenshot screen=(TakesScreenshot)Driver.getDriver();
  final byte[] screenshot = 
      screen.getScreenshotAs(OutputType.BYTES); ==> taking screenshot
  scenario.embed(screenshot, "image/png"); 
              ==> adding screenshot to the report 
    }
	}
Posted by: Guest on January-14-2021

Code answers related to "selenium take screenshot when test fail java"

Browse Popular Code Answers by Language