webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.04k stars 2.5k forks source link

[🐛 Bug]: Unable to attach screenshot to Allure report with Jasmine Framework #11115

Closed sairam9994 closed 1 year ago

sairam9994 commented 1 year ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.16.4

Node.js Version

18.16.0

Mode

Standalone Mode

Which capabilities are you using?

package.json:
{
        "chromedriver": "^109.0.0",
        "wdio-chromedriver-service": "^8.1.1",
        "@wdio/allure-reporter": "^8.16.3",
        "@wdio/cli": "^8.16.4",
        "@wdio/jasmine-framework": "^8.16.4",
        "@wdio/local-runner": "^8.16.4",
        "@wdio/spec-reporter": "^8.16.3",
        "allure-commandline": "^2.24.0",
        "webdriverio": "^8.16.4"
}
wdio.conf.js:
capabilities: [{
        maxInstances: 6,
        browserName: 'chrome',
        browserVersion: 'stable',
        acceptInsecureCerts: true,
        'goog:chromeOptions': {
            args: [
                '--no-sandbox',
                '--disable-infobars',
                '--headless',
                '--disable-gpu',
                '--window-size=1440,735',
                '--disable-colors',
                '--disable-translate',
                '--disable-dev-shm-usage',
                '--disable-extensions',
                '--enable-clipboard',
                'disable-popup-blocking', 'disable-notifications',
                '--allow-site-access-from-files'
            ]},

 reporters: [
        ['allure', {
            outputDir: 'allure-results',
            disableWebdriverStepsReporting: true,
            disableWebdriverScreenshotsReporting: false,
            addConsoleLogs:true
        }],
    ]

What happened?

Unable to attach screenshots to allure report after adding the takeScreenshot in afterTest hook in the wdio.confg.js

What is your expected behavior?

After test execution failed, It should attach screenshot as per afterTest hook in Allure Report. I can add console log but no screenshot for failures.

How to reproduce the bug.

I've attached the versions & wdio.conf.js file. wdio.conf.js: capabilities: [{ maxInstances: 6, browserName: 'chrome', browserVersion: 'stable', acceptInsecureCerts: true, 'goog:chromeOptions': { args: [ '--no-sandbox', '--disable-infobars', '--headless', '--disable-gpu', '--window-size=1440,735', '--disable-colors', '--disable-translate', '--disable-dev-shm-usage', '--disable-extensions', '--enable-clipboard', 'disable-popup-blocking', 'disable-notifications', '--allow-site-access-from-files' ]},

reporters: [ ['allure', { outputDir: 'allure-results', disableWebdriverStepsReporting: true, disableWebdriverScreenshotsReporting: false, addConsoleLogs:true }], ], onComplete: function() { const reportError = new Error('Could not generate Allure report') const generation = allure(['generate', 'allure-results', '--clean']) return new Promise((resolve, reject) => { const generationTimeout = setTimeout( () => reject(reportError), 5000)

        generation.on('exit', function(exitCode) {
            clearTimeout(generationTimeout)

            if (exitCode !== 0) {
                return reject(reportError)
            }

            console.log('Allure report successfully generated')
            resolve()
        })
    })
},
afterTest: async function (test, context, { error, result, duration, passed, retries }) {
    if (!passed) {
        await browser.takeScreenshot();
    }

}, framework: 'jasmine',

Relevant log output

I don't see much related to afterTest hook issue. I've updated config entry logLevel: 'trace' to get more info about the execution.

at getErrorFromFailedTest (file://node_modules/@wdio/allure-reporter/build/utils.js:78:15)
    at AllureReporter.onTestFail (file:///node_modules/@wdio/allure-reporter/build/reporter.js:332:31)
    at AllureReporter.<anonymous> (file:////node_modules/@wdio/reporter/build/index.js:119:18)
    at AllureReporter.emit (node:events:513:28)
    at AllureReporter.emit (node:domain:489:12)
    at file:///node_modules/@wdio/runner/build/reporter.js:47:56
    at Array.forEach (<anonymous>)
    at BaseReporter.emit (file:///node_modules/@wdio/runner/build/reporter.js:47:25)
    at JasmineReporter.emit (file:///node_modules/@wdio/jasmine-framework/build/reporter.js:175:24)
    at JasmineReporter.specDone (file:///node_modules/@wdio/jasmine-framework/build/reporter.js:105:14)
    at UserContext.fn (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7976:23)
    at QueueRunner.attempt (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7798:40)
    at QueueRunner.run (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7836:27)
    at QueueRunner.execute (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7690:10)
    at queueRunnerFactory (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1561:35)
    at node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1598:16
    at node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7950:9
    at new Promise (<anonymous>)
    at dispatch (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7949:14)
    at ReportDispatcher.specDone (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7918:18)
    at reportSpecDone (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1872:16)
    at SuiteBuilder.specResultCallback [as specResultCallback_] (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1861:7)
    at Spec.resultCallback (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:10390:16)
    at UserContext.fn (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:837:14)
    at QueueRunner.attempt (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7809:40)
    at QueueRunner.run (node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7836:27)
    at runNext (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7740:16)
    at /node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7746:11
    at /node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7636:9
    at onPromiseRejection (/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:7824:7)

Code of Conduct

Is there an existing issue for this?

christian-bromann commented 1 year ago

@epszaw @BorisOsipov any ideas?

epszaw commented 1 year ago

Will investigate the problem as soon as possible 👍

sairam9994 commented 1 year ago

Hi, Could you please let me know if any update on the issue?

epszaw commented 1 year ago

Don't have any update for now

BorisOsipov commented 1 year ago

@sairam9994 Could you please create a reproducible example via https://webdriver.io/docs/gettingstarted and share it with us via github repo?

nikhilgupta1789 commented 1 year ago

I am also facing issue of not able to see the screenshot in the report after following all required configuration/settings for @wdio/allure-reporter, after upgrading it to the latest version 8.16.3. Kindly please fix this issue as we're not able to see screenshot in the report and have to share execution result to the client. @BorisOsipov @epszaw could you guys please have a look into this issue as we're blcoked with this issue.

SpencerChilds commented 1 year ago

Try

afterTest: async function (test, context, { error, result, duration, passed, retries }) { if (!passed) { allureReporter.addAttachment('Screenshot', Buffer.from(await browser.takeScreenshot(), 'base64'), 'image/png'); }

as a workaround.

sairam9994 commented 1 year ago

I'm getting cannot read property error while running test. Any suggestions here?

[0-0] 2023-09-12T16:45:36.349Z ERROR @wdio/utils:shim: TypeError: Cannot read properties of undefined (reading 'addAttachment')
[0-0]     at Object.afterTest (/wdio.conf.js:335:28)
[0-0]     at file:///node_modules/@wdio/utils/build/shim.js:31:27
[0-0]     at new Promise (<anonymous>)
[0-0]     at file://node_modules/@wdio/utils/build/shim.js:28:47
[0-0]     at Array.map (<anonymous>)
[0-0]     at executeHooksWithArgsShim (file:///node_modules/@wdio/utils/build/shim.js:28:33)
[0-0]     at UserContext.testFrameworkFnWrapper (file:///node_modules/@wdio/utils/build/test-framework/testFnWrapper.js:60:46)
[0-0] 2023-09-12T16:45:36.349Z DEBUG @wdio/utils:shim: Finished to run "afterTest" hook in 12ms
[0-0] Error in "AfterTest Hook"
Cannot read properties of undefined (reading 'addAttachment')

wdio.conf.js

const { allureReporter } = require('@wdio/allure-reporter');

    afterTest: async function (test, context, { error, result, duration, passed, retries }) {
        if (!passed) {
            allureReporter.addAttachment('Screenshot', Buffer.from(await browser.takeScreenshot(), 'base64'), 'image/png');
        }
    },
SpencerChilds commented 1 year ago

Try

CJS

const allureReporter = require('@wdio/allure-reporter').default

ESM

import allureReporter from '@wdio/allure-reporter'

nikhilgupta1789 commented 1 year ago

Try

afterTest: async function (test, context, { error, result, duration, passed, retries }) { if (!passed) { allureReporter.addAttachment('Screenshot', Buffer.from(await browser.takeScreenshot(), 'base64'), 'image/png'); }

as a workaround.

Doing by this every time we have to download the screenshot, this is temporary fix. Can we get the earlier behavior by which we can directly access the attach screenshot without needing of downloading it and can quickly access and see the screenshot.

christian-bromann commented 1 year ago

@sairam9994 any updates on the reproducible example?

christian-bromann commented 1 year ago

Closing, as no reproducible example can be provided.