browserstack / browserstack-local-nodejs

NodeJS bindings for BrowserStack Local
https://www.browserstack.com
MIT License
71 stars 56 forks source link

After BrowserStackLocal runner app update wdio fails to run local BrowserStack server #105

Open dimkin-eu opened 4 years ago

dimkin-eu commented 4 years ago

Environment (please complete the following information):

Config of WebdriverIO common things, apart this

    user: process.env.BROWSERSTACK_USERNAME,
    key: process.env.BROWSERSTACK_ACCESS_KEY,
    capabilities: [
        {
            "bstack:options": {
                "os": "Windows",
                "osVersion": "10",
                "resolution": "1920x1080",
                "networkLogs": "true",
                "video": "false",
                "seleniumVersion": "3.141.59"
            },
            "browserName": "Chrome",
            "goog:chromeOptions": {
                excludeSwitches: ["enable-automation", "load-extension"]
            }
        }
    ],

    services: [["browserstack", { browserstackLocal: true }]],

    onPrepare(config, capabilities) {
        bsLocal = new browserstack.Local();

        return new Promise(function (resolve) {
            bsLocal.start({ "key": process.env.BROWSERSTACK_ACCESS_KEY }, function (error) {
                if (error) {
                    console.log(error);
                } else {
                    resolve();
                }
            });
        });
    },

Describe the bug BrowserStack dropped old app, and the new app creates problems for running

To Reproduce

  1. install new local testing app https://www.browserstack.com/local-testing/live - this need for manual testing via browser
  2. try to run wdio test using BrowserStack

Expected behavior test runs

Log

LocalError: Either another browserstack local client is running on your machine or some server is listening on port 45690
    at /Users/.../node_modules/browserstack-local/lib/Local.js:65:20
    at ChildProcess.exithandler (child_process.js:294:7)
    at ChildProcess.emit (events.js:311:20)
    at ChildProcess.EventEmitter.emit (domain.js:482:12)
    at maybeClose (internal/child_process.js:1021:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
  name: 'LocalError',
  message: 'Either another browserstack local client is running on your machine or some server is listening on port 45690',
  extra: undefined
}

For a workaround is not enough to uninstall the app or just kill running processes - you need to kill both ( app is pretty smart :) )

 % ps -ax | grep BrowserStackLocal
31261 ??         0:00.01 bash /Applications/BrowserStackLocal.app/Contents/Resources/public/start_binary.sh
31266 ??         0:00.63 BrowserStackLocal --app --app-version 2.0   
31268 ??         0:00.71 BrowserStackLocal --app --app-version 2.0   
shawnlobo96 commented 4 years ago

Hey @dimkin-eu

In case you need to run both the desktop app as well as use Webdriver IO for an automate test, you can use the local identifier option in your WebdriverIO configuration.

This will allow both the local connections to be run simultaneously (Desktop app for local + local binary for WebdriverIO)

You need to add the below

bs_local_args = { 'key': '<browserstack-accesskey>', 'localIdentifier': 'randomstring' }

Refer: https://github.com/browserstack/browserstack-local-nodejs#local-identifier

In your capabilities, within bstack:options, you need to add the same identifier using you defined in bs_local_args.

Your bstack:options block should look like:

"bstack:options": {
                "os": "Windows",
                "osVersion": "10",
                "resolution": "1920x1080",
                "networkLogs": "true",
                "video": "false",
                "localIdentifier": "randomstring",
                "seleniumVersion": "3.141.59"
            }

This will prevent the error from showing up

dimkin-eu commented 4 years ago

@shawnlobo96 a little bit cumbersome, and looks like another workaround :) And which id BrowserStackLocal uses? to not set the same ( you know, human random is pseudorandom :) )

shawnlobo96 commented 4 years ago

@dimkin-eu this is indeed another workaround. Browserstack local does not set a local identifier by default. Ideally, when you require multiple binaries to be run with the same access_key, you would use a local identifier as this allows for multiple binaries to be spawned with the same credentials. This identifier can be any random characters or numbers.

Also, the local identifier you use is specific to your account.

Let's say you are using local identifier abc with your access_key, that would not affect my execution even if I specify the local identifier as abc since our accounts are different.

TLDR: you need to have the same localIdentifier in your capabilities as that used to start up the binary. You can think of it as a kind of mapping that maps the running test session with the binary instance.

You can write at 'support@browserstack.com' in case you still have any further questions or feedback :)