1 两台计算机,一台计算机既做HUB,又做Node
机器A设置HUB的步骤:
1 运行---输入cmd
2 输入: cd c:/
3 输入: java -jar selenium-server-standalone-2.48.2.jar -role hub
设置node的步骤:
1 运行---输入cmd
2 输入: cd c:/
3 输入: java -jar selenium-server-standalone-2.48.2.jar -role node -port 5555 -hub http://HubIP:4444/grid/register -maxSession 15 -browser browserName="ie",version=ANY,platform=WINDOWS,maxInstances=15 -Dwebdriver.ie.driver=C:\IEDriverServer.exe
机器B设置Node的步骤:
同机器A设置node的步骤
2 testng.xml的设置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestNGSuite" parallel="classes" thread-count="2"
verbose="1">
<test name="Test2" preserve-order="true">
<parameter name="seleniumHost" value="172.16.107.74" />
<parameter name="seleniumPort" value="5555" />
<parameter name="name" value="100001" />
<parameter name="password" value="100001" />
<parameter name="seleniumHost1" value="192.168.198.128" />
<parameter name="seleniumPort1" value="5556" />
<parameter name="name1" value="100002" />
<parameter name="password1" value="100002" />
<classes>
<class name="cn.test.testScripts.TestsuijiPbgc1" />
<class name="cn.test.testScripts.TestsuijiPbgc2" />
</classes>
</test>
</suite>
3代码设置
@Parameters({ "seleniumHost", "seleniumPort" ,"name", "password" })
@BeforeClass
public void beforeMethod(String seleniumHost,String seleniumPort,String name,String password) {
DOMConfigurator.configure("log4j.xml");
//System.setProperty("webdriver.ie.driver",
// "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities
.internetExplorer();
ieCapabilities
.setCapability(
InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
//ieCapabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, true);
try {
//driver = new InternetExplorerDriver(ieCapabilities);
driver = new RemoteWebDriver(new URL("http://" + seleniumHost + ":"+seleniumPort+"/wd/hub"), ieCapabilities);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
long id = Thread.currentThread().getId();
System.out.println("这个是电脑1,After test-method. Thread id is: " + id);
Login_Action.excutepw(driver, name, password);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}