WebdriverIO allows you to run multiple automated sessions in a single test. This becomes handy when you’re testing features that require multiple users (for example, chat or WebRTC applications).
Instead of creating a couple of remote instances where you need to execute common commands like
url on each instance, you can simply create a multiremote instance and control all browsers at the same time.
To do so, just use the
multiremote() function, and pass in an object with names keyed to
capabilities for values. By giving each capability a name, you can easily select and access that single instance when executing commands on a single instance.
Multiremote is not meant to execute all your tests in parallel. It is intended to help coordinate multiple browsers and/or mobile devices for special integration tests (e.g. chat applications).
All multiremote instances return an array of results. The first result represents the capability defined first in the capability object the second result the second capability and so on.
Here is an example of how to create a multiremote instance in standalone mode:
In order to use multiremote in the WDIO testrunner, just define the
capabilities object in your
wdio.conf.js as an object with the browser names as keys (instead of a list of capabilities):
This will create two WebDriver sessions with Chrome and Firefox. Instead of just Chrome and Firefox you can also boot up two mobile devices using Appium or one mobile device and one browser.
You can even boot up one of the cloud services backend together with local Webdriver/Appium, or Selenium Standalone instances. WebdriverIO automatically detect cloud backend capabilities if you specified either of
sauce:options (SauceLabs), or
tb:options (TestingBot) in browser capbilities.
Any kind of OS/browser combination is possible here (including mobile and desktop browsers). All commands your tests call via the
browser variable are executed in parallel with each instance. This helps streamline your integration tests and speed up their execution.
For example, if you open up a URL:
Each command’s result will be an object with the browser names as the key, and the command result as value, like so:
Notice that each command is executed one by one. This means that the command finishes once all browsers have executed it. This is helpful because it keeps the browser actions synced, which makes it easier to understand what’s currently happening.
Sometimes it is necessary to do different things in each browser in order to test something. For instance, if we want to test a chat application, there has to be one browser who sends a text message while another browser waits to receive it, and then run an assertion on it.
When using the WDIO testrunner, it registers the browser names with their instances to the global scope:
In this example, the
myFirefoxBrowser instance will start waiting on a message once the
myChromeBrowser instance has clicked on
Multiremote makes it easy and convenient to control multiple browsers, whether you want them doing the same thing in parallel, or different things in concert.