In order to run your tests on a myriad of browser and operating system combinations, you need a way to run them at scale. With Selenium Remote, you can point your tests at a Selenium Grid that you maintain or someone else’s Grid (e.g. Sauce Labs), which they maintain and you pay for usage.
Selenium Grid
There are two main elements to Selenium Grid–a hub, and nodes. First you need to stand up a hub. Then you can connect (or “register”) nodes to that hub. Nodes are where your tests will run, and the hub is responsible for making sure your tests end up on the right node (e.g., the machine with the operating system and browser you specified in your test setup).
Selenium Grid comes built into the Selenium Standalone Server, which you can download here (pick the highest number for the latest version).
Then start the hub.
> java -jar selenium-server-standalone.jar -role hub
19:05:12.718 INFO - Launching Selenium Grid hub
...
After that, we can register nodes to the hub.
> java -jar selenium-server-standalone.jar -role node -hub http://ip-address-or-dns-name-to-your-hub:4444/grid/register
19:05:57.880 INFO - Launching a Selenium Grid node
...
Note: To span nodes across multiple machines, you will need to place the standalone server on each machine and launch it with the same registration command (providing the IP Address or DNS name of your hub, and specifying additional parameters as needed).
Then it is a simple matter of connecting to the Grid Hub in our test setup.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
String url = "http://ip-address-or-dns-name-to-your-hub:4444/wd/hub";
driver = new RemoteWebDriver(new URL(url), capabilities);
Note: Selenium Grid is a great option for scaling your test infrastructure, but it doesn’t give you parallelization for free. It can handle as many connections as you throw at it (within reason), but you still need to find a way to execute your tests in parallel (with your test framework, for instance). Also, if you are considering standing up your own grid, be sure to check out docker-selenium, Selenium-Grid-Extras, and SeleniumGridScaler.
Selenium Service Providers
Rather than take on the overhead of a standing up and maintaining a test infrastructure, you can easily outsource things to a third-party cloud provider (a.k.a. someone else’s Grid) like Sauce Labs.
Note: You’ll need an account to use Sauce Labs. Their free trial offers enough to get you started. And if you’re signing up because you want to test an open-source project, then be sure to check out their Open Sauce account.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("browserName", "firefox");
capabilities.setCapability("version", "33");
capabilities.setCapability("platform", "Windows XP");
String sauceUrl = String.format("http://%s:%[email protected]:80/wd/hub",
sauceUser, sauceKey);
driver = new RemoteWebDriver(new URL(sauceUrl), capabilities);
Note: You can see a full list of Sauce Labs’ available platform options here. There’s also a handy configuration generator that will tell you what values to plug into your test. Be sure to check out Sauce Labs’ documentation portal for more details.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}