webdriverio / webdriverio

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

[🐛 Bug]: v9 - Problems running tests on Browserstack #13722

Open BosseKarat opened 1 month ago

BosseKarat commented 1 month ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.1.2

Node.js Version

20.17.0

Mode

WDIO Testrunner

Which capabilities are you using?

capabilities: [
    {
        browserName: 'Chrome',       
        'bstack:options': {
          browserVersion: '127.0',
          os: 'Windows',
          osVersion: '10',
        }

      }
  ],

  user: xxxxx,
  key: xxxxx,

  services: [
    [
      "browserstack",
      {
        browserstackLocal: true,
        testObservability: true,
        testObservabilityOptions: {
            projectName: "Your project name goes here",
            buildName: "The static build job name goes here e.g. Nightly regression"
        },

      },
    ],
  ],

What happened?

I tried updating from v.8.x to latest v.9 and ran into problems trying to run my tests using browserstack. I spoke to Erwin at Discord and he thought it might be related to https://github.com/webdriverio/webdriverio/pull/13701 and adviced me to submit a ticket. Please see logs below for relevant output regarding the error.

What is your expected behavior?

I should be able to connect to browserstack service

How to reproduce the bug.

Try running any tests using browserstack service to trigger the error. I have tried to adjust the flags but I always get the same error.

package.json

"@types/mocha": "^10.0.8",
"@wdio/browserstack-service": "^9.1.2",
"@wdio/cli": "^9.1.2",
"@wdio/local-runner": "^9.1.2",
"@wdio/mocha-framework": "^9.1.2",

Relevant log output

**WDIO logs:**

2024-10-01T05:07:15.689Z ERROR @wdio/browserstack-service: Data upload to BrowserStack Test Observability failed due to TypeError: fetch failed
2024-10-01T05:07:15.708Z ERROR @wdio/cli:utils: A service failed in the 'onPrepare' hook
Error: spawn UNKNOWN
    at ChildProcess.spawn (node:internal/child_process:421:11)
    at spawn (node:child_process:762:9)
    at Object.execFile (node:child_process:351:17)
    at C:\Projects\webdriverio-9\node_modules\browserstack-local\lib\Local.js:88:34
    at LocalBinary.binaryPath (C:\Projects\webdriverio-9\node_modules\browserstack-local\lib\LocalBinary.js:158:7)
    at Local.getBinaryPath (C:\Projects\webdriverio-9\node_modules\browserstack-local\lib\Local.js:259:19)
    at Local.start (C:\Projects\webdriverio-9\node_modules\browserstack-local\lib\Local.js:83:10)
    at node:internal/util:432:7
    at new Promise (<anonymous>)
    at bound  (node:internal/util:418:12)

**bstack-wdio-service.log;**

2024-10-01T05:18:43.162Z DEBUG @wdio/browserstack-service Exception in sending funnel data: TypeError: fetch failed
2024-10-01T05:18:43.162Z DEBUG @wdio/browserstack-service app is not defined in browserstack-service config, skipping ...
2024-10-01T05:18:45.984Z DEBUG @wdio/browserstack-service teardown started
2024-10-01T05:18:45.984Z DEBUG @wdio/browserstack-service teardown ended
2024-10-01T05:18:46.147Z DEBUG @wdio/browserstack-service Inside OnComplete hook..
2024-10-01T05:18:46.148Z DEBUG @wdio/browserstack-service Reading worker file worker-data-29044.json
2024-10-01T05:18:46.150Z DEBUG @wdio/browserstack-service Sending SDK event with data 

----

[90m2024-10-01T05:18:46.178Z DEBUG @wdio/browserstack-service Exception in sending funnel data: TypeError: fetch failed
2024-10-01T05:18:46.178Z INFO @wdio/browserstack-service If facing any issues, please contact BrowserStack support with the Build Run Id - xxxx
2024-10-01T05:18:46.207Z DEBUG @wdio/browserstack-service Failed to fire api request due to TypeError: fetch failed - TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async nodeRequest (C:\Projects\webdriverio-9\node_modules\@wdio\browserstack-service\build\index.js:880:22)
    at async uploadLogs (C:\Projects\webdriverio-9\node_modules\@wdio\browserstack-service\build\index.js:1808:20)
    at async BrowserstackLauncherService._uploadServiceLogs (C:\Projects\webdriverio-9\node_modules\@wdio\browserstack-service\build\index.js:3327:22)
    at async BrowserstackLauncherService.onComplete (C:\Projects\webdriverio-9\node_modules\@wdio\browserstack-service\build\index.js:3203:7)
    at async file:///C:/Projects/webdriverio-9/node_modules/@wdio/cli/build/index.js:1207:9
    at async Promise.all (index 0)
    at async Launcher.run (file:///C:/Projects/webdriverio-9/node_modules/@wdio/cli/build/index.js:2198:7)
    at async Module.run (file:///C:/Projects/webdriverio-9/node_modules/@wdio/cli/build/index.js:3214:16)
2024-10-01T05:18:46.207Z DEBUG @wdio/browserstack-service Response - undefined

Code of Conduct

Is there an existing issue for this?

wdio-bot commented 1 month ago

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

behnamazimi commented 1 month ago

Getting a similar error when I set the configs to upload an app file:

   TypeError: fetch failed
    at node:internal/deps/undici/undici:13178:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at BrowserstackLauncherService._uploadApp (../node_modules/@wdio/browserstack-service/build/index.js:3298:19)
    at BrowserstackLauncherService.onPrepare (../node_modules/@wdio/browserstack-service/build/index.js:3072:24)
    at async file:///../node_modules/@wdio/cli/build/index.js:1207:9
    at async Promise.all (index 0)
    at async Launcher.run (file:///../node_modules/@wdio/cli/build/index.js:2190:7) {
  [cause]: InvalidArgumentError: invalid content-length header
kamal-kaur04 commented 1 month ago

@BosseKarat Thank you for reporting the issue.

Could you please share the minimal reproducible setup if possible and the OS you are using. I tried with the same configuration and dependencies you shared but cannot reproduce the issue for Test Observability.

wdio-bot commented 1 month ago

Thanks for raising this issue 🙏

Unfortunately we can't help you without a reproducible example in this matter. Please read our contributing guidelines on how to create a reproducible example. If you can't provide a reproducible example we will close this issue in 7 days.

If you have any questions please reach out to us on our Discord channel. We are happy to help you out there.

BosseKarat commented 1 month ago

@BosseKarat Thank you for reporting the issue.

Could you please share the minimal reproducible setup if possible and the OS you are using. I tried with the same configuration and dependencies you shared but cannot reproduce the issue for Test Observability.

I'm using Windows 10. The setup is minimal - I started from scratch using npm init wdio@latest, select TypeScript and make the wizard install sample test and page object. Use the same capabilities as mentioned above. Other than that, I didn't make any changes at all except for altering the URL a few times in the page.ts file.

If you don't mind @kamal-kaur04 - would it be possible for you provide a working example for V.9.x with TypeScript that is working on your end?

BosseKarat commented 1 month ago

@kamal-kaur04 never mind, here is a minimal reproducible setup: https://github.com/BosseKarat/bservice-wdio9. Please se readme regarding my machine specs. My version of node is 20.17.0.

kamal-kaur04 commented 1 month ago

@BosseKarat No luck :/ Cannot reproduce the issue with the same sample you shared on Windows as well.

Could you please modify the below line in wdio-browserstack-service in node_modules ->

BStackLogger.error(`Data upload to BrowserStack Test Observability failed due to ${error}`)

to

BStackLogger.error(`Data upload to BrowserStack Test Observability failed due to ${error}. Cause : ${error.cause}`)

and please share the error log.

BosseKarat commented 1 month ago

@kamal-kaur04 - there is no such entry in my project. I have @browserstack , browserstack-local and browserstack-service within the @wdio-folder (i.e @wdio/browserstack-service). I don't get any results trying to search for the BStackLogger.

BosseKarat commented 1 month ago

@kamal-kaur04 I'm guessing there's something here you would like me to modify?

bild

kamal-kaur04 commented 1 month ago

Yeah, I meant @wdio/browserstack-service here. Path should be node_modules/@wdio/browserstack-service/build/index.js

BosseKarat commented 1 month ago

@kamal-kaur04 I don't have a packages folder in @wdio/browserstack-service. Just to be clear - could you send me the relative path to file that you wan't me to adjust, e.g bservice-wdio9\node_modules\@wdio\browserstack-service\..... I'm starting to think that you are not referring to the repo that I've sent as an example, i.e https://github.com/BosseKarat/bservice-wdio9

kamal-kaur04 commented 4 weeks ago

@BosseKarat Apologies, corrected the path. Please check previous comment.

BosseKarat commented 3 weeks ago

@kamal-kaur04 Thank you. I don't seem to get that far though. I can't find anything related to "Cause :" when looking through the logs. This is only place in the code that I can trace to the error message presented:

bild

bild

However, you don't have to enable Test Observability for this issue to happen. I tried the latest update (v.9.2.2) and disabled Test Observability. This is what the logs came out like with logLevel set to "debug":

Execution of 1 workers started at 2024-10-28T12:10:22.186Z

2024-10-28T12:10:22.227Z DEBUG @wdio/utils:initializeServices: initialize service "browserstack" as NPM package 2024-10-28T12:10:22.692Z INFO @wdio/cli:launcher: Run onPrepare hook 2024-10-28T12:10:22.704Z DEBUG @wdio/browserstack-service: Sending SDK event with data { userName: 'xxxx', accessKey: 'xxx', event_type: 'SDKTestAttempted', detectedFramework: 'WebdriverIO-mocha', event_properties: { language_framework: 'WebdriverIO_mocha', referrer: 'WebdriverIO-mocha/9.2.1', language: 'WebdriverIO', languageVersion: 'v20.17.0', buildName: 'TestBuild', buildIdentifier: 'undefined', os: 'Windows_NT', hostname: 'xxx', productMap: { observability: false, accessibility: false, percy: false, automate: true, app_automate: false }, product: [ 'automate' ] } } 2024-10-28T12:10:22.818Z DEBUG @wdio/browserstack-service: Exception in sending funnel data: TypeError: fetch failed 2024-10-28T12:10:22.819Z DEBUG @wdio/browserstack-service: app is not defined in browserstack-service config, skipping ... 2024-10-28T12:10:29.510Z DEBUG @wdio/cli:utils: Finished to run "onPrepare" hook in 6817ms 2024-10-28T12:10:29.515Z INFO @wdio/cli:launcher: Run onWorkerStart hook 2024-10-28T12:10:29.516Z DEBUG @wdio/cli:utils: Finished to run "onWorkerStart" hook in 0ms 2024-10-28T12:10:29.519Z INFO @wdio/local-runner: Start worker 0-0 with arg: run ./wdio.conf.ts 2024-10-28T12:10:29.539Z DEBUG @wdio/local-runner: Send command run to worker with cid "0-0" 2024-10-28T12:10:29.542Z INFO @wdio/browserstack-service: Browserstack Local successfully started after 6688.735499999999ms [0-0] 2024-10-28T12:10:32.493Z INFO @wdio/local-runner: Run worker command: run [0-0] 2024-10-28T12:10:32.649Z DEBUG @wdio/runner: init remote session [0-0] 2024-10-28T12:10:32.654Z ERROR @wdio/runner: TypeError: this[#browser].on is not a function [0-0] at new ContextManager (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriverio\build\index.js:2995:19) [0-0] at getContextManager (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriverio\build\index.js:2983:22) [0-0] at remote (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriverio\build\index.js:7472:5) [0-0] at async Runner._startSession (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:781:23) [0-0] at async Runner.run (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:642:20) [0-0] 2024-10-28T12:10:32.704Z DEBUG @wdio/utils:initializeServices: initialize service "browserstack" as NPM package [0-0] 2024-10-28T12:10:33.120Z DEBUG @wdio/utils:shim: Finished to run "beforeSession" hook in 0ms [0-0] RUNNING in Chrome - file:///C:/Projects/gh-wdio/bservice-wdio9/test/specs/test.e2e.ts [0-0] 2024-10-28T12:10:33.438Z DEBUG @wdio/runner: init remote session [0-0] 2024-10-28T12:10:33.441Z INFO webdriver: Initiate new session using the WebDriver protocol [0-0] 2024-10-28T12:10:33.441Z INFO @wdio/utils: Connecting to existing driver at https://hub-cloud.browserstack.com:443/wd/hub [0-0] 2024-10-28T12:10:33.443Z INFO webdriver: [POST] https://hub-cloud.browserstack.com/wd/hub/session [0-0] 2024-10-28T12:10:33.444Z INFO webdriver: DATA { [0-0] capabilities: { [0-0] alwaysMatch: { [0-0] browserName: 'Chrome', [0-0] 'bstack:options': [Object], [0-0] webSocketUrl: true, [0-0] unhandledPromptBehavior: 'ignore' [0-0] }, [0-0] firstMatch: [ {} ] [0-0] } [0-0] } [0-0] 2024-10-28T12:10:33.903Z ERROR webdriver: Error: WebDriverError: Request failed with error code SELF_SIGNED_CERT_IN_CHAIN when running "https://hub-cloud.browserstack.com/wd/hub/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"browserName":"Chrome","bstack:options":{"browserVersion":"127.0","os":"Windows","osVersion":"10","projectName":"TestProject","buildName":"TestBuild","sessionName":"TestSession","local":true,"wdioService":"9.2.1"},"webSocketUrl":true,"unhandledPromptBehavior":"ignore"},"firstMatch":[{}]}}" [0-0] at FetchRequest._libRequest (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:1434:13) [0-0] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [0-0] at async FetchRequest._request (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:1335:20) [0-0] at async startWebDriverSession (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:864:16) [0-0] at async Function.newSession (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:1569:41) [0-0] at async remote (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriverio\build\index.js:7459:20) [0-0] at async Runner._startSession (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:781:23) [0-0] at async Runner._initSession (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:755:22) [0-0] at async Runner.run (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:662:16) [0-0] 2024-10-28T12:10:33.913Z DEBUG @wdio/browserstack-service: teardown started [0-0] 2024-10-28T12:10:33.913Z DEBUG @wdio/browserstack-service: teardown ended [0-0] 2024-10-28T12:10:33.910Z ERROR @wdio/runner: Error: Failed to create session. [0-0] WebDriverError: Request failed with error code SELF_SIGNED_CERT_IN_CHAIN when running "https://hub-cloud.browserstack.com/wd/hub/session" with method "POST" and args "{"capabilities":{"alwaysMatch":{"browserName":"Chrome","bstack:options":{"browserVersion":"127.0","os":"Windows","osVersion":"10","projectName":"TestProject","buildName":"TestBuild","sessionName":"TestSession","local":true,"wdioService":"9.2.1"},"webSocketUrl":true,"unhandledPromptBehavior":"ignore"},"firstMatch":[{}]}}" [0-0] at startWebDriverSession (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:868:11) [0-0] at process.processTicksAndRejections (node:internal/process/task_queues:95:5) [0-0] at async Function.newSession (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriver\build\index.js:1569:41) [0-0] at async remote (C:\Projects\gh-wdio\bservice-wdio9\node_modules\webdriverio\build\index.js:7459:20) [0-0] at async Runner._startSession (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:781:23) [0-0] at async Runner._initSession (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:755:22) [0-0] at async Runner.run (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/runner/build/index.js:662:16) [0-0] 2024-10-28T12:10:33.915Z DEBUG @wdio/utils:shim: Finished to run "after" hook in 4ms 2024-10-28T12:10:34.051Z DEBUG @wdio/local-runner: Runner 0-0 finished with exit code 1 [0-0] FAILED in Chrome - file:///C:/Projects/gh-wdio/bservice-wdio9/test/specs/test.e2e.ts 2024-10-28T12:10:34.053Z INFO @wdio/cli:launcher: Run onWorkerEnd hook 2024-10-28T12:10:34.053Z DEBUG @wdio/cli:utils: Finished to run "onWorkerEnd" hook in 0ms 2024-10-28T12:10:34.054Z INFO @wdio/cli:launcher: Run onComplete hook 2024-10-28T12:10:34.054Z DEBUG @wdio/browserstack-service: Inside OnComplete hook.. 2024-10-28T12:10:34.056Z DEBUG @wdio/browserstack-service: Reading worker file worker-data-17744.json 2024-10-28T12:10:34.059Z DEBUG @wdio/browserstack-service: Sending SDK event with data { userName: 'xxxx', accessKey: 'xxxx', event_type: 'SDKTestSuccessful', detectedFramework: 'WebdriverIO-mocha', event_properties: { language_framework: 'WebdriverIO_mocha', referrer: 'WebdriverIO-mocha/9.2.1', language: 'WebdriverIO', languageVersion: 'v20.17.0', buildName: 'TestBuild', buildIdentifier: 'undefined', os: 'Windows_NT', hostname: 'xxxxx', productMap: { observability: false, accessibility: false, percy: false, automate: true, app_automate: false }, product: [ 'automate' ], productUsage: { testObservability: { enabled: false, manuallySet: true, buildHashedId: undefined } } } } 2024-10-28T12:10:34.106Z DEBUG @wdio/browserstack-service: Exception in sending funnel data: TypeError: fetch failed 2024-10-28T12:10:34.162Z DEBUG @wdio/browserstack-service: Failed to fire api request due to TypeError: fetch failed - TypeError: fetch failed at node:internal/deps/undici/undici:13178:13 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async nodeRequest (C:\Projects\gh-wdio\bservice-wdio9\node_modules\@wdio\browserstack-service\build\index.js:880:22) at async uploadLogs (C:\Projects\gh-wdio\bservice-wdio9\node_modules\@wdio\browserstack-service\build\index.js:1808:20) at async BrowserstackLauncherService._uploadServiceLogs (C:\Projects\gh-wdio\bservice-wdio9\node_modules\@wdio\browserstack-service\build\index.js:3327:22) at async BrowserstackLauncherService.onComplete (C:\Projects\gh-wdio\bservice-wdio9\node_modules\@wdio\browserstack-service\build\index.js:3203:7) at async file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/cli/build/index.js:1207:9 at async Promise.all (index 0) at async Launcher.run (file:///C:/Projects/gh-wdio/bservice-wdio9/node_modules/@wdio/cli/build/index.js:2198:7) 2024-10-28T12:10:38.421Z DEBUG @wdio/cli:utils: Finished to run "onComplete" hook in 4367ms

Spec Files: 0 passed, 1 failed, 1 total (100% completed) in 00:00:16

2024-10-28T12:10:38.422Z INFO @wdio/local-runner: Shutting down spawned worker 2024-10-28T12:10:38.683Z INFO @wdio/local-runner: Waiting for 0 to shut down gracefully 2024-10-28T12:10:38.684Z INFO @wdio/local-runner: shutting down

The SELF_SIGNED_CERT_IN_CHAIN is interesting. We have not made any adjustments in our organization and everything works fine using wdio v.8.x

This error: [0-0] 2024-10-28T12:10:32.654Z ERROR @wdio/runner: TypeError: this[#browser].on is not a function is also interesting ..

kamal-kaur04 commented 3 weeks ago

@behnamazimi App Upload issue is fixed in https://github.com/webdriverio/webdriverio/releases/tag/v9.2.2

@BosseKarat Let's have a word via BrowserStack Support. They will reach out here and ask you to create a ticket.

BhumikaBBrowserstack commented 3 weeks ago

Hi @BosseKarat Request you to create a ticket with all the details using the below link and we can continue the investigation from there: https://www.browserstack.com/contact

BosseKarat commented 3 weeks ago

No problems @kamal-kaur04 @BhumikaBBrowserstack, I will contact the support.

It should be noted though that I'm not the only one having this problem. I've seen at least two other people in the wdio community chat and I've used this issue as a reference. I think it would be in your best interest to present a solution here as well.

@christian-bromann - do as you please with this ticket. We will move this discussion to Borwserstack support

BosseKarat commented 3 weeks ago

FYI:

image