Selenium grid is powerful and can be easily used with just few lines of code.
A Grid is a network of computers which can be heterogeneous and geographically dispersed.
A Selenium Grid is how a grid of computers are connected using Selenium and configured to perform a task.
A task typically here is running a suite of test cases with different browsers in different platforms across geographically dispersed systems. The test cases can be run in parallel using Selenium.
So if we have a grid of three computers the same set of test cases can be run in IE, Firefox and Chrome.
To establish this we have three important components.
1) Hub
2) Node
3) Test Script
A Hub acts like the server to which requests are sent. The Hub sends to request to various registered nodes. The HUB can be instantiated using command line by using the selenium server standalone jar file.
Open command prompt, navigate to the folder which has the selenium server file and use this command.
java -jar selenium-server-standalone-2.14.0.jar -role hub
-role is the parameter to set the role the program plays. In Java, when executing commands through command line parameters are passed with "-" in front of it. -browsername,-platform are other parameters.
The hub will start using default port 4444. You have a console to view the status of the hub, the connected nodes etc. The console can be accessed using http://localhost:4444/grid/console
A Node registers itself to the hub to provide services. A Node and a hub can exist in the same local system.
Start the node in the command prompt by using the command
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:4444/hub/register
Using this command we register our node with the hub that we started. If the hub and node are not in the same system, you can use the IP Address in place of the localhost
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register
The node will start using default port 5555.
The nodes are configured by default to provide 5 firefox, 5 chrome and 1 IE instances. This can be modified using command line settings.
This can be done using command prompt. You can decide what services your node should provide by setting the platform, browsername and version
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register -browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX
You can specify more than one browser switch using -browser.
Test Script is the program which should use this capability. As discussed in earlier chapters you need to use RemoteWebDriver and DesiredCapabilities to use grid feature.
DesiredCapabilities capability = DesiredCapabilities.firefox();
A Grid is a network of computers which can be heterogeneous and geographically dispersed.
A Selenium Grid is how a grid of computers are connected using Selenium and configured to perform a task.
A task typically here is running a suite of test cases with different browsers in different platforms across geographically dispersed systems. The test cases can be run in parallel using Selenium.
So if we have a grid of three computers the same set of test cases can be run in IE, Firefox and Chrome.
To establish this we have three important components.
1) Hub
2) Node
3) Test Script
A Hub acts like the server to which requests are sent. The Hub sends to request to various registered nodes. The HUB can be instantiated using command line by using the selenium server standalone jar file.
Open command prompt, navigate to the folder which has the selenium server file and use this command.
java -jar selenium-server-standalone-2.14.0.jar -role hub
-role is the parameter to set the role the program plays. In Java, when executing commands through command line parameters are passed with "-" in front of it. -browsername,-platform are other parameters.
The hub will start using default port 4444. You have a console to view the status of the hub, the connected nodes etc. The console can be accessed using http://localhost:4444/grid/console
A Node registers itself to the hub to provide services. A Node and a hub can exist in the same local system.
Start the node in the command prompt by using the command
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:4444/hub/register
Using this command we register our node with the hub that we started. If the hub and node are not in the same system, you can use the IP Address in place of the localhost
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register
The node will start using default port 5555.
The nodes are configured by default to provide 5 firefox, 5 chrome and 1 IE instances. This can be modified using command line settings.
This can be done using command prompt. You can decide what services your node should provide by setting the platform, browsername and version
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://192.14.54.134:4444/hub/register -browser browserName=firefox,version=3.6,maxInstances=5,platform=LINUX
You can specify more than one browser switch using -browser.
Test Script is the program which should use this capability. As discussed in earlier chapters you need to use RemoteWebDriver and DesiredCapabilities to use grid feature.
DesiredCapabilities capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform("WINDOWS");
capability.setVersion("3.6")
capability.setPlatform("WINDOWS");
capability.setVersion("3.6")
Key | Type | Description |
browserName | string | The name of the browser being used; should be one of {android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari}. |
version | string | The browser version, or the empty string if unknown. |
platform | string | A key specifying which platform the browser should be running on. This value should be one of {WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID}. When requesting a new session, the client may specify ANY to indicate any available platform may be used. For more information see |
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);The hub will assign the test to a matching node.
Note: You need to have your windows and custom firewall settings configured to allow the connections between the hub and nodes to happen. When running the test cases in parallel, make sure the web driver instances are deallcoated at the end of the test case.
All properties that are set with respect to the browser like where to find the driver executable should be done in the node. System.setproperty("webdriver.ie.driver","path to driver executable") won't work when you are using grid.
Note: You need to have your windows and custom firewall settings configured to allow the connections between the hub and nodes to happen. When running the test cases in parallel, make sure the web driver instances are deallcoated at the end of the test case.
All properties that are set with respect to the browser like where to find the driver executable should be done in the node. System.setproperty("webdriver.ie.driver","path to driver executable") won't work when you are using grid.
Eg:java -jar selenium-server-standalone-2.31.0.jar -role node -hub http://localhost:4444/grid/register
-maxSession 15 -browser browserName="chrome",version=ANY,platform=WINDOWS,maxInstances=15
-Dwebdriver.chrome.driver=lib\chromedriver.exe
Comments
Post a Comment