modernweb-dev / web

Guides, tools and libraries for modern web development.
https://modern-web.dev
MIT License
2.21k stars 281 forks source link

Browserstack launcher: "WebDriver Error: Timed out waiting for asyncrhonous script" on iOS devices #2706

Open gruhn opened 5 months ago

gruhn commented 5 months ago

Bug Description

When I run tests on iOS devices (iPhone/iPad) using the Browserstack launcher AND in the web-test-runner config concurrency is set to something >1, then I get the following error:

[Browserstack] Setting up Browserstack Local proxy...

2024-04-19T12:25:59.180Z ERROR webdriver: Request failed with status 500 due to WebDriver Error: Timed out waiting for asyncrhonous script result after 0 ms
index.html:

 ❌ WebDriver Error: Timed out waiting for asyncrhonous script result after 0 ms
    WebDriver Error: Timed out waiting for asyncrhonous script result after 0 ms
        at getErrorFromResponseBody (file:///Users/niklas.gruhn/Workspace/demo-browserstack-iphone-timeout/node_modules/webdriver/build/utils.js:195:12)
        at NodeJSRequest._request (file:///Users/niklas.gruhn/Workspace/demo-browserstack-iphone-timeout/node_modules/webdriver/build/request/index.js:193:23)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async Browser.wrapCommandFn (file:///Users/niklas.gruhn/Workspace/demo-browserstack-iphone-timeout/node_modules/@wdio/utils/build/shim.js:90:29)
        at async Browser.wrapCommandFn (file:///Users/niklas.gruhn/Workspace/demo-browserstack-iphone-timeout/node_modules/@wdio/utils/build/shim.js:90:29)
        at async IFrameManager.stopSession (/Users/niklas.gruhn/Workspace/demo-browserstack-iphone-timeout/node_modules/@web/test-runner-webdriver/dist/IFrameManager.js:95:29)

In the Browserstack web UI I can see that the tests were successfully executed. The error only occurs when closing the session. This is the "asynchrones script" that is timing out:

https://github.com/modernweb-dev/web/blob/efd8579cd12d578a742f8f5424ce0bbba36a7e72/packages/test-runner-webdriver/src/IFrameManager.ts#L119-L138

In particular, it seems like the load event on the iframe is never fired.

To Reproduce

I setup this repository with a minimal demo. Unfortunately, Browserstack credentials are required. To reproduce: pull the repository and run:

export BROWSERSTACK_USERNAME="..."
export BROWSERSTACK_ACCESSKEY="..."
npm install
npm test

Workaround

Setting concurrency: 1 in the web-test-runner config.