0

I'm trying to create a function to get Screenshot in selenium, at the end of the tests. I am passing 3 parameters "Test result", "Message", "True / False" for the user to decide whether or not to take a print.

However, when executing the function call, it does not take the print off the screen, it generates the HTML with the executed steps, but without the print.

Function

public void escreveRelatorio(boolean status, String msg, boolean printScreen) {

        scenario.write(msg);

        if(printScreen) {
            scenario.embed(((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES), "image/png");
        }

        if(status == false) {
            Assert.fail(msg);
        }

    }

Function call in the middle of the tests.

generic.escreveRelatorio(false, "O número de confirmação foi gerado: " + num, true);

Or

public void validaNumeroConfirmacao() {

    String num = generic.obterTexto(lblConfirmationNumber).substring(23);

    if(!num.equals("1")){
        generic.escreveRelatorio(false, "O número de confirmação foi gerado: " + num, true);
    } else {
        generic.escreveRelatorio(true, "O número de confirmação foi gerado: " + num, true);
    }

}

What am I doing wrong?

Paulo Roberto
  • 1,498
  • 5
  • 19
  • 42

1 Answers1

1

Problem with above example is you are not specifying where your screenshot should save.

Your getScreenshotAs() will return byte[] but you are not doing anything with it.

File scrfile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);    
FileUtils.copyFile(scrfile, new File("/screenshot/SomeUniqueName.png"));
Sumit2500
  • 183
  • 7
  • In this case, do I need to save the physical image and then put it in the Report HTML? I didn't quite understand how to put this in my code. – Paulo Roberto Mar 09 '20 at 13:02