多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

Selenium grid使用方法-自动化测试

更新时间:2022-05-06 09:35:58 作者:多测师 浏览:622

  代码和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

Selenium grid使用方法-自动化测试

  代码如下

  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()

  以上内容为大家介绍了自动化测试中的Selenium grid使用方法,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部