You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Screenshot is not attached to Allure when executing it in beforeTestStop() method. #813
Describe the bug
I want to attach the screenshot of failed test to the Allure report. I used TestNG's ITestListener interface's onTestFailure() method first and see the attachment file is visible in the allure-results folder yet not visible in the report itself. After that, I implement the solution suggested here: #444
The attachment file is not visible both in the allure-results folder and report itself. When I debugged I saw that it executes the onTestFailure() method but beforeTestStop() is not executed.
You can see my implementation below.
public class TestListener implements ITestListener, TestLifecycleListener {
ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
@Override
public void onTestStart(ITestResult result) {
System.out.printf("Test started: %s\n", result.getName());
}
@Override
public void onTestSuccess(ITestResult result) {
System.out.printf("Test passed: %s\n", result.getName());
}
@Override
public void onTestFailure(ITestResult result) {
System.out.printf("Test failed: %s\n", result.getName());
WebDriver driver = ((BaseTest) result.getInstance()).getDriver();
drivers.set(driver);
}
@Override
public void beforeTestStop(TestResult result) {
if(result.getStatus().name().equalsIgnoreCase("FAILED")) {
takeScreenshot(drivers.get());
}
}
private void takeScreenshot(WebDriver driver) {
Allure.addAttachment("Screenshot of failed step", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}
@Attachment(value = "Page screenshot", type = "image/png")
private byte[] saveScreenshot(WebDriver driver) {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return screenshot;
}
}
Expected behavior
I want to see the screenshot of failed test in the Allure report.
Reacted by michalw666, calvario31, SoLsysTeMus and Volodymyr Shumara
I have the same issue... tryt to ge the screenshot on test start and on test failure but on both cases says the same log message:
[main] ERROR io.qameta.allure.AllureLifecycle - Could not add attachment: no test is running
[main] ERROR io.qameta.allure.AllureLifecycle - Could not add attachment: no test is running
Maybe is related to the browser version? I run on a previous framework I have locally and it also didnt get the screenshot (same error) even if they have old dependencies and previously was working
Describe the bug I want to attach the screenshot of failed test to the Allure report. I used TestNG's ITestListener interface's onTestFailure() method first and see the attachment file is visible in the allure-results folder yet not visible in the report itself. After that, I implement the solution suggested here: #444 The attachment file is not visible both in the allure-results folder and report itself. When I debugged I saw that it executes the onTestFailure() method but beforeTestStop() is not executed.
You can see my implementation below.
public class TestListener implements ITestListener, TestLifecycleListener {
ThreadLocal<WebDriver> drivers = new ThreadLocal<>();
@Override
public void onTestStart(ITestResult result) {
System.out.printf("Test started: %s\n", result.getName());
}
@Override
public void onTestSuccess(ITestResult result) {
System.out.printf("Test passed: %s\n", result.getName());
}
@Override
public void onTestFailure(ITestResult result) {
System.out.printf("Test failed: %s\n", result.getName());
WebDriver driver = ((BaseTest) result.getInstance()).getDriver();
drivers.set(driver);
}
@Override
public void beforeTestStop(TestResult result) {
if(result.getStatus().name().equalsIgnoreCase("FAILED")) {
takeScreenshot(drivers.get());
}
}
private void takeScreenshot(WebDriver driver) {
Allure.addAttachment("Screenshot of failed step", new ByteArrayInputStream(((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES)));
}
@Attachment(value = "Page screenshot", type = "image/png")
private byte[] saveScreenshot(WebDriver driver) {
byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
return screenshot;
}
}
Expected behavior I want to see the screenshot of failed test in the Allure report.
Activity
michalw666 commentedon Sep 8, 2022
I have the same issue with beforeTestStop() method. Please advice.
calvario31 commentedon Sep 11, 2022
I have the same issue... tryt to ge the screenshot on test start and on test failure but on both cases says the same log message:
Maybe is related to the browser version? I run on a previous framework I have locally and it also didnt get the screenshot (same error) even if they have old dependencies and previously was working
SoLsysTeMus commentedon Sep 14, 2022
I have the same issue
calvario31 commentedon Sep 14, 2022
I made it to work on this repo https://github.com/calvario-31/SeleniumJavaCompleteFramework/blob/main/src/main/java/listeners/AllureListeners.java but had to use a static driver
baev commentedon Mar 19, 2024
see #707 (comment)