Search code examples
javascriptallure

How do I add an image to an Allure report with addattachment on JS?


I'm trying to add the screenshots to my allure reports between steps, but in my case is that the test cases are manually created from the IDE with Allure TestOps plugin. How do I modify this code to use the existing screenshots (eg uploaded to the GH repo) just to display it in the allure report and not to take screenshots?

const png = await browser.takeScreenshot() allure.createAttachment('screenshot',new Buffer(png,'base64'),'image/png')

I tried to use const img = new image(); img.src = ... but it doesn't work.


Solution

  • May be this can help

    // Import the fs module to read the file
    const fs = require("fs");
    
    // Read the file into a Buffer object
    const screenshotBuffer = fs.readFileSync("path/to/screenshot.png");
    
    // Add the screenshot to the Allure report
    allure.createAttachment("screenshot", screenshotBuffer, "image/png");