In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Background
Agile (Agile) pattern is widely used, and testing is particularly important. As new versions need to be released frequently, we need to execute test cases more frequently to ensure that no new bug is introduced into the version.
The time and resources required by a complete testing process can not be ignored, including the analysis of test results. How to provide complete and comprehensive testing to ensure quality in a shorter time is not only the problem we are eager to solve, but also the key to ensure that agile development can be carried out smoothly.
Jenkins implements the unattended testing process. Once the development is completed, once the test environment is deployed successfully, the downstream testing tasks will be executed immediately.
The application of Jenkins saves human resources to a certain extent, while Docker technology can achieve the rapid expansion of Container, thus saving a lot of equipment resources and time, and quickly complete the test. This is a very important part of Jenkins Pipeline (code pipeline management), as shown in figure 1:
Figure 1. Jenkins Pipeline
This paper mainly introduces how to make use of Docker Swarm cluster function and Selenium Grid script distribution function to build a Selenium automatic script execution environment that can be dynamically expanded. Compared with using a real machine as the Selenium automated script execution environment, using this environment can greatly reduce the maintenance of the execution environment, such as various browser types and version management. It can also greatly reduce the material investment in the script execution environment and save all kinds of resources.
Set up Docker Swarm cluster
Introduction to Swarm
Swarm is a cluster management tool provided by Docker, which is used to manage Docker clusters. It abstracts several Docker hosts as a whole and manages various Docker resources on these Docker hosts through an entry.
Swarm is just a Scheduler and Router. Swarm does not run the container itself, it just accepts requests from Docker clients and schedules suitable nodes to run the container, which means that even if Swarm dies for some reason, the nodes in the cluster will run as usual, and when Swarm resumes operation, it will collect and rebuild cluster information.
Swarm is similar to Kubernetes, but lighter and has less functionality than Kubernetes.
Environmental preparation
To build a Docker Swarm cluster environment, I prepared two machines in the example. One is as a manager node, but also as a worker node, and the other is only as a worker node.
Let's assume that the IP information of our two machines is as follows:
M1:10.13.181.1M2:10.13.181.2
Starting with V1.12.0, Docker Engine natively integrates with Docker Swarm, so as long as you install Docker on each machine, you can use Docker Swarm directly. Here, the installation of Docker will not be described in detail, please follow the official Docker Swarm documentation to install. After the installation is complete, start the Docker service on each machine.
Tip:
Note: it is best to turn off the firewall on the machine, otherwise there may be problems with Swarm cluster network connectivity.
Command to turn off the firewall: systemctl stop firewalld.service
Disable firewall boot command: systemctl disable firewalld.service
Steps
1. Create a management node.
We use machine M1 as a manager node and execute commands on this machine to initialize the cluster environment. The command is as follows:
Sudo docker swarm init-advertise-addr 10.13.181.1
After executing this command, a Token is returned to join the cluster so that other worker can join the cluster.
Listing 1. Join a cluster token example:
The copy code is as follows: docker swarm join-- token SWMTKN-1-5p3kzxhsvlqonst5wr02hdo185kcpdajcu9omy4z5dpmlsyrzj-
3phtv1qkfdly2kchzxh0h2xft 10.13.181.1:2377
If you want to get the command to join the cluster again, you can get it by executing the following command:
Sudo docker swarm join-token worker
Machine M1 is also added to the cluster as a worker node.
Run the command in listing 1 on the manager node machine to add machine M1 to the swarm cluster as worker.
3. Add another machine M2 to the cluster as a worker node.
You can add M2 to the cluster by executing the commands in listing 1 above on machine M2.
4. Run the following command to create a cluster network:
Sudo docker network create-d overlay seleniumnet
Here, seleniumnet is the name of the cluster network we created.
5. Create a Selenium Grid service on the newly created cluster network.
a. Create a Selenium Grid Hub service. Based on the cluster network seleniumnet, you can increase or decrease the timeout time by mapping port 4444 to port 4444 of the cluster and setting the timeout time to 120 seconds, as shown in listing 2.
Listing 2. To create a Selenium Grid Hub service:
The copy code is as follows: sudo docker service create-- name selenium-hub-- network seleniumnet-p 4444move4444-e
GRID_TIMEOUT=120 selenium/hub
b. Create a Selenium Grid Firefox node service and connect to the newly created Hub service. As shown in listing 3.
Listing 3. Create a Selenium Grid Firefox node service:
Sudo docker service create\-- name node-firefox\-- replicas 5\-- p 7900sudo docker service create 5900\-- network seleniumnet\-e HUB_PORT_4444_TCP_ADDR=selenium-hub\-e HUB_PORT_4444_TCP_PORT=4444\ selenium/node-firefox-debug bash-c 'SE_OPTS= "- host $HOSTNAME" / opt/bin/entry_point.sh'
Parameter description:
-p: 7900 Docker 5900 exposes the internal VNC5900 of the Docker to port 7900 of the host, allowing users to monitor the internal execution of the Docker from the outside through the VNC.
c. Create a Selenium Grid Chrome Node service and connect to the newly created Hub service. As shown in listing 4.
Listing 4. Create a node service:
Sudo docker service create\-name node-chrome\-replicas 3\-p 7901 HUB_PORT_4444_TCP_ADDR=selenium-hub 5900\-network seleniumnet\-e HUB_PORT_4444_TCP_ADDR=selenium-hub\-e HUB_PORT_4444_TCP_PORT=4444\ selenium/node-chrome-debug bash-c 'SE_OPTS= "- host $HOSTNAME" / opt/bin/entry_point.sh'
Parameter description:
-p: 7901 VNC5900 5900 exposes the Docker internal VNC5900 to port 7901 of the host, allowing users to monitor the internal execution of the Docker from the outside through the VNC.
6. Check whether the environment is built successfully. Execute the following command on machine M1 to see if each service starts successfully:
Sudo docker service ls
You can see that the Selenium Hub and Firefox nodes and Chrome nodes have been started successfully. The node copy of Firefox is 5, and the node copy of Chrome is 3, as shown in figure 2.
Figure 2. Docker service list
Let's open Selenium Hub URL by adding port 4444 to IP on any machine to see if the started Firefox and Chrome nodes have been successfully mounted to the Hub node, as shown in figure 3.
Hub url: 10.13.181.1:4444
Figure 3. Interface diagram of Selenium Hub
As you can see from figure 3, five Firefox nodes and three Chrome nodes have been successfully mounted to the Hub node. It shows that 5 Firefox nodes and 3 Chrome nodes have been provided in the Docker Swarm environment to execute Selenium automated test scripts.
Capacity expansion method
Users can dynamically expand the number of nodes based on the number of scripts executed at any time to improve the execution efficiency of automated scripts. For example, we need 10 Container that can run Firefox browsers. The corresponding commands are as follows:
Sudo docker service scale node-firefox=10
Run Jenkins Job on Docker Swarm
When you run Jenkins Job in Docker Swarm, you don't need to do extra configuration in Jenkins, but you need to call Selenium Hub in the corresponding automation script to call WebDriver remotely. This makes it possible to run Selenium scripts in Docker Container.
Taking the scenario in this article as an example, you only need to call the remote Selenium Hub in the automation script, as follows: http://9.111.139.104:4444/wd/hub
Run automation scripts in Selenium Grid
Basic concept
Selenium Grid, for distributed automation testing, that is, a set of Selenium code can be run in different environments, which makes it easy to run applications in different Container provided by Docker.
Selenium Grid has two concepts:
Hub: master node, you can think of it as a general dispatch center. Node: branch node, which you can think of as the worker that actually performs the task.
In other words, there can be only one master Hub in the Selenium Grid, but multiple branch nodes can be established locally or remotely, the test script points to the master Hub, and the master Hub is assigned to the local / remote node to run test cases.
Mode of realization
To run automation scripts in Selenium Grid, we first need to create an object of remote driver, which can be realized by the source code in figure 4. The corresponding input parameter selhub in the screenshot is the URL: http://9.111.139.104:4444/wd/hub of Selenium hub.
Figure 4. Code screenshots of automated scripts
By calling the driver above, you can run the automation script in Docker Container.
Concluding remarks
In continuous integration testing, deploying the test to Docker Swarm and automatically allocating the nodes to execute the test through Selenium Grid can improve the testing efficiency, expand the scope of testing, better guarantee the product quality delivered in the rapid iteration, and save test resources.
Original link: https://www.ibm.com/developerw. .html
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.