Earlier days we can run Selenium test in multiple machine
ONLY using Selenium 1 RC (The Project name called
Selenium Grid). The biggest downside with Selenium Grid is that, it doesn’t support
Webdriver.
But now with
Grid 2, both
Selenium 1 and Webdriver are supported and we can run test in multiple machines. Grid 2 will allow you to do following
· Scale by distributing tests on several machines ( parallel execution )
· Manage multiple environments from a central point, making it easy to run the tests against a vast combination of browsers / OS.
· Minimize the maintenance time for the grid by allowing you to implement custom hooks to leverage virtual infrastructure for instance.
Steps to run test in multiple machine using Grid 2
Step1 (HUB)
Start the Selenium standalone server with following command
java -jar selenium-server-standalone-2.14.0.jar -role hub
Now the Command prompt window will look like this
If you could see the above screen shot, selenium server once started, it started as a Selenium grid Server.
The hub will automatically start-up using port 4444 by default. To change the default port, you can add the optional parameter -port when you run the command. You can view the status of the hub by opening a browser window and navigating to:
http://localhost:4444/grid/console
Step2 (Node)
Now start the node from the same Selenium standalone server package itself in command prompt, since Selenium standalone server package itself includes Hub, Webdrivers and RC
java -jar selenium-server-standalone-2.14.0.jar -role node -hub http://localhost:4444/grid/register
Now the Console looks like this
Now once you go back to your browser and check the link
http://localhost:4444/grid/console it will look like this
By default Grid 2 starts 11 browsers : 5 Firefox, 5 Chrome, 1 Internet Explorer. The maximum number of concurrent tests is set to 5 by default.
Running Test using RC and Webdriver
For the Selenium 1 RC nodes, you can continue to use the DefaultSelenium object and pass in the hub information
Selenium selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://www.google.com”);
Similarly for running test using Webdriver, use RemoteWebDriver instead of WebDriver and DesiredCapabilities object to define browser, OS version etc.
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
Pass the code to RemoteWebdriver object also
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
The Complete working code will look like this.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
class RemoteTest {
public static void main(String[] args) throws Exception {
// Change this to match the location of your server
URL server = new URL("http://127.0.0.1:4444/wd/hub");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
System.out.println("Connecting to " + server);
WebDriver driver = new RemoteWebDriver(server, capabilities);
driver.get("http://www.google.com");
driver.quit();
}
That’s it.
Enjoy running Test in Distributed Environment !!
Thanks,
Karthik KK
How to control java robot class on remote machine. Please advice how to resolve this issue.
Hi Kartik,
HAve u ever implemented the grid with Csharp
I am a java guy – And using TestNG its very easily possible to implement grid
Whereas with Csharp I am not able to find the correct tool
Well explained, it worked for me. Thank you very much.
Hi Karthick,
I followed the same procedure and my scripts are running on nodes that i registered from my virtual box but they are not executing on remote machine.Any suggestions will be appreciated.
This script is not running at my end.
I am getting below Exception
Exception in thread “main” org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Hi
I am also getting the same error.
Were you able to find any solution.
Kindly share the solution if you have any
Thanks!!
Hope i am not too late. Use this command to run standalone server
java -jar -Dwebdriver.gecko.driver="\geckodriver.exe" .jar
I am getting below exception
org.openqa.selenium.SessionNotCreatedException: Unable to create new service: GeckoDriverService
Build info: version: ‘3.7.1’, revision: ‘8a0099a’, time: ‘2017-11-06T21:07:36.161Z’
System info: host: ‘COMP25’, ip: ‘192.168.0.106’, os.name: ‘Windows 7’, os.arch: ‘x86’, os.version: ‘6.1’, java.version: ‘1.8.0_144’
Driver info: driver.version: unknown
Command duration or timeout: 69 milliseconds