CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

BrowserStack Service plugin not working

Open princebaretto99 opened this issue 3 years ago • 1 comments

Plugin part :

plugins: {  
        wdio: {
            enabled: true,
            services: [
                [ 'browserstack', {
                        browserstackLocal: true
                    }
                ]
            ],
        },
}

Error I'm getting:

Could not load plugin wdio from module './plugin/wdio':
name.toLowerCase is not a function
TypeError: name.toLowerCase is not a function

Please let me know how to resolve this?

princebaretto99 avatar Jul 12 '22 11:07 princebaretto99

I tried debugging the flow of how wdio plugin is called and eventually the selected service and how the objects are passed to that launcher. Here are the issues I found:

  • The params of the service needs to be set as independent properties and not as nested objects as listed on WebdriverIO's website. Eg:
plugins: {
    wdio: {
      enabled: true,
      services: ['browserstack'],
      browserstackLocal: true,
      user: BROWSERSTACK_USERNAME,  // optional and in-case Webdriver helper not instantiated
      key: BROWSERSTACK_ACCESS_KEY, // optional and in-case Webdriver helper not instantiated
    }
}
  • The params passed above are sent to codecept-js-browserstack/node_modules/codeceptjs/lib/plugin/wdio.js where there are certiain checks. What I found is that if the Webdriver helper and wdio plugin are used together, there is a check on line 89 of this file
if (webDriver) {
    config = Object.assign(webDriver.options, config);
    restartsSession = !!config.restart;
  }
  • This condition causes the config to be merged and I was getting W3C capability errors. If I commented this condition, the wdio plugin and Webdriver were able to co-exist.

  • Next, the wdio service launcher expects 3 params in wdio v5+. I think there is an order or object creation mismatch here.

          launchers.push(new Launcher(options, [config.capabilities], config));
  • The browserstack-service launcher expects options to contain all the configuration set in the plugin object like browserstackLocal, but receives seleniumInstallArgs, seleniumArgs instead. I tried switching the order of options and config and the browserstack-service was able to instantiate and received the correct params.
  • However I wasn't able to get the core features of the service to work, i.e. mark tests as passed or failed on BrowserStack based on after hooks, name the session on browserstack based on the scenario name, and even though browserStackLocal was initiated successfully, the capability wasn't passed to BrowserStack.
  • There also is an issue with the BrowserStack service code that it breaks if the capabilities object is not an array. So until that's fixed, capabilities would have to be an array. Not sure why codecept isn't creating a capabilities array as webdriverio test runner expects capabilities to be an array.

I think this will require some end-to-end debugging on how the options, capabilities, config is passed through from codecept -> wdio -> Browserstack Service and also where capabilities should be added? In the wdio object? or the Webdriver object ~

alliv8 avatar Jul 13 '22 18:07 alliv8