Selenium Grid2分布式执行测试脚本
来源:互联网 发布:java递归获取父节点 编辑:程序博客网 时间:2024/05/22 13:23
Selenium grid是用来分布式执行测试用例脚本的工具,比如测试人员经常要测试多浏览器的兼容性,那就可以用到grid了。下面就来介绍如何在多个浏览器上运行同一份脚本。
使用grid所需要的文件:1.Selenium server(即selenium-server-standalone-x.xx.x.jar);2.grid配置文件(该文件负责提供主机和浏览器信息);3.测试脚本。
1.先来看看grid配置文件的内容:
def grid(): d={'http://127.0.0.1:4444/wd/hub' : 'firefox', 'http://127.0.0.1:5555/wd/hub' : 'internet explorer', } return d
该文件定义了一个方法,该方法存放了一个字典,分别给本机分配了2个不同的端口并指定了不同的浏览器(4444是grid hub的默认端口,5555这个是一个node的端口,后续会介绍)。
2.再来看看测试脚本:
# encoding:utf-8from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesimport time, os.pathimport grid_modulefor host, browser in grid_module.grid().items(): driver = webdriver.Remote( command_executor=host, desired_capabilities={ 'platform': 'ANY', 'browserName': browser, 'version': '', 'javascriptEnabled': True } ) driver.get("http://www.baidu.com") driver.find_element_by_id("kw").send_keys(u"中国") driver.find_element_by_id("su").click() time.sleep(3) if driver.title == u"中国_百度搜索": print("title匹配!") else: print("title不匹配!") driver.close()
该脚本是写了一个百度搜索关键词并做了简单断言的脚本,导入的grid_module就是第一步中的grid配置文件,循环体中写的是从字典中取出主机名和浏览器名赋给下面的参数,这样的话该测试脚本就会接连调用本地的2个指定浏览器并运行。
3.然后就启server了,从http://selenium-release.storage.googleapis.com/index.html上下载对应版本的Selenium server:
下载下来后打开cmd,输入java -jar selenium-server-standalone-x.xx.x.jar -role hub
,这是万恶之源,先启它才能干后面的事。启动之后再打开一个cmd,输入java -jar selenium-server-standalone-x.xx.x.jar -role node -port 5555
,这是启动第一个node,指定端口5555,与grid配置文件中所写的端口一致。
hub和node启动好之后我们在浏览器里输入http://127.0.0.1:4444/grid/console,打开grid的控制台:
我们能看到有一个端口为5555的node已经启动起来了,此处的IP就是本机IP。
4.最后我们运行测试脚本,2个浏览器乖乖地启起来了呢~
- Selenium Grid2分布式执行测试脚本
- Selenium Grid2做分布式测试
- 使用 Selenium Grid2 来提高全球化测试中自动化截图的执行效率
- Selenium Grid2
- 利用jenkins分布式执行selenium自动化测试
- selenium-grid2 远程并发控制用例执行
- Selenium-grid2 远程并发控制用例执行
- selenium-grid2 远程并发控制用例执行
- 执行 Selenium WebDriver 测试脚本抛出 StaleElementReferenceException
- 用Selenium WebDriver+Grid2实现浏览器端性能测试
- 如何搭建Selenium-Grid2环境(Java)(自动化测试技术)
- Selenium-Grid2 配置
- selenium grid2 - node说明
- Eclipse 执行 Selenium WebDriver 测试脚本无法启动浏览器
- selenium 分布式部署测试
- 利用 Selenium WebDriver + Grid2 实现并行的浏览器端性能测试
- 利用 Selenium WebDriver + Grid2 实现并行的浏览器端性能测试
- Selenium测试脚本
- HDU 3068 最长回文 (Manacher 模板题)
- JFinal Web开发学习(十)前后台显示博客列表
- 算法学习-查找旋转数组的最小值
- iOS 当定义一个类继承UICollectionReusableView时,宽度不能自适应的解决办法
- 推荐系统研究常用数据库
- Selenium Grid2分布式执行测试脚本
- 283. Move Zeroes
- servlet和filter路径
- 关于matlab中textread
- js比较2个日期相差的天数
- less 命令
- SpringAOP
- 各大Oj平台介绍
- 对称 非对称加密 RSA MD5 概念