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]
   }
  }

Hi @christian_wolf
I’m trying CodeceptJS for first time, documentation was good and easy to start. I have a question around running CodeceptJS BDD on Browserstack, could you please guide me with a sample codecept.conf.JS. I’m clueless where to add.
I was trying this for test cafe and planning to run on Web Browser and Mobile Browser.

Thanks a million for advance help

Hi @amar

when your tests already running locally, you just have to add some Browserstack parameters to the codeceptjs.conf:

 helpers: {
    WebDriver: {
    host: "hub-cloud.browserstack.com",
    user: "BROWSERSTACK_USER",
    key: "BROWSERSTACK_KEY"
    }
}

These are the mandatory parameters. The User and Key you must create in Browserstack.
You can add more parameters, like which OS, device, browser, etc.
e.g.

helpers: {
 WebDriver: {
      host: "hub-cloud.browserstack.com",
      user: "BROWSERSTACK_USER",
      key: "BROWSERSTACK_KEY",
      windowSize: "375x667",
      browser: "Chrome",
      browserVersion: "88",
      desiredCapabilities: {
        "bstack:options": {
          os: "OS X",
          osVersion: "Big Sur",
          seleniumVersion: "3.141.59"
         }
      }
   }
}

All available capabilities can be found here: BrowserStack - Capabilities for running mobile app tests on BrowserStack

I hope that helps you!