Selenium Grid分布式测试入门

发表于:2017-11-27 08:04

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:liangww    来源:博客园

  4.4 更多选项
  关于Selenium Grid更多命令选项,可运行--help查看:
d:\grid>java -jar selenium-server-standalone-3.5.0.jar --help
Usage: <main class> [options]
Options:
--version, -version
Displays the version and exits.
Default: false
-browserTimeout
<Integer> in seconds : number of seconds a browser session is allowed to
hang while a WebDriver command is running (example: driver.get(url)). If the
timeout is reached while a WebDriver command is still processing, the session
will quit. Minimum value is 60. An unspecified, zero, or negative value means
wait indefinitely.
Default: 0
-debug
<Boolean> : enables LogLevel.FINE.
Default: false
-enablePassThrough
<Boolean>: Whether or not to use the experimental passthrough mode.
Defaults to true.
Default: true
-jettyThreads, -jettyMaxThreads
<Integer> : max number of threads for Jetty. An unspecified, zero, or
negative value means the Jetty default value (200) will be used.
-log
<String> filename : the filename to use for logging. If omitted, will log
to STDOUT
-port
<Integer> : the port number the server will use.
Default: 4444
-role
<String> options are [hub], [node], or [standalone].
Default: standalone
-timeout, -sessionTimeout
<Integer> in seconds : Specifies the timeout before the server
automatically kills a session that hasn't had any activity in the last X seconds. The
test slot will then be released for another test to use. This is typically
used to take care of client crashes. For grid hub/node roles, cleanUpCycle
must also be set.
Default: 1800
  5. Selenium Grid 分布式测试脚本
  下面,我们编写一个Selenium Grid自动化测试脚本,分别在3个node上运行Chrome,Firefox及IE浏览器,执行WEB页面自动化测试。
  示例脚本如下:
# coding:utf-8
from selenium.webdriver import Remote
import time
# 定义node_hub与浏览器对应关系
nodes = {
'http://127.0.0.1:5555/wd/hub': 'chrome',
'http://127.0.0.1:5556/wd/hub': 'internet explorer',
'http://127.0.0.1:5557/wd/hub': 'firefox'
}
# 通过不同的浏览器执行测试脚本
for host, browser in nodes.items():
print(host, browser)
# 调用remote方法
driver = Remote(command_executor=host,
desired_capabilities={'platform': 'ANY', 'browserName': browser, 'version': '', 'javascriptEnabled': True})
# 打开百度首页并搜索词语,最后判断搜索跳转页面标题是否含有搜索词
wd = 'lovesoo'
driver.get('https://www.baidu.com')
driver.find_element_by_id("kw").send_keys(wd)
driver.find_element_by_id("su").click()
time.sleep(1)
assert wd in driver.title, '{0} not in {1}'.format(wd, driver.title.encode('utf-8'))
driver.quit()
  运行结果如下:
('http://127.0.0.1:5555/wd/hub', 'chrome')
('http://127.0.0.1:5557/wd/hub', 'firefox')
('http://127.0.0.1:5556/wd/hub', 'internet explorer')
  6. 常见问题
  脚本运行过程中若IE浏览器报错找不到元素,而Chrome及Firefox浏览器正常,原因是IE浏览器的保护模式没有关闭:
  1) 打开IE浏览器,在浏览器的菜单栏上点击“工具”选项,然后点击“Internet选项”
  2) 在“Internet选项”中,切换到“安全”选项,取消“启用保护模式”的勾选
  3) 并且上面四个区域的保护模式都需要关闭
22/2<12
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号