Execute tests on Selenium Grid
Hello Folks, if you are new to this series, I recommend starting from the first post -
Alright, moving ahead from our last post, where we learned about setting up the Selenium grid, let us now understand how to execute our tests -
After completing the four steps mentioned above, testers can use the Selenium Grid to execute tests. In case the Selenium 1 RC nodes are utilized, the DefaultSelenium object can be used by testers. This can be passed in the hub formation using the following command.
Selenium selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, “https://www.mdhakite.xyz”);To utilize Remote WebDriver nodes, testers need to use RemoteWebDriver and DesiredCapabilities objects to specify the browser, version, and platform. Firstly, create the desired browser capabilities for test execution using the code:
DesiredCapabilities cap = DesiredCapabilities.firefox();Then, pass this capability set into the RemoteWebDriver object using the following code:
WebDriver driver = new RemoteWebDriver(new URL("https://localhost:4444/wd/hub"), cap);Once done, the hub will allocate the test to a corresponding node if all the requested capabilities are met. To request specific capabilities on the grid, define them before passing them to the WebDriver object in the below pattern:
cap.setBrowserName();
cap.setPlatform();
cap.setVersion()
cap.setCapability(,);If the specified capabilities are not available on the Grid, the code will not find a match, and hence the test will fail to run.
For instance, let's consider a node that has the following settings registered:
-browser browserName=firefox,version=4,maxInstances=4,platform=WINDOWSThen, it will match with the below set of capabilities defined for the test:
cap.setBrowserName(“firefox” );
cap.setPlatform(“WINDOWS”);
cap.setVersion(“4”);Note that the capabilities that are not specified for the test will be ignored. For instance, in the above example, if the platform parameter is not mentioned, yet it will get a match.
You can also set Desired Capabilities by using BrowserStack Capabilities Generator
With the help of these steps, testers can effortlessly establish, customize, and execute test suites on the Selenium Grid to achieve concurrent test execution.
Wish to Learn More about Selenium Grid
Great to hear that you're interested in learning more about AutoScaling with Selenium Grid. Let me explain a bit more about the problem that can occur with the approach we discussed.
When we define a fixed number of nodes in our Selenium Grid setup, it means that the grid can handle only a limited number of concurrent test runs. This can cause a bottleneck in your testing process as any additional test requests beyond this limit will have to wait in the queue until one of the nodes becomes available.
To avoid this bottleneck, we can use AutoScaling. AutoScaling allows you to dynamically increase or decrease the number of nodes in your Selenium Grid setup based on the demand for test runs. This ensures that your grid can handle any number of concurrent test runs without any waiting time.
In our next post, we will dive deeper into AutoScaling and how to implement it with Selenium Grid. Stay tuned!