怎么让Hub分配脚本跑
public void gridTest() throws MalformedURLException, InterruptedException {
/*DesiredCapabilities fireFoxDC=DesiredCapabilities.firefox();
//指定机器的ip和hub端口,wd/hub必须要写
WebDriver driver=new RemoteWebDriver(new URL("http://192.168.191.3:4444/wd/hub"),fireFoxDC);*/
DesiredCapabilities chromeDC=DesiredCapabilities.chrome();
//指定机器的ip和hub端口,wd/hub必须要写
WebDriver driver=new RemoteWebDriver(new URL("http://192.168.137.1:4445/wd/hub"),chromeDC);
driver.get("http://www.baidu.com");
Thread.sleep(5000);
}
分发规则是越靠前的节点越早分发,第一个节点资源被占满不够用再向后分发,如果想指定node跑脚本,可以将ew RemoteWebDriver(new URL(“http://192.168.137.1:4445/wd/hub”)中的地址修改为node地址
一个脚本在不同浏览器跑(通过TestNG做数据驱动)
public class GridHub {
//创建一个注解,参数值随便设置
@DataProvider(name = "browser1")
//返回类型一定是Object
public Object[][] data(){
//return返回的后面要加引号,必须是Object类
return new Object[][]{
{"http://192.168.137.1:3333","chrome"},
{"http://192.168.137.1:5555","firefox"}
};
}
@Test(dataProvider = "browser1")//表示这个case需要拿数据的,数据来源是上面的browser1
public void testData(String url,String browser) throws MalformedURLException, InterruptedException {
DesiredCapabilities dc = null;
//判断浏览器类型
if (browser.equals("chrome")){
dc = DesiredCapabilities.chrome();
}else if(browser.equals("firefox")){
dc = DesiredCapabilities.firefox();
}else {
dc = DesiredCapabilities.internetExplorer();
}
WebDriver driver=new RemoteWebDriver(new URL(url+"/wd/hub"),dc);
driver.get("http://www.baidu.com");
Thread.sleep(5000);
driver.quit();
}
脚本都是通过一个xml文件running的,除了右键run跑脚本,也可以通过外部的xml文件跑
可以将该文件重命名后复制到项目中
右击xml文件跑起来,如果要跑类下面的所有test,将methods标签都删掉
TestNG 并发配置
在xml文件中添加如下内容:
添加线程后3个Test同时跑,不添加是一个一个跑
假设排除某个case不用跑,用exclude排除。也可以添加更多的class,多个类同时跑