Official document: http://www.seleniumhq.org/docs/07_selenium_grid.jsp
1. Suppose you have two machines with necessary JDK, drivers, selenium-server-standalone-***.jar
Machine one (IP: 192.168. 1.100): (Used as the hub)
Java -jar selenium-server-standalone-2.53.0.jar -role hub
Note: the default port is 4444, you can use -port option to change it as below:
java -jar selenium-server-standalone-2.53.0.jar -role hub -port 4455
Open the url: http://localhost:4444 to check the server status.
Machine two (IP: 192.168.1.110): (Used as the node)
java -jar selenium-server-standalone-2.53.0.jar -role node -hub http://192.168.1.100:4444/grid/register
Note: 1. The IP (192.168.1.100) is your server ip.
2. The default port is 5555, you can use -port to change it.
A simple test case:
package testcases; import java.net.MalformedURLException; import java.net.URL; import org.openqa.selenium.By; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class TestBaidu { public static void main(String[] args) throws MalformedURLException { // TODO Auto-generated method stub DesiredCapabilities dc = DesiredCapabilities.chrome();
// Use this to launch firefox
// DesiredCapabilities dc = DesiredCapabilities.firefox(); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://192.168.0.110:5555/wd/hub"), dc); String url = "http://www.baidu.com"; driver.get(url); driver.findElement(By.id("kw")).sendKeys("Hello Webdriver!"); driver.findElement(By.id("su")).click(); System.out.println(driver.getTitle()); driver.quit(); } }
Note: The IP 192.168.0.110 is your node IP
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://192.168.0.110:5555/wd/hub"), dc);