webdriverio/webdriverio

[馃悰 Bug]: No reports if session has already terminated when test fails

Open

#13114 opened on Jul 3, 2024

View on GitHub
聽(7 comments)聽(1 reaction)聽(0 assignees)JavaScript聽(6,029 stars)聽(1,793 forks)batch import
Bug 馃悰help wanted

Description

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.18.2

Node.js Version

20.13.1

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

We sometimes receive "Session not started or terminated" responses from Browserstack.

In these cases no report is written.

This is due to the uncaught exception "invalid session id: A session is either terminated or not started" at https://github.com/webdriverio/webdriverio/blob/16434613fd3dc04667e789bdf276f595552a62e3/packages/wdio-runner/src/index.ts#L451, preventing shutdown from being called

Catching the exception and continuing seems to fix the reports

try {
    // This will throw if a session is already terminated preventing
    // reporters from receiving "runner:end" event
    await this._browser?.deleteSession();
} catch (error) {
    log.error('Error deleting session', error);
}

What is your expected behavior?

No response

How to reproduce the bug.

Sorry, no repro.

I found I was able to reproduce by waiting over 5 minutes before throwing in a test but this is likely something specific to our setup

import { Then } from '@wdio/cucumber-framework'

Then('I blow up very slowly', { timeout: 6 * 60 * 1000 }, async function () {
  await new Promise((resolve) => setTimeout(resolve, 5.1 * 60 * 1000))
  throw new Error('boom')
}

Relevant log output

2024-07-02T12:33:45.283Z WARN webdriver: Request failed with status 200 due to Unable to communicate to node
2024-07-02T12:33:45.859Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:33:45.864Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:33:45.869Z ERROR webdriver: Request failed with status 404 due to WebDriver Error: Session not started or terminated
2024-07-02T12:35:10.937Z WARN webdriver: Request failed with status 200 due to Session not started or terminated
2024-07-02T12:35:11.511Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:35:12.130Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:35:12.712Z ERROR webdriver: Request failed with status 404 due to WebDriver Error: Session not started or terminated
2024-07-02T12:35:43.356Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:35:44.514Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:35:45.101Z WARN webdriver: Request failed with status 404 due to Session not started or terminated
2024-07-02T12:35:45.694Z ERROR webdriver: Request failed with status 404 due to WebDriver Error: Session not started or terminated
2024-07-02T12:35:45.695Z ERROR @wdio/utils:shim: WebDriver Error: Session not started or terminated
    at getErrorFromResponseBody (node_modules/webdriver/build/utils.js:194:12)
    at NodeJSRequest._request (node_modules/webdriver/build/request/index.js:164:23)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:81:29)
    at async Browser.wrapCommandFn (node_modules/@wdio/utils/build/shim.js:81:29)
    at async BrowserstackService._executeCommand (node_modules/@wdio/browserstack-service/build/service.js:353:17)
    at async BrowserstackService.beforeScenario (node_modules/@wdio/browserstack-service/build/service.js:206:9)
    at async Promise.all (index 4)
    at async executeHooksWithArgsShim (node_modules/@wdio/utils/build/shim.js:59:20)
    at async createCustomWorld.<anonymous> (node_modules/@wdio/cucumber-framework/build/index.js:289:13)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Contributor guide