Detect BROWSERSTACK_ALL_PARALLELS_IN_USE error when instantiating a driver with WebdriverIO

402 Views Asked by At

I am creating a new Appium WebDriver session using WebdriverIO API:

const options = {...};
const driver: Browser<"async">;

try {
    driver = await remote(options);
} catch (error) {
    console.log("Error:", error);
}

In BrowserStack there is a limit on the number of parallel tests that one can run. I am hitting that limit and my call to remote errors and, in the catch, I get this inside variable error:

Failed to create session.

Which does not give me much info on why the call failed. On the other hand, the driver is emitting logs that give such an answer:

XXXX-XX-XXTXX:XX:XX.XXXZ ERROR webdriver: [BROWSERSTACK_ALL_PARALLELS_IN_USE] All parallel tests are currently in use, including the queued tests. Please wait to finish or upgrade your plan to add more sessions.: [BROWSERSTACK_ALL_PARALLELS_IN_USE] All parallel tests are currently in use, including the queued tests. Please wait to finish or upgrade your plan to add more sessions.
    at Object.getErrorFromResponseBody (/home/vsts/work/1/s/node_modules/webdriverio/node_modules/webdriver/build/utils.js:189:12)
    at /home/vsts/work/1/s/node_modules/webdriverio/node_modules/webdriver/build/request.js:168:31
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/vsts/work/1/s/node_modules/webdriverio/node_modules/webdriver/build/request.js:9:103)
    at _next (/home/vsts/work/1/s/node_modules/webdriverio/node_modules/webdriver/build/request.js:11:194)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Question

How can I get more information about the nature of the error as I am calling remote? I want to detect the occurrence of BROWSERSTACK_ALL_PARALLELS_IN_USE so that I can implement, in code, some strategies around this issue (like retrying after some randomized time).

2

There are 2 best solutions below

1
On

The error BROWSERSTACK_ALL_PARALLELS_IN_USE indicates that all your running threads and queued threads are full and no more test can be triggered.

Once you have maxed out your running + queued threads, any new sessions initiated are dropped with BROWSERSTACK_ALL_PARALLELS_IN_USE.

You will not be able to trigger any more tests until there are threads available.

You can take a look at https://webdriver.io/docs/organizingsuites/ by setting maxInstances. This will allow you to limit the number of tests triggered.

0
On

Actually the error is a proper Error object and has message and stack available. The log shown is encapsulated in the message, so the following is just fine:

try {
    driver = await remote(options);
} catch (error) {
    if (error.message.indexOf("BROWSERSTACK_ALL_PARALLELS_IN_USE") >= 0) {
        // Retry
    }
    // Do something else
}