0

Im not sure why, but ever time my screenshot is executed, the images are saved as blank. heres the code:

    public void screenshotOnError() throws IOException {
    WebDriver driver = new FirefoxDriver();

    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"));
    }
}

Here's the code that's calling this method:

    @Test
    public websiteProspector_beta doLogin(String myUsername, String myPassword) throws IOException {
    logs.InfoDetails("Logging into Tomcat8- 2092");

    try {
        username.sendKeys(myUsername);
        password.sendKeys(myPassword);
        loginButton.click();


        Assert.assertEquals(driver.getPageSource().contains(cF.homePage), true);
        logs.InfoDetails("Login successful");
    }catch (NoSuchElementException e) {
        logs.errorDetails("Login unsuccessful");
        tU.screenshotOnError();
2

Your screenshot function is creating a new WebDriver instance each time and then taking a screenshot of the default blank page in firefox.

You could try passing in your test's WebDriver instance so you get a picture from your test:

static public void screenShotOnError(WebDriver driver) {
    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"));
}

Then call it as:

tU.screenshotOnError(driver);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.