Docker practice-building a distributed UI test environment

Source: Internet
Author: User
Tags unique id docker ps docker run selenium grid

 background : Projects require UI Automation testing in different versions of Chrome Firefox

  status : A single machine can only install one version of the browser; Multiple computers are too troublesome to work together;

  Solution : Simplify deployment of selenium grid distributed testing via Docker

1.Grid Introduction

  

  

 Web-side Automation testing presents a single-largest state, most of which are done using selenium, and are the official support tools of the major browsers, which are widely used.

Deploying a distributed Selenium grid cluster in a traditional way requires a lot of time and machine cost to prepare the test environment. For example, to test for different versions of Chrome, a specific version of the Chrome browser needs to be installed on a different physical or virtual machine.

  

 2.Docker deployment

2.1 Docker Environment Setup

This machine uses Windows7 64Bit to install the host based on the Dockertoolbox Linux

Setup completes initialization slow, requires FQ faster

  2.2 Installing images

Hub installation Chrome+firefox different versions installed

Baozhida/selenium-hub hub.docker.com/r/baozhida/selenium-hub/

Baozhida/selenium-node-firefox-debug hub.docker.com/r/baozhida/selenium-node-firefox-debug/

Baozhida/selenium-node-chrome-debug hub.docker.com/r/baozhida/selenium-node-chrome-debug/

Suyunrong/selenium-node-chrome-debug hub.docker.com/r/suyunrong/selenium-node-chrome-debug/tags/

Installation commands

  Docker Pull baozhida/Selenium-hub:3.3. 1

dock ER pull baozhida/selenium-node-chrome-debug:

< span class= "n" > < span class= "n" > docker pull baozhida /selenium-node- chrome-debug:58

< Span class= "o" > < Span class= "o" > docker pull baozhida/ selenium-node-firefox -debug:47

< Span class= "o" > < Span class= "o" > docker pull baozhida/ selenium-node-firefox -debug:52

< span class= "n" > < span class= "n" > < span class= "n" > /span>  Docker pull Suyunrong/selenium-node-chrome-debug: 66.0.3359.170

Note 1:debug version can be logged in via VNC tool to see Remote Desktop

Note 2: You are free to download other versions of the image

View installation Success Docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Suyunrong/selenium-node-chrome-debug 66.0.3359.170 7bccb076f06a 3 months ago 889MB
Baozhida/selenium-node-chrome-debug 36863BDC2BBF months ago 923MB
Baozhida/selenium-node-firefox-debug 2792d74ddc5c months ago 729MB
Baozhida/selenium-node-firefox-debug 6952015b6de6 months ago 736MB
Baozhida/selenium-hub 3.3.1 8bbca693c0c0 months ago 394MB

REPOSITORY represents the Mirror warehouse name

Image ID represents the image ID

TAG represents version number latest--The latest version generally does not indicate the latest version

  

  3. Create a running container

Create Selenium Hub Container
Docker run-d-P 4444:4444--name Selehub baozhida/selenium-hub:3.3.1


Create a Chrome node container
Docker run-d-P 5901:5900--name gc48--link selehub:hub--shm-size=512m baozhida/selenium-node-chrome-debug:48
Docker run-d-P 5902:5900--name gc58--link selehub:hub--shm-size=512m baozhida/selenium-node-chrome-debug:58
Docker run-d-P 5903:5900--name gc66--link selehub:hub--shm-size=512m suyunrong/selenium-node-chrome-debug : 66.0.3359.170
 Docker run-d-P 5904:5900--name gc65--link selehub:hub--shm-size=512m suyunrong/selenium-node-chrome-debug : 65.0.3325.162

Create a Firefox node container
Docker run-d-P 5911:5900--name ff47--link selehub:hub--shm-size=512m baozhida/selenium-node-firefox-debug:47
Docker run-d-P 5912:5900--name ff52--link selehub:hub--shm-size=512m baozhida/selenium-node-firefox-debug:52

-D stands for background mode operation

-P represents port mapping 5,901:5,900 container 5900 port mapped to Docker 5901 port access Docker 5901 Port accessible container

--name represents the container name can be customized do not set automatic system assignment

--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.*

--link binding to a container

  Note: Port definition chrome nod [5901---] firefox nod[5911--]

  

 View in the Run container

Docker PS

  

NAMES container run up after name

PORTS 5,912:5,900 Container Port 5900 Docker Port 5912

CONTAINER ID container runs after a unique ID is generated a container can run n times to generate n IDs

Enter the address in the browser http://192.168.99.100:4444/grid/console
Looking at the Selenium grid console, you can see that the container you just created is registered properly.

  

4.VNC Remote Browser environment

66 For example

Enter 192.168.99.100:5903 Enter password secret

5.Python Initialization driver Concurrent execution

Chrome_driver = Os.path.abspath (r "D:\Python27")
os.environ["Webdriver.chrome.driver"] = Chrome_driver
Chrome_capabilities = {
"Browsername": "Chrome",
"58.0.3029.81",
"Platform": "Any",
"Javascriptenabled": True,
Chrome_driver
}
  
Firfox_capabilities = {
"Browsername": "Firefox",
"47.0",
"Platform": "Any",
"Javascriptenabled": True
}
Dr = Webdriver. Remote (command_executor = "Http://192.168.99.100:4444/wd/hub", desired_capabilities = chrome_capabilities)


--CHROME_DRIVER Specifies the drive path Chromedriver.exe
--firefox driver Low version requires no driver
--firefox 48 and above needs to be driven
 
Firfox_driver = Os.path.abspath (r "D:\Python27")
os.environ["Webdriver.gecko.driver"] = Firfox_driver
Firfox_capabilities = {
"Browsername": "Firefox",
"Version": "61.0.1",
"Platform": "Any",
"Javascriptenabled": True,
"Webdriver.gecko.driver": Firfox_driver
}
  Concurrent simultaneous calls using thread implementations (subsequent reports can be implemented with the Unit test framework)
  

  

 

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: info-contact@alibabacloud.com 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.