webdriverio/webdriverio

Enhancement: Attach the screenshot to each node in the step() tree.

Open

#11.934 aperta il 26 dic 2023

Vedi su GitHub
 (5 commenti) (0 reazioni) (0 assegnatari)JavaScript (1793 fork)batch import
help wantedwdio-allure-reporter

Metriche repository

Star
 (6029 star)
Metriche merge PR
 (Merge medio 15g 15h) (48 PR mergiate in 30 g)

Descrizione

In the Click() method show below, I intend to attach a screenshot to each node within the parent step node. However, in the report, it appears both screenshots are attached to the parent step node.

Enhancement: It would be nice if one of more attachments can be attached to a related node, and display the attachment with the name passed to the method.

Note: Four .png attachments are created in ./allure-results folder. Why?

` /** * Clicks on a WebdriverIO element and logs the action in the Allure report. * * @param {WebdriverIO.Element} element - The element to be clicked. * @returns {Promise} - A promise that resolves once the element is clicked. * * @example * await click(buttonElement); */

async click(element: WebdriverIO.Element): Promise<void> {
    try {
        const elementText = await element.getText();
        const stepDescription = (elementText ? elementText : element.selector).toString();
        await allureReporter.step(`Click on ${stepDescription}`, async (s1) => {
            await s1.step('Before click', async () => {
                const sanitizeStepDescription = stepDescription.replace(/ /g, ''); // Remove spaces
                const timestamp = new Date().toISOString().replace(/[:.]/g, ''); // Generate a timestamp without special characters
                const screenshotFileName = `${sanitizeStepDescription}_${timestamp}.png`;
                const screenshotPath = `./reports/ui/allure-results/${screenshotFileName}`;
                s1.attach(await browser.saveScreenshot(screenshotPath), 'image/png');
            });
            //
            await element.click()
            await s1.step('After click', async () => {
                const sanitizeStepDescription = stepDescription.replace(/ /g, ''); // Remove spaces
                const timestamp = new Date().toISOString().replace(/[:.]/g, ''); // Generate a timestamp without special characters
                const screenshotFileName = `${sanitizeStepDescription}_${timestamp}.png`;
                const screenshotPath = `./reports/ui/allure-results/${screenshotFileName}`;
                s1.attach(await browser.saveScreenshot(screenshotPath), 'image/png');
            });
        });
    } catch (error) {
        // Handle the error and add it to the step reporter
        await allureReporter.step(`Failed to click on element: ${error.message}`, async () => {
        // Your error handling logic here, if needed
        });
        throw error; // Re-throw the error to propagate it further, if necessary
    }
}

2023-12-25_14-23-38wdio 2023-12-25_14-22-11allureRepor 2023-12-25_18-21-05 `

Guida contributor