WebdriverIO config file for multiple browsers

5.8k Views Asked by At

I need to run test cases on multiple browsers, while using webdriverIO. Despite going through several articles and documentation of WDIO, I couldn't find a way in which works.

this is my wdio.conf.js.

exports.config = {
    baseUrl: 'http://127.0.0.1:8100/',
    path: '/wd/hub',
    specs: [
        './e2e/**/*-wdio.e2e-spec.ts'
    ],
    maxInstances: 10,
    // capabilities: [
    //   {
    //       browserName: 'Chrome',
    //   }, 
    //   {
    //       browserName: 'Firefox',
    //   }
    // ],
    capabilities: {
        myChromeBrowser: {
            desiredCapabilities: {
                browserName: 'Chrome',
            }
        },
        myFirefoxBrowser: {
            desiredCapabilities: {
                browserName: 'Firefox',
            }
        }
    },
    
    sync: true,
    waitforTimeout: 10000,
    services: ['selenium-standalone'],
    framework: 'jasmine',
    jasmineNodeOpts: {
        defaultTimeoutInterval: 50000,
        expectationResultHandler: function(passed, assertion) {  }
    },
    before: function () {
        require('ts-node/register');
        require('ts-node').register({
            project: 'e2e'
        });
    },
}

These are the devDependencies I have used in package.json:

"devDependencies": {
   "ts-node": "^3.3.0",
   "wdio-appium-service": "^0.2.3",
   "wdio-firefox-profile-service": "^0.1.0",
   "wdio-jasmine-framework": "^0.3.2",
   "wdio-selenium-standalone-service": "0.0.9",
   "wdio-spec-reporter": "^0.1.2",
   "wdio-typescript-service": "0.0.3",
   "webdriverio": "^4.9.8"
}

As you can see, I have tried both "capabilities": [] and "capabilities": {} but following official docs, and even after that, only two instances of Chrome run. I have also tried installing Firefox's plugin/dependencies by following installation doc.

Can anybody point out, what have i missed or wrongly configured? Currently two instances of google Chrome launches and the test cases run on them, while I want the test cases to run in chrome and firefox separately.

2

There are 2 best solutions below

0
On

Additionally please check your "Camel Casing" on your browser names. Because you have Firefox instead of firefox - you are probably having it launch the second instance of Chrome.

...
capabilities: [
{
    // maxInstances can get overwritten per capability. So if you have an in-house Selenium
    // grid with only 5 firefox instances available you can make sure that not more than
    // 5 instances get started at a time.
    maxInstances: 1,
    browserName: 'chrome'
},
{
    maxInstances: 1,
    browserName: 'firefox'
}
],
...
0
On

İf you want multiple browser tests is to run a single test suite with different environment variables. You should define matrix like;

matrix:
- _BROWSER: "firefox"
  _PLATFORM: "Linux"
  _VERSION: "26"
- _BROWSER: "firefox"
  _PLATFORM: "Windows_7"
  _VERSION: "26"
- _BROWSER: "chrome"
  _PLATFORM: "Windows_7"
  _VERSION: "31"

then just create your WebdriverJS instance with given capacities

var BROWSERNAME = (process.env._BROWSER || process.env.BROWSER || 'chrome').replace(/_/g,' ');
var BROWSERVERSION = process.env._VERSION || process.env.VERSION || '*';
var BROWSERPLATFORM = (process.env._PLATFORM || process.env.PLATFORM || 'Linux').replace(/_/g,' ');

var options = {
    desiredCapabilities: {


     browserName: BROWSERNAME,
        version: BROWSERVERSION,
        platform: BROWSERPLATFORM
    },
    // ...
};

client = webdriverjs.remote(options);

Travis will automatically start three different builds and will run your tests with different browser in parallel. Check out this example project for more implementation details.

For more details multiple browsers test