Docker+selenium deployment of the Web Automation test environment

Source: Internet
Author: User
Tags docker ps docker hub docker run docker toolbox selenium grid

Docker+selenium deployment of the Web Automation test environment

1. Open the Docker terminal using SECURECRT or Docker Quickstart terminal.

2. Download the image required for Selemiunui test

Command Docker Pull: Download the image from the Docker hub.

First, search for the image that needs pull

Command:Docker search Selenium

For Docker selenium, the image that needs pull here is:



Currently only supported for testing in Chrome and Firefox

The downloaded command is the Docker pull+ image name +tag
Docker pull baozhida/selenium-hub:3.3.1
Docker Pull baozhida/selenium-node-chrome-debug:58
Docker Pull Baozhida/selenium-node-firefox-debug:52

The official image may cause the open page to appear garbled in Chinese, so the above image can be used.

Description: The default tag is Latest;dockerhub server overseas, so the network speed when bad, and sometimes timeout error, more than a few times will be able to succeed.

Because the local access to the Docker hub is slow, the time taken to pull the mirror is longer.

You can pull from dockerhub on this issue, and then use the accelerator to modify Docker's registry-mirrors. The Daocloud accelerator is used here.
here's how to get an accelerator using Daocloud.

Register for login at

To log in successfully, click Accelerator, as shown in the figure:

Wait a minute. The following interface appears, select Windows System, copy the acquired registry-mirrors configuration.

Please make sure your Docker Toolbox is up and executing the following commands (please replace the accelerator address with the dedicated address obtained on the Accelerators page)

Docker-machine SSH Default
sudo sed-i "s| Extra_args= ' | Extra_args= '--registry-mirror= acceleration address |g '/var/lib/boot2docker/profile

For more accelerated configuration of the environment, please refer to the following Help documentation


3. View image

Enter the command Docker images to view the images that have been downloaded

4. Create and run the container

Create Selenium Hub Container
dockerrun-d-P 4444:4444--name selehub baozhida/selenium-hub:3.3.1

Create a Chrome node container

Docker run-d-P 5901:5900--name node58--linkselehub:hub


Create a Firefox node container

Docker run-d-P 5912:5900--name ff52--linkselehub:hub

--shm-size=512m baozhida/selenium-node-firefox-debug:52


*-d Parameters: Background mode operation;

--name parameter: alias;

-P Parameter: Maps the container's 5900 port to the 5901 port of Docker and accesses the 5901 port of Docker to access the node container;

--shm-size parameter: Docker default shared Memory/dev/shm only 64m, sometimes causing Chrome to crash, this parameter increases the shared memory size to 512m.*

5. Enter the command Docker ps-a view the running container in the UP state

6. Enter the address in the browser
Check the Selenium grid console to see that the container you just created is registered properly

7. VNC Remote Browser environment

Debug end of the mirror with the VNC server side, the local installation of the VNC client, you can connect remotely.

Download Address:
Enter> carriage return-Enter Password:secret--> confirm-Enter chrome:58 container desktop

Enter> carriage return-Enter Password:secret--> confirm-Enter firefox:52 container desktop

8. Run the following script locally to test.

#coding =utf-8
from  Selenium import webdriver
    "browsername": "Firefox",
    "version": "52.0", #注意版本号一定要写对
    "platform": "Any",
    "javascriptenabled": True,
    "marionette": true,
Browser=webdriver. Remote ("Http://", desired_capabilities=firefox_capabilities) #注意端口号4444是我们上文中映射的宿主机端口号
browser.get ("")
Browser.get_screenshot_as_file (r "C:/baidu.png")
Browser.close ()

The effect of the above code is: Open the Baidu interface with firefox52.0, and save the screenshot in the C drive.

But following the above, the code reported the following error:


The corresponding modification should be made according to the method in (

Then use the official image to create the Selenium hub container:

Close the original Selenium hub container

Docker stop "CONTAINER ID" (The ID of the corresponding container)

Remove the original Selenium hub container

Docker rm "NAMES" (as described above, the name here uses Selehub)

Download Selenium/hub image

Docker pull Selenium/hub (version defaults to latest)

Create Selenium Hub Container
Docker run-d-P 4444:4444--nameselehub Selenium/hub

Run the script again

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.