BrowserStack Service plugin not working
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?
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.jswhere there are certiain checks. What I found is that if theWebdriverhelper andwdioplugin 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
wdioplugin andWebdriverwere 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-servicelauncher expectsoptionsto contain all the configuration set in the plugin object likebrowserstackLocal, but receivesseleniumInstallArgs,seleniumArgsinstead. I tried switching the order of options and config and thebrowserstack-servicewas 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
afterhooks, name the session on browserstack based on the scenario name, and even thoughbrowserStackLocalwas initiated successfully, the capability wasn't passed to BrowserStack. - There also is an issue with the BrowserStack service code that it breaks if the
capabilitiesobject 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 ~