Skip to content

Commit

Permalink
Taking screenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
angiejones committed Jul 11, 2019
1 parent 1e53b1f commit 48f9406
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions webdriver_java/src/test/java/base/BaseTests.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package base;

import com.google.common.io.Files;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import pages.HomePage;
import utils.WindowManager;

import java.io.File;
import java.io.IOException;

public class BaseTests {

private WebDriver driver;
Expand All @@ -31,6 +39,20 @@ public void tearDown(){
driver.quit();
}

@AfterMethod
public void recordFailure(ITestResult result){
if(ITestResult.FAILURE == result.getStatus())
{
var camera = (TakesScreenshot)driver;
File screenshot = camera.getScreenshotAs(OutputType.FILE);
try{
Files.move(screenshot, new File("resources/screenshots/" + result.getName() + ".png"));
}catch(IOException e){
e.printStackTrace();
}
}
}

public WindowManager getWindowManager(){
return new WindowManager(driver);
}
Expand Down

0 comments on commit 48f9406

Please sign in to comment.