Multiple device/browser configuration for BrowserStack

How do we add more than one device/browser for BS to test?

Standard config for one device:

WebDriver: {
  url: localUrl,
  user: bs.username,
  key: bs.apiKey,
  browser: 'chrome',
  waitForTimeout: 10000,
  smartWait: 10000,
  desiredCapabilities: {
    os_version: '7.0',
    device: 'Samsung Galaxy S8',
    name: 'CodeceptJS',
    'browserstack.debug': 'true',
    'browserstack.local': 'true',
    'browserstack.console': 'errors',
  },
},

I want to do something like this:

WebDriver: {
  url: localUrl,
  user: bs.username,
  key: bs.apiKey,
  browser: 'chrome',
  waitForTimeout: 10000,
  smartWait: 10000,
  commonCapabilities: {
    name: 'CodeceptJS',
    'browserstack.debug': 'true',
    'browserstack.local': 'true',
    'browserstack.console': 'errors',
  },
  desiredCapabilities: [
  {
    os_version: '7.0',
    device: 'Samsung Galaxy S8',
  }
  {
    os_version: '12',
    device: 'iPhone 8',
  }
],
},

This doesn’t work. What’s the correct format?

@paulcredmond What do you expect to happen with your example config? Shall a single scenario run on an iphone device AND an android device?

If so, you must execute codeceptjs two times and you can use --profile option (https://codecept.io/configuration/#profile) or directly different configs for each execution which will overwrite specific config parameters.

We use specific configs that extend our base config with specific parameters using the _.merge function… e.g. for iphone on BS the specific codecept.iphone.conf.js looks something like this:

const { merge } = require("lodash");

const { config: commonConfig } = require("./codecept.browserstack.conf");

const browserStackAppiumVersion = "1.17.0";

// windowSize is not supported for mobile device
delete commonConfig.helpers.WebDriver.windowSize;

const specificConfig = {
  isMobile: true,
  helpers: {
    WebDriver: {
      browserName: "iPhone",
      desiredCapabilities: {
        "bstack:options": {
          osVersion: "13",
          deviceName: "iPhone 11",
          realMobile: "true",
          appiumVersion: browserStackAppiumVersion
        }
      }
    }
  }
};

exports.config = merge({}, commonConfig, specificConfig);

and we use it like this: npx codeceptjs run -c codecept.iphone.conf.js

@christian_wolf

What do you expect to happen with your example config? Shall a single scenario run on an iphone device AND an android device?

Yes, that’s correct. In fact I want to run each scenario using 8 different devices and browsers.

I was going to go down the multiple config route as you suggested but I was hoping to solve it using one config. I have found a way to do it on browserstack using:

  multiple: {
    remote: {
      browsers: [list of browsers and capabilities]
   }
  }