Building a selenium distributed environment based on docker

Building a selenium distributed environment based on docker

1. Download the image

docker pull selenium/hub
docker pull selenium/node-firefox
docker pull selenium/node-chrome

Note: selenium/node-firefox and selenium/node-chrome are both headless.

To see the real-time running interface, you need to use one of the following two images.

docker pull selenium/standalone-chrome-debug
docker pull selenium/standalone-firefox-debug

2. Start the Docker of the Hub node

docker run -p 4444:4444 -d --name hub selenium/hub

Parameter Description:

  • run: Run an image and create a container.
  • -p 4444:4444 : Map the port in the container.
  • -d: Run in the background
  • --name: container name, here I will just call this container hub

3. Start the Docker of Node

docker run -P -d --link hub:hub --name firefox selenium/node-firefox
docker run -P -d --link hub:hub --name chrome selenium/node-chrome

Or a Node with a Debug interface

docker run -d -p 5900:5900 --link hub:hub selenium/node-chrome-debug

Parameter Description:

--link is a link to the container with the alias hub.

4. Install and configure VNC

VNC (Virtual Network Console) is the abbreviation of virtual network console. It is an excellent remote control tool software, a free open source software based on UNIX and Linux operating systems, with powerful remote control capabilities, efficient and practical.

Download address: https://www.realvnc.com/en/connect/download/viewer/

5. Test code

To use the Selenium Grid service, you need to use the webdriver.Remote method to connect to the service and pass in the desired_capbilities desired capabilities. The sample script is as follows.

from time import sleep
from selenium import webdriver


driver = webdriver.Remote(
command_executor = 'http://192.168.99.100:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'}
)

driver.get('https://www.baidu.com')
print("start run")
sleep(1)
print(driver.title)
driver.quit()
print("end...")

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Practical way to build selenium grid distributed environment with docker
  • Docker+selenium method to realize automatic health reporting
  • How to use selenium+testng to realize web automation in docker
  • Sample code for testing technology application based on Docker+Selenium Grid

<<:  A brief discussion on Vue3 father-son value transfer

>>:  4 solutions to mysql import csv errors

Recommend

The difference between Vue interpolation expression and v-text directive

Table of contents 1. Use plugin expressions 2. Us...

Detailed explanation of redo log and undo log in MySQL

The most important logs in the MySQL log system a...

Detailed explanation of MySQL precompilation function

This article shares the MySQL precompilation func...

How to use watch listeners in Vue2 and Vue3

watch : listen for data changes (change events of...

Complete steps to build NFS file sharing storage service in CentOS 7

Preface NFS (Network File System) means network f...

Implementation of mysql data type conversion

1. Problem There is a table as shown below, we ne...

Record of the actual process of packaging and deployment of Vue project

Table of contents Preface 1. Preparation - Server...

Example of converting timestamp to Date in MySQL

Preface I encountered a situation at work: In the...

Detailed process of using vmware to test PXE batch installation server

Table of contents 1. Preparation 1. Prepare the e...

Study notes to write the first program of Vue

Table of contents 1. Write an HTML, the first Vue...

HTML page adaptive width table

In the pages of WEB applications, tables are ofte...

Vue3.0 adaptive operation of computers with different resolutions

First we need to install some dependencies npm i ...