Screenshots after every test

36 views
Skip to first unread message

Andre Steenkamp

unread,
Nov 1, 2023, 9:51:26 AM11/1/23
to sele...@googlegroups.com


I’m struggling to create png screenshots after every successful @Test completes and including those screenshots in my allure report.

 

Please help.

 

I’ve tried to put the below under my public class but then the test never finishes and I’m forced to stop the run and only then a test is created but as an xml file.

 

@RegisterExtension
static ScreenShooterExtension screenshotEmAll = new ScreenShooterExtension(true).to(System.getProperty("user.dir") + "/screenshots");

 

Andre Steenkamp
Senior Test Analyst
C: +27 82 923 9140 | T: +27 21 525 3100 
An...@switch.tj | transactionjunction.co.za 

      

The information in this message is confidential and may be legally privileged. It is intended solely for the addressee.  Access to this message by anyone else is unauthorised.  
If you are not the intended recipient, any disclosure, copying, or distribution of the message, or any action or omission taken by you in reliance on it, is prohibited and may be unlawful.  
Please immediately contact the sender if you have received this message in error. 
Thank you.


Andrei Solntsev

unread,
Nov 1, 2023, 5:57:54 PM11/1/23
to Andre Steenkamp, sele...@googlegroups.com
Hi Andre.
Selenide's ScreenShooterExtension takes the screenshots, but doesn't add them to Allure report.
Selenide doesn't know anything about Allure.

BUT

Allure has its own integration with Selenide. See https://selenide.org/documentation/reports.html#allure-report

Andrei Solntsev


ср, 1 нояб. 2023 г. в 15:51, Andre Steenkamp <An...@switch.tj>:
--
You received this message because you are subscribed to the Google Groups "selenide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenide+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenide/JNZP275MB1498F0881F183CA33CEFA81BA4A7A%40JNZP275MB1498.ZAFP275.PROD.OUTLOOK.COM.

Andre Steenkamp

unread,
Nov 2, 2023, 3:44:16 AM11/2/23
to Andrei Solntsev, sele...@googlegroups.com


Hi Andrei,

 

I had this config just not the extra screenshots and savePageSource properties which I have added but I see no difference and no screenshots.

 

@BeforeAll
static void setupAllureReports() {
   
SelenideLogger.addListener("AllureSelenide", new AllureSelenide()
            .
screenshots(true)
            .
savePageSource(true)
    );
}

 

 

I would love to take a screenshot after every @Test block before I move on to the next @Test.

 

Andre Steenkamp
Senior Test Analyst
C: +27 82 923 9140 | T: +27 21 525 3100 
An...@switch.tj | transactionjunction.co.za 

Andrei Solntsev

unread,
Nov 2, 2023, 3:48:41 AM11/2/23
to Andre Steenkamp, selenide
Ok, then your question is about Allure, not Selenide.
I guess this Allure listener by default takes screenshot only after failed tests. 
And probably it has some flag to take screenshots after every test.

Andre Steenkamp

unread,
Nov 2, 2023, 3:51:54 AM11/2/23
to Andrei Solntsev, selenide


I’ve found a way to attach a screenshot to the Allure report, below is just a static png file that I attach if I call this function.

 

@Attachment(value = "screenshot", type = "image/png", fileExtension = ".png")
public byte[] attachScreenshotPNG() throws IOException, IOException {
   
return Files.readAllBytes(Paths.get(System.getProperty("user.dir")+ "/screenshots/image.png"));
}

 

So how can I create a png screenshot file after every test?

 

I can then just pass the location to this function to attach to the Allure report.

Andre Steenkamp

unread,
Nov 2, 2023, 10:03:56 AM11/2/23
to Andrei Solntsev, selenide


I’ve tried adding this but then my tests just hang and it never gets past the first test.

 

It’s like it cannot take the screenshot and just sits there.

 

@AfterEach
void takeScreenshot(){
   
Selenide.screenshot(new Date().toString());
}

 

 

I’m not sure if it is because I’m interacting with an apk on an Android device and if it is not possible to take screenshots?

 

Andre Steenkamp
Senior Test Analyst
C: +27 82 923 9140 | T: +27 21 525 3100 
An...@switch.tj | transactionjunction.co.za 

From: Andre Steenkamp
Sent: Thursday, November 2, 2023 9:52 AM
To: Andrei Solntsev <andrei....@gmail.com>
Cc: selenide <sele...@googlegroups.com>
Subject: RE: Screenshots after every test

 

I’ve found a way to attach a screenshot to the Allure report, below is just a static png file that I attach if I call this function.

 

@Attachment(value = "screenshot", type = "image/png", fileExtension = ".png")
public byte[] attachScreenshotPNG() throws IOException, IOException {
   
return Files.readAllBytes(Paths.get(System.getProperty("user.dir")+ "/screenshots/image.png"));
}

 

So how can I create a png screenshot file after every test?

 

I can then just pass the location to this function to attach to the Allure report.

 

From: Andrei Solntsev <andrei....@gmail.com>

Andrei Solntsev

unread,
Nov 2, 2023, 3:38:21 PM11/2/23
to Andre Steenkamp, selenide
1. This line can take a screenshot, but cannot add it to the Allure report. Again: Selenide doesn't know anything about any reports in the world.
2. If our tests hang, you need to take a thread dump and read it. Then you will know what task is hanging.

Andrei Solntsev


чт, 2 нояб. 2023 г. в 16:03, Andre Steenkamp <An...@switch.tj>:

Andre Steenkamp

unread,
Nov 3, 2023, 4:54:25 AM11/3/23
to Andrei Solntsev, selenide


I think I have some other issue here because if I look at the Appium logs it gets to this point and then just hangs here.

 

I am causing a failure by having an incorrect element to ensure it doesn’t find it.

 

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Calling AppiumDriver.getScreenshot() with args: ["01c15334-b14d-4641-8f17-6026a95b200b"]

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Matched '/screenshot' to command name 'getScreenshot'

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Proxying [GET /screenshot] to [GET http://127.0.0.1:8200/session/83a784ab-0da2-48ce-87fe-85ad3844e913/screenshot] with no body

Andre Steenkamp
Senior Test Analyst

Andre Steenkamp

unread,
Nov 3, 2023, 7:29:47 AM11/3/23
to Andrei Solntsev, selenide


This can be ignored I finally realised what my issue is.

 

It is not allowed on the device I’m using and I only realised that when I looked at the Logcat logs and there it throws an exception when attempting a screenshot.

 

Thanks for all the assistance though!

 

Andre Steenkamp
Senior Test Analyst
C: +27 82 923 9140 | T: +27 21 525 3100 
An...@switch.tj | transactionjunction.co.za 

From: Andre Steenkamp
Sent: Friday, November 3, 2023 10:54 AM
To: Andrei Solntsev <andrei....@gmail.com>
Cc: selenide <sele...@googlegroups.com>
Subject: RE: Screenshots after every test

 

I think I have some other issue here because if I look at the Appium logs it gets to this point and then just hangs here.

 

I am causing a failure by having an incorrect element to ensure it doesn’t find it.

 

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Calling AppiumDriver.getScreenshot() with args: ["01c15334-b14d-4641-8f17-6026a95b200b"]

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Matched '/screenshot' to command name 'getScreenshot'

[debug] [AndroidUiautomator2Driver@3542 (01c15334)] Proxying [GET /screenshot] to [GET http://127.0.0.1:8200/session/83a784ab-0da2-48ce-87fe-85ad3844e913/screenshot] with no body

 

From: Andrei Solntsev <andrei....@gmail.com>

Reply all
Reply to author
Forward
0 new messages