I am currently setting up PageObject with PageFactory Automation tests. I currently have a screenCapture.java and I try to call the method within the screenCapture when there's an error.
Here is the code from screenCapture:
public void screenshotOnError() throws IOException {
long epoch = System.currentTimeMillis();
String ssTimestamp = String.valueOf(epoch);
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("/Users/sqadan/Desktop/workFiles/maven/MavenProject/screenshots/" + ssTimestamp + ".jpg"));
}
}
and here's the code that's calling the screenshotOnError method:
try {
username.sendKeys(myUsername);
password.sendKeys(myPassword);
loginButton.click();
logs.InfoDetails("Login successful");
}catch (NoSuchElementException e) {
logs.errorDetails("Login unsuccessful");
s.screenshotOnError();
Assert.fail();
}
I currently have this test to purposely fail, but when it does, I get a NPE exception:
java.lang.NullPointerException
at com.acton.util.screenCapture.screenshotOnError(screenCapture.java:24)
at com.acton.team.inbound.actonLogin.doLogin(actonLogin.java:46)