本文介绍了针对从SeleniumHQ Docker映像创建的Selenium网格的Selenium Python测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何针对从SeleniumHQ Docker映像创建的Selenium Grid容器正确运行Python Selenium测试?

How to run Python Selenium tests properly against Selenium Grid container created from SeleniumHQ Docker images?

我也在这里SeleniumHQ上问

I also asked on SeleniumHQ herehttps://github.com/SeleniumHQ/docker-selenium/issues/521


我已经尝试过和,但没有找到

I've tried this web search and similar search on our site and found none useful.

可以独立运行

我已经成功运行了

-启动网格

docker run -d -p 4445:4444 -v /dev/shm:/dev/shm selenium/standalone-chrome:3.4.0-einsteinium
docker run -d -p 4446:4444 --shm-size 2g selenium/standalone-firefox:3.4.0-einsteinium

-运行测试

#!/usr/bin/env python2.7

SELENIUM_HUB_CH = 'http://localhost:4445/wd/hub' #hub created at file 's01b_start_selenium_standalone_grid.sh'
SELENIUM_HUB_FF = 'http://localhost:4446/wd/hub' #hub created at file 's01b_start_selenium_standalone_grid.sh'

#region webdriver loading
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driverCH = webdriver.Remote(
  command_executor=SELENIUM_HUB_CH,
  desired_capabilities=DesiredCapabilities.CHROME,
)
driverFF = webdriver.Remote(
  command_executor=SELENIUM_HUB_FF,
  desired_capabilities=DesiredCapabilities.FIREFOX,
)
#endregion webdriver loading

for driver in [driverCH, driverFF]:
  driver.get('http://www.google.com')
  print(driver.title)

但是使用集线器+节点网格失败

尽管我未能运行

Though I failed to run that simple test against the hub+node selenium grid

-启动网格

docker run -d -p 4444:4444 --name selenium-hub selenium/hub:3.4.0-einsteinium
docker run -d --link selenium-hub:hub selenium/node-chrome:3.4.0-einsteinium
docker run -d --link selenium-hub:hub selenium/node-firefox:3.4.0-einsteinium

-运行测试

#!/usr/bin/env python2.7

SELENIUM_HUB = 'http://localhost:4444/wd/hub'

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(
  command_executor=SELENIUM_HUB,
  desired_capabilities=DesiredCapabilities.CHROME,
)

driver.get('http://www.google.com')
print(driver.title)

问题

我有兴趣针对Selenium网格容器进行测试,即从。

I am interested in testing against Selenium grid containers i.e. the hub+node container created from these Docker images.

推荐答案

感谢

我可以确认安装python硒3.3.1后我的测试现在可以正常工作

pip uninstall selenium ; pip install selenium==3.3.1

这篇关于针对从SeleniumHQ Docker映像创建的Selenium网格的Selenium Python测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 16:52