简体   繁体   中英

Running selenium test in Docker

I wrote a selenium script that works works fine when I launch it using cmd.

I would like now to execute the script in a docker so that it can easily be launched from any machine in one click.

I wrote a Dockerfile using the base image FROM selenium/standalone-chrome-debug

I changed my script like this :

driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME)
driver.maximize_window()
driver.get("www.google.com")

But when I launch it, I have the following error :

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4444): Max retries exceeded with url: /wd/hub/session (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd11b9e3b90>: Failed to establish a new connection: [Errno 111] Connection refused',))

I'm new to docker and selenium so I may have forgot something.

You are passing local IP and local port number

http://127.0.0.1:4444 - your IP is local and local port

You need to identify your selenium hub docker ip and port on which hub running on same VM and update your below line:

driver = webdriver.Remote("http://127.0.0.1:4444/wd/hub", DesiredCapabilities.CHROME)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM