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

Operate on two columns of data as new columns in sql

As shown below: select a1,a2,a1+a2 a,a1*a2 b,a1*1...

Echarts tutorial on how to implement tree charts

Treemaps are mainly used to visualize tree-like d...

Example of how to install nginx to a specified directory

Due to company requirements, two nginx servers in...

Solve the problem that Docker cannot ping the host machine under Mac

Solution Abandon the Linux virtual machine that c...

Two ways to reset the root password of MySQL database using lnmp

The first method: Use Junge's one-click scrip...

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

How to use Vue3 to achieve a magnifying glass effect example

Table of contents Preface 1. The significance of ...

Perfect solution to the problem of webpack packaging css background image path

Inside the style tag of the vue component, there ...

Why MySQL can ignore time zone issues when using timestamp?

I have always wondered why the MySQL database tim...

Implementation of CSS circular hollowing (coupon background image)

This article mainly introduces CSS circular hollo...

How to fix some content in a fixed position when scrolling HTML page

This article mainly introduces how some content i...

Native Js implementation of calendar widget

This article example shares the specific code of ...

react-diagram serialization Json interpretation case analysis

The goal of this document is to explain the Json ...