python webdriver grid多节点运行webdriver程序
grid整理:
机制
Hub机器和节点机器上要装jdk和jar包
A机器:hub 中控:用来监控所有节点机的状态
启动命令:
java -jar selenium-server-standalone-3.8.1.jar -role hub
启动成功结果显示:
INFO - Registered a node http://192.168.1.105:6666
B机器:节点机1,注册到hub机器上,角色是webdriver节点
启动节点机命令:
java -jar selenium-server-standalone-3.8.1.jar -role webdriver -hub http://127.0.0.1:4444/grid/register-Dwebdriver.chrome.driver="c:\chromedriver.exe"-Dwebdriver.ie.driver="d:\test\IEDriverServer.exe"-Dwebdriver.firefox.driver="c:\geckodriver.exe" -port 6666 -maxSession 5 -browser browserName="internet explorer",maxInstances=5 -browser browserName="chrome",maxInstances=5 -browser browserName="firefox",maxInstance=5
解释:
1-注意jar包的版本号3.8.1,要统一,且和机器上的该目录下的jar包信息一致
2-http://127.0.0.1:4444,是A机器中控机的ip和默认端口4444,后边接浏览器类型
3-"d:\chromedriver.exe" 是在节点机上的驱动路径
4-6666节点机对外服务的端口默认就是6666,5000以上都可以,没有限制
5-maxInstances=5,表示单独某个浏览器启动最多5个
6-maxSession 5,节点不同种浏览器启动的个数上限是5个,总数限制
注册节点机成功后提示:
The node is registered to the hub and ready to use
d机器:发起脚本执行的机器:
脚本内容:
driver = webdriver.Remote(
# 设定Node节点的URL地址,后续将通过访问这个地址连接到Node计算机
#节点机的ip
command_executor = 'http://localhost:6666/wd/hub',
desired_capabilities = {
# 指定远程计算机执行使用的浏览器为firefox
"browserName": "firefox",
"video": "True",
# 远程计算机的平台
"platform": "WINDOWS"
#"platform": "windows_nt"
})
操作步骤
起hub:
java -jar selenium-server-standalone-3.8.1.jar -role hub
起节点机:三种浏览器都有
java -jar selenium-server-standalone-3.8.1.jar -role webdriver -hub http://127.0.0.1:4444/grid/register-Dwebdriver.chrome.driver="c:\chromedriver.exe"-Dwebdriver.ie.driver="d:\test\IEDriverServer.exe"-Dwebdriver.firefox.driver="c:\geckodriver.exe" -port 6666 -maxSession 5 -browser browserName="internet explorer",maxInstances=5 -browser browserName="chrome",maxInstances=5 -browser browserName="firefox",maxInstance=5
脚本:
test_grid_by_firefox.py:
#encoding=utf-8
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Remote(
# 设定Node节点的URL地址,后续将通过访问这个地址连接到Node计算机
command_executor = 'http://localhost:6666/wd/hub',
desired_capabilities = {
# 指定远程计算机执行使用的浏览器为firefox
"browserName": "firefox",
"video": "True",
# 远程计算机的平台
"platform": "WINDOWS"
#"platform": "windows_nt"
})
print ("Video: " + "http://www.baidu.com" + driver.session_id)
try:
#driver.implicitly_wait(30)
driver.maximize_window()
driver.get("http://www.sogou.com")
assert u"搜狗" in driver.title
elem = driver.find_element_by_id("query")
elem.send_keys(u"webdriver实战宝典")
elem.send_keys(Keys.RETURN)
time.sleep(3)
assert u"吴晓华" in driver.page_source
print 'done!'
finally:
driver.quit()
结果:
起hub中控机:
d:\test>java -jar selenium-server-standalone-3.8.1.jar -role hub
22:27:48.714 INFO - Selenium build info: version: '3.8.1', revision: '6e95a6684b'
22:27:48.715 INFO - Launching Selenium Grid hub
2018-07-02 22:27:50.394:INFO::main: Logging initialized @2117ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:27:50.420 INFO - Will listen on 4444
2018-07-02 22:27:50.554:INFO:osjs.Server:main: jetty-9.4.7.v20170914
2018-07-02 22:27:50.607:INFO:osjs.session:main: DefaultSessionIdManager workerName=node0
2018-07-02 22:27:50.608:INFO:osjs.session:main: No SessionScavenger set, using defaults
2018-07-02 22:27:50.612:INFO:osjs.session:main: Scavenging every 600000ms
2018-07-02 22:27:50.639:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@18a70f16{/,null,AVAILABLE}
2018-07-02 22:27:50.664:INFO:osjs.AbstractConnector:main: Started ServerConnector@67e2d983{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2018-07-02 22:27:50.665:INFO:osjs.Server:main: Started @2389ms
22:27:50.666 INFO - Nodes should register to http://192.168.1.105:4444/grid/register/
22:27:50.666 INFO - Selenium Grid hub is up and running
22:28:13.139 WARN - Max instance not specified. Using default = 1 instance
22:28:13.147 INFO - Registered a node http://192.168.1.105:6666
起节点机:
D:\test>java -jar selenium-server-standalone-3.8.1.jar -role webdriver -hub http://127.0.0.1:4444/grid/register-Dwebdriver.chrome.driver="c:\chromedriver.exe"-Dwebdriver.ie.driver="d:\test\IEDriverServer.exe"-Dwebdriver.firefox.driver="c:\geckodriver.exe" -port 6666 -maxSession 5 -browser browserName="internet explorer",maxInstances=5 -browser browserName="chrome",maxInstances=5 -browser browserName="firefox",maxInstance=5
22:28:11.177 INFO - Selenium build info: version: '3.8.1', revision: '6e95a6684b'
22:28:11.178 INFO - Launching a Selenium Grid node
2018-07-02 22:28:12.593:INFO::main: Logging initialized @1908ms to org.seleniumhq.jetty9.util.log.StdErrLog
22:28:12.669 INFO - Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
22:28:12.701 INFO - Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
22:28:12.710 INFO - Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()`
22:28:12.712 INFO - Driver class not found: com.opera.core.systems.OperaDriver
22:28:12.713 INFO - Using `new OperaOptions()` is preferred to `DesiredCapabilities.operaBlink()`
22:28:12.715 INFO - Using `new SafariOptions()` is preferred to `DesiredCapabilities.safari()`
22:28:12.717 INFO - Driver class not found: org.openqa.selenium.phantomjs.PhantomJSDriver
22:28:12.756 INFO - Driver provider class org.openqa.selenium.safari.SafariDriver registration is skipped:
registration capabilities Capabilities {browserName: safari, platform: MAC, version: } does not match the current platform WIN10
22:28:12.802 INFO - Using `new ChromeOptions()` is preferred to `DesiredCapabilities.chrome()`
22:28:12.804 INFO - Using `new EdgeOptions()` is preferred to `DesiredCapabilities.edge()`
22:28:12.804 INFO - Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
22:28:12.805 INFO - Using `new OperaOptions()` is preferred to `DesiredCapabilities.operaBlink()`
22:28:12.805 INFO - Using `new SafariOptions()` is preferred to `DesiredCapabilities.safari()`
22:28:12.815 INFO - Using the passthrough mode handler
2018-07-02 22:28:12.851:INFO:osjs.Server:main: jetty-9.4.7.v20170914
2018-07-02 22:28:12.898:WARN:osjs.SecurityHandler:main: ServletContext@o.s.j.s.ServletContextHandler@6f4a47c7{/,null,STARTING} has uncovered http methods for path: /
2018-07-02 22:28:12.908:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@6f4a47c7{/,null,AVAILABLE}
2018-07-02 22:28:12.936:INFO:osjs.AbstractConnector:main: Started ServerConnector@4c309d4d{HTTP/1.1,[http/1.1]}{0.0.0.0:6666}
2018-07-02 22:28:12.939:INFO:osjs.Server:main: Started @2253ms
22:28:12.940 INFO - Selenium Grid node is up and ready to register to the hub
22:28:12.976 INFO - Starting auto registration thread. Will try to register every 5000 ms.
22:28:12.977 INFO - Registering the node to the hub: http://127.0.0.1:4444/grid/register
22:28:13.147 INFO - The node is registered to the hub and ready to use
注册成功后
访问http://127.0.0.1:4444/grid/console可以看到注册到hub的driver情况
可以在view config看到配置
脚本结果:
D:\test>python test.py
Video: http://www.baidu.com9e11588b-935d-4a97-a92c-cef268dea154
done!
总结一下:
用grid多节点功能,需要注意的点比较多,如:
一、不同的浏览器和驱动可能运行不起来,需要自己调试哪个版本的好用,目前可以确定firefox49版本和对应驱动可以跑起来,ie和chrome还不确定哪些一定可以
二、另外注册节点机的时候,即使驱动目录不存在也会提示注册成功,要通过访问http://127.0.0.1:4444/grid/console查看注册的webdriver信息和或运行脚本程序时才能验证是否真正注册成功
三、在同一台机器上跑时,需要注意运行注册命令的目录和跑脚本的目录,不是一个的话,可能会有问题,待验证
四、grid的原理是在hub机器、节点机、跑脚本的机器是独立的机器时,跑的,此种场景需要在多台机器上验证
python webdriver grid多节点运行webdriver程序的更多相关文章
- Python系统调用——运行其他程序
转载:http://blog.csdn.net/ssihc0/article/details/7738527 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其 ...
- python中的commands模块,执行出错:'{' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
最近发现了python的commands模块,查看了下源码,使用的popen封装的,形成三个函数getstatus(), getoutput(), getstatusoutput() 源码如下: de ...
- python简单的监控脚本-利用socket、psutil阻止远程主机运行特定程序
python简单的监控脚本-利用socket.psutil阻止远程主机运行特定程序 psutil是一个跨平台的库(http://code.google.com/p/psutil/),能够轻松的实现获取 ...
- Python中四种运行其他程序的方式
原文地址:http://blog.csdn.net/jerry_1126/article/details/46584179 在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在 ...
- Jenkins构建Python项目提示:'python' 不是内部或外部命令,也不是可运行的程序
问题描述: jenkin集成python项目,立即构建后,发现未执行成功,查看Console Output 提示:'Python' 不是内部或外部命令,也不是可运行的程序,如下图: 1.在 Windo ...
- Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors
Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors 1,分析原因: 根本原因是Chromedriver和Chrome的版本不兼容: 网 ...
- Python 运行其他程序
10.4 运行其他程序 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程, ...
- python 命令行:help(),'more'不是内部或外部命令,也不是可运行的程序或批处理文件
Python下使用help(dict),显示'more'不是内部或外部命令,也不是可运行的程序或批处理文件,该如何处理? 环境变量设置的问题,进入 Path 的环境变量设置界面,将;%SystemRo ...
- Python版:Selenium2.0之WebDriver学习总结_实例1
Python版:Selenium2.0之WebDriver学习总结_实例1 快来加入群[python爬虫交流群](群号570070796),发现精彩内容. 实属转载:本人看的原文地址 :http:/ ...
随机推荐
- capitalize()
capitalize() 是字符串的一个方法,用于把字符串的第一个字母转换成大写 In [1]: str = 'hello world' In [2]: str.capitalize() Out[2] ...
- cocos2dx游戏--欢欢英雄传说--为敌人添加移动和攻击动作
这里主要为敌人添加了一个移动动作和攻击动作.移动动作是很简略的我动他也动的方式.攻击动作是很简单的我打他也打的方式.效果:代码: #ifndef __Progress__ #define __Prog ...
- ceph 存储安装部署
环境准备 1.三台服务器 cephnode01 192.168.254.83 cephnode02 192.168.254.84 cephnode03 192.168.254.85 2.基本环境配置 ...
- javascript字符串函数
substring() 从字符串中提取一些字符 <script type="text/javascript"> var str="Hello world!&q ...
- linux下php安装
nginx中配置php: http://www.111cn.net/sys/nginx/64044.htm
- Express 框架的安装
从零开始用 Node.js 实现一个微博系统,功能包括路由控制.页面模板.数据库访问.用户注册.登录.用户会话等内容. Express 框架. MVC 设计模式. ejs 模板引擎 MongoDB 数 ...
- jhipser微服务架构介绍
内容提要 本文涉及以下内容: 微服务架构介绍 spring cloud介绍 jhipster架构介绍 微服务架构介绍 微服务概念 微服务和SOA很相似,都是按照业务功能把系统拆分成一个一个的服务.比如 ...
- 【MySQL案例】error.log的Warning:If a crash happens thisconfiguration does not guarantee that the relay lo(转)
标签: 1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be c ...
- 设备加速传感器(accelerometer) ---- HTML5+
模块:Accelerometer Accelerometer模块管理设备加速度传感器,用于获取设备加速度信息,包括x(屏幕水平方向).y(垂直屏幕水平方向).z(垂直屏幕平面方向)三个方向的加速度信息 ...
- maven学习(二)(转)
一.maven父工程与子模块的拆分与聚合原理 问题描述:将ssh工程拆分为多个模块开发 1.1.拆分原理 创建一个maven project(pom),然后在创建三个子模块(maven moudule ...