selenium grid 使用方法

本文介绍了如何配置和使用Selenium Grid进行跨平台、跨浏览器的自动化测试。通过设置不同的节点,可以指定特定的操作系统和浏览器版本来运行测试案例。

代码和selenium driver相同 只是 启动环境方式不同。至少启动一个hub 一个 node 。如需要多个,可以使用端口进行区分。

  1. java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5555  
  2. java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5556  
  3. java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5557
  4. 代码如下

WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap); 

//test01: 只匹配Windows下的ie来执行此用例,版本不限;多个版本匹配成功时优先级暂未知  

  1. DesiredCapabilities aDesiredcap = DesiredCapabilities();  
  2. aDesiredcap.setBrowserName("internet explorer")  
  3. aDesiredcap.setVersion("")  
  4. aDesiredcap.setPlatform(Platform.WINDOWS)  
  5. WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);  
  6. wd.doSomething()  
  7.   
  8. //test02: 只匹配linix下的firefox的版本为22的浏览器执行用例;    
  9. DesiredCapabilities aDesiredcap = DesiredCapabilities("firefox""22", Platform.LINUX);  
  10. WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);  
  11. wd.doSomething()      
  12.   
  13. //test03: 只匹配MAC下的safari浏览器执行,版本不限    
  14. DesiredCapabilities aDesiredcap = DesiredCapabilities.safari();  
  15. aDesiredcap.setPlatform(Platform.MAC)  
  16. WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);  
  17. wd.doSomething()      
  18.   
  19. //test04: 只匹配chrome浏览器,任意平台,任意版本  
  20. DesiredCapabilities aDesiredcap = DesiredCapabilities.chrome();  
  21. aDesiredcap.setPlatform(Platform.ANY)  
  22. WebDriver wd = new RemoteDriver("http://localhost:4444/wd/hub", aDesiredcap);  
  23. wd.doSomething() 

转载于:https://www.cnblogs.com/wcLT/p/3394375.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值