In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Recently, you need to test the zoom video conference and simulate 100 people to join the meeting at the same time. It has been learned that zoom provides a way to join the meeting directly through the url link (only through the chrome browser or FireFox browser, because the protocol is webrtc).
Following this idea, we can automate through Selenium and start multiple browser processes at the same time, each representing a video conference user to achieve the effect of simulating multi-party meetings. However, there are two difficulties:
Multiple chrome browser processes are required to survive at the same time, and it takes about 220m to start a chrome browser process on a computer. Audio and video sources for video conferencing.
Chrome browser has good support for audio and video sources of video conferencing. In the parameters for initializing Chrome browser in Selenium script, you only need to add the following configuration:
Chrome_options.add_argument ("- use-fake-ui-for-media-stream") chrome_options.add_argument ("--use-fake-device-for-media-stream")
After joining the video conference, you can use virtual video and audio. However, there is a question to consider. There seems to be a gap between the video quality of this virtual video and the real video conference, and whether it will affect the test results. We will not discuss this topic here for the time being.
Now the only headache is how to implement 100 chrome browser processes, you may think, this is not a resource problem? Don't you just add a server?! But if you have server resources, how to schedule tasks? Fortunately, there is Selenium Grid, which is the three major components of Selenium, specifically used to perform distributed tests.
So a test scheme is designed based on Selenium Grid:
Register a server as a Hub, that is, master registers the remaining machines as a node with the hub machine. Selenium automation scripts are executed locally using multiple processes (which I implemented in python).
According to the above design idea, it is theoretically possible to simulate 100 people to join the meeting at the same time. Then we officially begin the exploration of using docker to build a Selenium Grid distributed environment.
Selenium jar package starts the node directly
In fact, at the beginning, I started the node directly using the jar package, and several nodes can accept it, but it will be particularly troublesome when there are more nodes. For example, if you want to restart the next node, you need to manually kill all of them, and then start them one by one.
As long as the work is repeated manually, it can be scripted. So I wrote two shell scripts, one to start the corresponding number of nodes based on passing parameters, and the other to kill all the node processes. The main script is shown in the following figure:
Although it can be easily implemented with a script, it is still not convenient. After starting the node first, many java processes are added, and there is no way to view the logs of a single node, because the logs of all nodes are printed on the console at the same time. So consider using docker to manage Selenium grid nodes.
Start directly with the docker command
There is a ready-made image on github: https://github.com/SeleniumHQ/docker-selenium. Then all the available image names are listed in the description document, because I mainly use the chrome browser. All three images: selenium/hub, selenium/node-chrome and selenium/node-chrome-debug are installed, in which the selenium/node-chrome-debug image starts a VNC Server. During the execution of the script, you can connect to VNC Server locally and check the script execution of the server through the interface. Use the command:
$docker pull selenium/hub$ docker pull selenium/node-chrome$ docker pull selenium/node-chrome-debug
The command to start hub is as follows:
$docker run-d-p 444444 4444-e name hub selenium/hub
The command to start the local node (hub and node on one machine) is as follows:
$docker run-d-p 5555 NODE_MAX_SESSION=5 5555-e NODE_MAX_INSTANCES=5-e NODE_MAX_SESSION=5-- shm-size=2g-- link hub:hub-- name node1 selenium/node-chrome
The command to start the remote node (hub and node are not on the same machine) is as follows:
$docker run-d-p port:5555-e HUB_HOST=remote_ip-e HUB_PORT=remote_port-e REMOTE_HOST= http://ip:port-e NODE_MAX_INSTANCES=5-e NODE_MAX_SESSION=5-- shm-size=2g-- name node1 selenium/node-chrome
It should be noted here that the startup commands provided by many tutorials on the Internet are hub and node on a single machine. If you need hub and node on different machines, according to the online tutorials, although the startup will not report an error, the network between the node and hub is impassable.
However, although you can view the logs of a single node by using the docker command directly, you face the same problem as using the jar package: starting multiple nodes is very inconvenient and requires manual execution of multiple commands. Is there a better plan? Of course, you can use docker-compose to integrate docker containers.
Docker-compose start
Docker compose is a command-line tool for docker to define and run applications composed of multiple containers. This means that we can put multiple docker commands in a file and execute them with one click of docker-compose.
Similarly, it needs to be divided into two situations:
Hub and node are on the same machine
You can use the following configuration file docker-compose.yml
Version: "3" services: selenium-hub: image: selenium/hub container_name: selenium-hub ports:-"4444 GRID_TIMEOUT=900 4444" environment:-GRID_MAX_SESSION=50-GRID_TIMEOUT=900-START_XVFB=false chrome: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm depends_on:-selenium-hub environment:-HUB_HOST=selenium-hub-HUB_PORT=4444-NODE_MAX_INSTANCES=5-NODE_MAX_SESSION=5
Then execute the command on the console:
$docker-compose up-d / /-d means to run in the background
What if you want to start multiple nodes at the same time? Very simple:
$docker-compose up-d-scale chrome=num / / num is the number of nodes to start
If you want to shut down the node, you can execute the following command:
$docker-compose down
Hub and node are not on the same machine.
You can use the following configuration file docker-compose.yml
Version: "3" services: # selenium-chrome-1 selenium-chrome-node-1: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm ports:-"5556 selenium-chrome-1 selenium-chrome-node-1 5555" restart: always stdin_open: true environment: HUB_HOST: hub_ip HUB_PORT: 4444 NODE_MAX_INSTANCES: 5 NODE_MAX_SESSION: 5 REMOTE_HOST: http:// Node ip:5556 GRID_TIMEOUT: 60000 shm_ Size: "2gb" # selenium-chrome-2 selenium-chrome-node-2: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm ports:-"555515 5555" restart: always stdin_open: true container_name: node1 environment: HUB_HOST: hub_ip HUB_PORT: 4444 NODE_MAX_INSTANCES: 5 NODE_MAX_SESSION: 5 REMOTE_HOST: http:// node ip:5555 GRID_TIMEOUT: 60000 shm_size: "2gb" # selenium-chrome-3 selenium-chrome-node-3: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm ports:-"5557 NODE_MAX_INSTANCES 5555" restart: always stdin_open: true environment: HUB_HOST: hub_ip HUB_PORT: 4444 NODE_MAX_INSTANCES: 5 NODE_MAX_SESSION: 5 REMOTE_HOST: http:// Node ip:5557 GRID_TIMEOUT: 60000 shm _ size: "2gb" # selenium-chrome-4 selenium-chrome-node-4: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm ports:-"5558 image 5555" restart: always stdin_open: true environment: HUB_HOST: hub_ip HUB_PORT: 4444 NODE_MAX_INSTANCES: 5 NODE_MAX_SESSION: 5 REMOTE_HOST: http:// Node ip:5558 GRID_TIMEOUT: 60000 shm_size : "2gb" # selenium-chrome-5 selenium-chrome-node-5: image: selenium/node-chrome volumes:-/ dev/shm:/dev/shm ports:-"5559 dev/shm:/dev/shm ports 5555" restart: always stdin_open: true environment: HUB_HOST: hub_ip HUB_PORT: 4444 NODE_MAX_INSTANCES: 5 NODE_MAX_SESSION: 5 REMOTE_HOST: http:// Node ip:5559 GRID_TIMEOUT: 60000 shm_size: "2gb"
The command to start the node is (provided that hub needs to be started in advance):
$docker-compose up-d
The command to turn off the node is:
$docker-compose down
Remaining problems
According to the way I built the Selenium Grid environment above, the local node can execute normally, but the remote node often times out, but all the node networks you can see from the http://hub_ip:4444/grid/console interface are connected.
Having checked some information before, it seems that you need to use Docker Swarm, which is a docker cluster management tool that abstracts several Docker hosts into a whole and manages various Docker resources on these Docker hosts through an entry. However, I have not studied it yet. If I have a conclusion with Docker Swarm, I will write an article and synchronize it to you.
Summary
Using docker to build a selenium grid distributed environment is very convenient, basically one-line command can start or shut down the node. I hope my article can provide you with some ideas to help you solve some problems in your usual work.
This is the end of this article on using docker to build selenium grid distributed environment practice road, more related docker to build selenium grid distributed content, please search the previous articles or continue to browse the following related articles hope that you will support more in the future!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.