Selenium grid 使用方法

代码和selenium driver相同 只是 启动环境方式不同。至少启动一个hub 一个 node 。如需要多个,可以使用端口进行区分。
java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5555
java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5556
java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5557
  代码如下
WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);
//test01: 只匹配Windows下的ie来执行此用例,版本不限;多个版本匹配成功时优先级暂未知
DesiredCapabilities aDesiredcap = DesiredCapabilities();
aDesiredcap.setBrowserName("internet explorer")
aDesiredcap.setVersion("")
aDesiredcap.setPlatform(Platform.WINDOWS)
WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);
wd.doSomething()
//test02: 只匹配linix下的firefox的版本为22的浏览器执行用例;
DesiredCapabilities aDesiredcap = DesiredCapabilities("firefox", "22", Platform.LINUX);
WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);
wd.doSomething()
//test03: 只匹配MAC下的safari浏览器执行,版本不限
DesiredCapabilities aDesiredcap = DesiredCapabilities.safari();
aDesiredcap.setPlatform(Platform.MAC)
WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);
wd.doSomething()
//test04: 只匹配chrome浏览器,任意平台,任意版本
DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();
aDesiredcap.setPlatform(Platform.ANY)
WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);
wd.doSomething()

最新内容请见作者的GitHub页:http://qaseven.github.io/
上一篇:《精通 ASP.NET MVC 4》----第 2 章 第一个MVC应用程序 2.1 准备工作站


下一篇:mysql数据库去重复