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程序的更多相关文章

  1. Python系统调用——运行其他程序

    转载:http://blog.csdn.net/ssihc0/article/details/7738527 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其 ...

  2. python中的commands模块,执行出错:'{' 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    最近发现了python的commands模块,查看了下源码,使用的popen封装的,形成三个函数getstatus(), getoutput(), getstatusoutput() 源码如下: de ...

  3. python简单的监控脚本-利用socket、psutil阻止远程主机运行特定程序

    python简单的监控脚本-利用socket.psutil阻止远程主机运行特定程序 psutil是一个跨平台的库(http://code.google.com/p/psutil/),能够轻松的实现获取 ...

  4. Python中四种运行其他程序的方式

    原文地址:http://blog.csdn.net/jerry_1126/article/details/46584179 在Python中,可以方便地使用os模块来运行其他脚本或者程序,这样就可以在 ...

  5. Jenkins构建Python项目提示:'python' 不是内部或外部命令,也不是可运行的程序

    问题描述: jenkin集成python项目,立即构建后,发现未执行成功,查看Console Output 提示:'Python' 不是内部或外部命令,也不是可运行的程序,如下图: 1.在 Windo ...

  6. Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors

    Python3.x:chrome运行webdriver脚本提示--ignore-certificate-errors 1,分析原因: 根本原因是Chromedriver和Chrome的版本不兼容: 网 ...

  7. Python 运行其他程序

    10.4 运行其他程序 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码.为了更好地控制运行的进程, ...

  8. python 命令行:help(),'more'不是内部或外部命令,也不是可运行的程序或批处理文件

    Python下使用help(dict),显示'more'不是内部或外部命令,也不是可运行的程序或批处理文件,该如何处理? 环境变量设置的问题,进入 Path 的环境变量设置界面,将;%SystemRo ...

  9. Python版:Selenium2.0之WebDriver学习总结_实例1

    Python版:Selenium2.0之WebDriver学习总结_实例1  快来加入群[python爬虫交流群](群号570070796),发现精彩内容. 实属转载:本人看的原文地址 :http:/ ...

随机推荐

  1. chr() 、ord()

    chr() 用于将一个数字转换为对应的ASCII字符,注意数字范围是0-255:ord() 用法相反,用于将一个ASCII字符转换为对应的数字 In [17]: print chr(33) ! In ...

  2. 将Eclipse项目导入到Android studio 中 很多点9图出现问题解决方法

    在build.gradle里添加以下两句: aaptOptions.cruncherEnabled = false aaptOptions.useNewCruncher = false

  3. 基于麒麟座开发板2.0的MQTT实现例程

    链接--->https://sanwen8.cn/p/649shZ1.html OneNET现已全面适配标准MQTT协议,相信这一功能的增加会**便于开发者进行设备的接入. OneNET提供了M ...

  4. 华为P10闪存门

    随着余承东的倡议书以及五一假期3天的时间冲刷,华为的闪存门事件,似乎被冲淡了.但相信还有很多人对华为“闪存门”的起始及发展过程不是特别了解.而华为作为2017年Q1季度手机出货量的冠军,居然在4月份出 ...

  5. JSON.parse()和JSON.stringfy()

    JSON.parse()从字符串中解析出JSON对象: var data = '{"a":1,"b":2}'; JSON.parse(data); JSON.s ...

  6. K-mean和k-mean++

    (1)k-mean聚类 k-mean聚类比较容易理解就是一个计算距离,找中心点,计算距离,找中心点反复迭代的过程, 给定样本集D={x1,x2,...,xm},k均值算法针对聚类所得簇划分C={C1, ...

  7. PropertyPlaceholderConfigurer读取配置文件

    1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是 BeanFactoryPostProcessor接口的一个实现.PropertyPlaceho ...

  8. JavaWeb温习之防止表单重复提交

    表单重复提交主要有以下三种情况: 1. 在网络延迟的情况下让用户有时间点击多次submit按钮导致表单重复提交 2. 表单提交后用户点击[刷新]按钮导致表单重复提交 3. 用户提交表单后,点击浏览器的 ...

  9. Web和Native使用外部字体ttf方法

    论坛教程:http://bbs.egret.com/forum.php?mod=viewthread&tid=24879&extra=&highlight=%E5%AD%97% ...

  10. 【BZOJ1801】[Ahoi2009]chess 中国象棋 DP

    [BZOJ1801][Ahoi2009]chess 中国象棋 Description 在N行M列的棋盘上,放若干个炮可以是0个,使得没有任何一个炮可以攻击另一个炮. 请问有多少种放置方法,中国像棋中炮 ...