Hub机器输入
java -jar selenium-jar-statnjld.jar -role hub
Node机器输入:
java -jar sel....... -role webdriver -hub 主机:4444/gird/register -port 6655
注意:火狐版本不要处于加载插件中,尽量版本不要太高
package com.gloryroad.remote;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.os.WindowsUtils;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.sun.jna.platform.unix.X11.Window;
public class TestSeleniumGrid {
WebDriver driver;
public static String baseUrl="http://www.baidu.com";
public static String nodeUrl="http://192.168.0.103:6655/wd/hub";
@BeforeMethod
public void setUp() throws MalformedURLException, InterruptedException{
//设定远程节点的操作系统和浏览器,需要设定DesiredCapabilities.
DesiredCapabilities des=DesiredCapabilities.firefox();
//设定远程浏览器的名称
des.setBrowserName("firefox");
//设定远程的操作系统平台
des.setPlatform(Platform.XP);
Thread.sleep(5000);
//使用RemoteWebDriver对象生成一个远程连接的Driver
driver=new RemoteWebDriver(new URL(nodeUrl), des);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20000, TimeUnit.SECONDS);
}
@AfterMethod
public void tearDown()
{
driver.quit();
}
@Test
public void testSearch()
{
for (int i = 0; i <4; i++) {
driver.get(baseUrl);
driver.get("http://sogou.com");
driver.navigate().back();
driver.get(baseUrl);
}
}
}