As you may expect, this is not the most effective method, because the connection to BrowserStack service is opened and closed for each command executed.

Sequential tests

Another option is to write a sequential test wrapper that will run selected tests against browsers defined in the config.json file one after another. It is a bit more complicated as it requires tests code refactoring.

The general idea is to connect to BrowserStackLocal, run tests for all browsers defined inside the config.json file and finally disconnect. To achieve this, we will use the beforeAll and afterAll hooks to handle BrowserStack connection. After establishing a connection with BrowserStackLocal we will loop through all browser versions from config file and run tests for each of them. Here's how it can look.