Search code examples
javascriptseleniumsaucelabs

How to speed up SauceLabs javascript queries in selenium tests?


I am running Selenium tests on the Chrome browser in SauceLabs and find the performance exceptionally slow.

Specifically, javascript queries (used to select objects) return in about 200ms in Sauce whereas the same queries return in about 5ms when running the test on my local machine. This 40x difference leads to total run-times that are about 5x longer in Sauce than if run local.

The code in question is basically:

return (List) driver.executeScript("return jQuery.find('.some_selector')");

Is there a known explanation for the slow response times?
Is there something I can change to speed up the javascript queries in Sauce?


Solution

  • I wouldn't expect the actual JavaScript to run at a significantly different speed once on the actual browser - though of course it depends upon the SauceLabs hardware / VMs.

    However, going back and forth to a remote driver over the WebDriver protocol is bound to be slower than talking to a local driver, so that will likely cover most of the difference.

    I suggest this is an inevitable result of running via Selenium Grid and especially of running against remote browsers, potentially on a variety of hardware. Hopefully the flexibility of this approach is worth the slight performance hit, and of course the difficulty of comparing local vs. remote.