Title:
Allure report not showing screenshots from TestNG Listener
Body:
I’m trying to attach screenshots in my Allure report using a TestNG ITestListener.
Here is my listener code:
@Attachment(value = "Screenshot", type = "image/png")
public static byte[] attachScreenshot(WebDriver driver) {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}
@Override
public void onTestFailure(ITestResult result) {
    WebDriver driver = DriverManager_For_Jenkins.getDriver();
    if (driver != null) {
        attachScreenshot(driver);
    }
}
In my LoginPageTest, I also added:
@Listeners({
        RetryListener.class,
        ScreenshotListener.class,
        io.qameta.allure.testng.AllureTestNg.class
})
public class LoginPageTest extends CommonToAllTest {
    // test methods
}
and in testng.xml:
<listeners>
    <listener class-name="io.qameta.allure.testng.AllureTestNg"/>
    <listener class-name="org.example.listeners.RetryListener"/>
    <listener class-name="org.example.listeners.ScreenshotListener"/>
</listeners>
But when I generate the report with:
allure generate target/allure-results --clean -o target/allure-report
allure open target/allure-report
→ The report runs fine, but no screenshots are shown in the “Attachments” tab.
How can I correctly attach screenshots to Allure reports from a TestNG listener?
The problem was caused by duplicate listener declarations.
I had added ScreenshotListener and RetryListener both in testng.xml and in the test class via @Listeners annotation.
Because of this, the listener was being triggered multiple times and Allure wasn’t attaching the screenshots properly.
Keep the listeners only in one place.
If you want them to apply globally → declare them in testng.xml.
If you want them only for specific classes → use @Listeners annotation.
Do not use both together.
So I removed the @Listeners annotation from my test class and only kept the listeners in testng.xml:
<listeners>
    <listener class-name="io.qameta.allure.testng.AllureTestNg"/>
    <listener class-name="org.example.listeners.RetryListener"/>
    <listener class-name="org.example.listeners.ScreenshotListener"/>
</listeners>
After running tests and regenerating the report, screenshots started appearing under the “Attachments” section in Allure. ✅