Web automatic testing method and device, equipment and storage medium

By packaging the Cypress test engine and browser into a Docker image and combining it with Jenkins tasks, multiple test tasks can be run in isolation on a test machine, which solves the problem of resource waste and improves the efficiency of automated web testing.

CN118567997APending Publication Date: 2024-08-30WUHAN DAMENG DATABASE
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410794947.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-19
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

In Web automated testing, when there are many test tasks, multiple test machines need to be set up, but each test machine is not fully utilized, resulting in a waste of resources.

Method used

By packaging the Cypress test engine, browser and browser dependencies into Docker images, using Jenkins tasks to obtain test cases in the version control system, and instantiating container instances to execute test cases, multiple test tasks are isolated on one test machine. operation to reduce resource waste.

Benefits of technology

It realizes running multiple isolated test tasks on a few computers, improves testing efficiency, avoids waste of resources, and maintains a small number of container instances at each time aspect for continuous and large-scale testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567997A
    Figure CN118567997A
Patent Text Reader

Abstract

The invention provides a Web automatic test method, device and equipment and a storage medium, and belongs to the technical field of automatic test.The method comprises the steps that a Cypress test engine, a browser and browser dependency are packaged based on a Docker engine, and a Docker mirror image is generated; storing the plurality of test cases in a version control system; creating and executing a jenkins task in response to the test instruction; wherein the jenkins task comprises the steps of obtaining a target test case from the version control system, controlling the Docker engine to instantiate the Docker mirror image to obtain a container instance, extracting the target test case in the plurality of test cases, and executing the target test case based on the container instance. According to the invention, through combination of Cypress and Docker, areas for execution of different test tasks can be isolated on one test machine, full utilization of test machine resources is realized, and the problem of waste of test machine resources in automatic test tasks is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automation technology, and in particular to a Web automation testing method, device, equipment and storage medium. Background Art

[0002] Cypress is a web automation testing engine written in JavaScript. Under this framework, JavaScript is used to write code with a specific structure, which is called and interpreted by the Cypress engine to drive mainstream browsers to simulate user interactions. Therefore, Cypress has become a widely used web automation testing tool.

[0003] Cypress uses text-based test cases as input, interprets them into a browser-readable form, and sends them to the browser. This involves the interaction of three entities: the test cases in the test task, the Cypress engine, and the browser. When the test task is executed, these three entities must be located on the same computer. In order to prevent test tasks from interfering with each other, test engineers generally do not run multiple test tasks on the same test machine. Because test tasks share the operating system, network stack, and file system, there is a great possibility of mutual interference. Therefore, test engineers will choose different test machines to run different tasks, resulting in each test machine not being fully utilized.

[0004] There is an urgent need to provide a Web automated testing method, device, equipment and storage medium to solve the technical problem that when there are many testing tasks, multiple testing machines need to be set up, but each testing machine is not fully utilized, resulting in the resources in the testing machine being forced to be idle and wasted. Summary of the invention

[0005] In view of this, it is necessary to provide a Web automation testing method, device, equipment and storage medium to solve the technical problem in the prior art that when there are many tasks, multiple test machines need to be set up, but each test machine is not fully utilized, resulting in the resources in the test machine being forced to be idle and wasted.

[0006] On the one hand, in order to solve the above technical problems, the present invention provides a Web automation testing method, comprising: Based on the Docker engine, the Cypress test engine, browser, and browser dependencies are packaged to generate a Docker image. Store multiple test cases in a version control system; Create and execute Jenkins tasks in response to test instructions; The Jenkins task includes: obtaining a target test case from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting a target test case from the multiple test cases, and executing the target test case based on the container instance.

[0007] In a possible implementation, the Jenkins task further includes: After obtaining and returning the execution result of the target test case, the container instance is automatically destroyed.

[0008] In a possible implementation, the Jenkins task further includes: After obtaining and returning the execution result of the target test case, the target test case is automatically destroyed.

[0009] In a possible implementation, the Docker engine is installed on a test machine, and executing the target test case based on the container instance includes: Obtaining a target test case from the version control system, and downloading the target test case to a test machine; Controlling the container instance to perform path mapping to obtain an access path of the target test case in the test machine; The target test case is executed based on the container instance and the access path.

[0010] In a possible implementation, controlling the Docker engine to instantiate the Docker image to obtain a container instance includes: Get the process passing parameters; The Docker image is instantiated based on the process transfer parameter and the Docker engine to obtain a container instance.

[0011] In a possible implementation, the process transfer parameter includes a browser type and a browser process start mode.

[0012] In a possible implementation, the browser types include Chrome browser, Firefox browser and Edge browser, and the browser process startup mode is headless.

[0013] On the other hand, the present invention also provides a Web automated testing device, comprising: The Docker image generation unit is used to package the Cypress test engine, browser, and browser dependencies based on the Docker engine to generate a Docker image; A test case storage unit, used for storing multiple test cases in a version control system; Automated testing unit, used to create and execute Jenkins tasks in response to test instructions; The Jenkins task includes: obtaining a target test case from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting a target test case from the multiple test cases, and executing the target test case based on the container instance.

[0014] On the other hand, the present invention also provides a Web automated testing device, including a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps of the Web automated testing method described in any one of the possible implementations above.

[0015] On the other hand, the present invention further provides a computer-readable storage medium having a program or instruction stored thereon, which, when executed by a processor, implements the steps of the Web automated testing method described in any one of the possible implementations described above.

[0016] The beneficial effects of the present invention are as follows: the Web automated testing method provided by the present invention can generate a Docker image by packaging the Cypress test engine, the browser, and the browser dependencies, so that a large number of container instances can be released by installing the Docker engine on only a few computers and generating a Docker image. These container instances are isolated from each other and operate independently. Through the combination of Cypress and Docker, different operating system-network stack-file system units can be isolated on a test machine, so that many test tasks can be run in isolation and safely on a test machine. Logically, one test machine is transformed into multiple test machines, solving the problem of waste of test machine resources by automated test tasks. On each time slice, only a few container instances need to be maintained to perform continuous and large-scale testing.

[0017] Furthermore, once the Docker image of the present invention is instantiated, all browsers and browser dependencies can be in place, thereby improving the test efficiency of Web automated testing.

[0018] Furthermore, the present invention uses a Docker container in which Cypress has been deployed, and after releasing the generated container instance, it can be used directly without redeploying Cypress, thereby further improving the test efficiency of Web automated testing. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 A schematic diagram of an embodiment of the Web automated testing method provided by the present invention; Figure 2 A schematic diagram of a flow chart of an embodiment of executing a target test case based on a container instance provided by the present invention; Figure 3 A schematic diagram of a specific embodiment of the Web automated testing method provided by the present invention; Figure 4 A schematic diagram of the structure of an embodiment of the Web automated testing device provided by the present invention; Figure 5 A schematic diagram of the structure of an embodiment of the Web automated testing device provided by the present invention. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0022] It should be understood that the schematic drawings are not drawn to scale. The flowchart used in the present invention shows the operations implemented according to some embodiments of the present invention. It should be understood that the operations of the flowchart can be implemented out of order, and the steps without logical context can be reversed in order or implemented simultaneously. In addition, those skilled in the art, under the guidance of the content of the present invention, can add one or more other operations to the flowchart, and can also remove one or more operations from the flowchart. Some of the block diagrams shown in the accompanying drawings are functional entities, which do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor systems and / or microcontroller systems.

[0023] Reference to an "embodiment" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiment may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0024] The present invention provides a Web automated testing method, device, equipment and storage medium, which are respectively described below.

[0025] Figure 1 A schematic diagram of an embodiment of the Web automation testing method provided by the present invention is shown in FIG. Figure 1 As shown, the Web automation testing methods include: S101. Package the Cypress test engine, browser, and browser dependencies based on the Docker engine to generate a Docker image. S102, storing multiple test cases in a version control system (Version Control System, VCS); S103, create and execute a Jenkins task in response to a test instruction; Among them, the Jenkins tasks include: obtaining target test cases from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting target test cases from multiple test cases, and executing the test cases based on the container instance.

[0026] It should be understood that Docker in step S101 is a containerization platform that allows developers to package an application and all its dependencies into an independent unit called a container. This container can run in any environment that supports Docker, providing a lightweight, portable and self-contained deployment solution.

[0027] The Docker image in step S101 can be understood as a medium similar to an installation package. Once released on a computer, it has a specific function, which is called a container instance. The difference between a Docker image and an installation package is that after it is instantiated, it is not a software, but a collection of software processes. This group of processes exists independently on the computer and does not interfere with other software processes on the computer. They have independent IP addresses and independent operating systems. They are physically contained, but not logically subordinate.

[0028] The version control system in step S102 is specifically SVN, which stands for Subversion. It allows users to trace back to different versions by recording historical changes of files and directories, and provides functions such as branching and merging to facilitate collaborative development among multiple people.

[0029] The Jenkins task in step S103 is a task generated by Jenkins, which is a task scheduling software of a master node / slave node architecture. The master node can issue instructions to each slave node through manual configuration, and schedule them in series or parallel to complete their respective responsibilities.

[0030] Among them, the test cases are manually written by test engineers or automatically generated by test case generation models.

[0031] It should also be understood that the execution order of step S101 and step S102 can be swapped.

[0032] Compared with the prior art, the Web automated testing method provided by the embodiment of the present invention can generate a Docker image by packaging the Cypress test engine, the browser, and the browser dependencies. This can achieve the goal of only installing the Docker engine on a few computers and generating a Docker image, and then releasing many container instances. These container instances are isolated from each other and operate independently. Through the combination of Cypress and Docker, different operating system-network stack-file system units can be isolated on a test machine, so that many test tasks can be run safely and isolated from each other on a test machine. Logically, one test machine is transformed into multiple test machines, solving the problem of waste of test machine resources by automated test tasks. On each time slice, only a few container instances need to be maintained to perform continuous and large-scale testing.

[0033] Furthermore, once the Docker image of the embodiment of the present invention is instantiated, all browsers and browser dependencies can be in place, thereby improving the test efficiency of Web automated testing.

[0034] Furthermore, the embodiment of the present invention uses a Docker container in which Cypress has been deployed, and after releasing the generated container instance, it can be used directly without redeploying Cypress, thereby further improving the test efficiency of Web automated testing.

[0035] In order to present the execution results of the test cases to the testers in a comprehensive and orderly manner, in some embodiments of the present invention, after step S103, the following steps are further included: Obtain the execution results of the target test case and generate a test report based on the execution results.

[0036] In some embodiments of the present invention, the Docker engine is installed on the test machine. Figure 2 As shown, the target test case is executed based on the container instance, including: S201, obtaining a target test case from a version control system, and downloading the target test case to a test machine; S202, controlling the container instance to perform path mapping, and obtaining the access path of the target test case in the test machine; S203: Execute the target test case based on the container instance and the access path.

[0037] That is, the target test case is executed on the test machine, so the test machine needs to have a Docker engine process.

[0038] The embodiment of the present invention can realize path conversion in two different local file systems, the test machine and the container instance, by setting path mapping.

[0039] The path mapping in step S202 refers to: making the container instance think that a file under a certain path on the computer is a file under a certain path of itself. In other words, making the container instance think that a file under a certain path on the test machine is a path under the operating system where the container instance is located.

[0040] Since the container instance is running in the test machine, it requires certain hardware storage resources. To further avoid resource waste, in some embodiments of the present invention, the Jenkins task also includes: After obtaining and returning the execution result of the target test case, the container instance is automatically destroyed.

[0041] The embodiment of the present invention can ensure the purity of hardware storage resources and avoid waste of resources by destroying the container instance after returning the execution result of the target test case.

[0042] Similarly, the target test case also needs to be called to the test machine for execution. To further avoid resource waste, in some embodiments of the present invention, the Jenkins task also includes: After obtaining and returning the execution result of the target test case, the target test case is automatically destroyed.

[0043] By destroying the target test cases, the target test cases can be prevented from occupying hardware storage resources, the number of cases that can be executed for automated testing in the test machine is increased, and resource waste is further reduced.

[0044] In order to implement silent browser invocation in an automated testing scenario, in some embodiments of the present invention, controlling the Docker engine to instantiate the Docker image to obtain a container instance includes: Get the process passing parameters; The Docker image is instantiated based on the process passing parameters and the Docker engine to obtain a container instance.

[0045] Since the Docker engine can pass parameters to the started process when instantiating the container, the embodiment of the present invention realizes silent calling of the browser by setting the process passing parameters.

[0046] In a specific embodiment of the present invention, the process transfer parameters include the browser type and the browser process starting method.

[0047] Specifically, the browser types include Chrome browser, Firefox browser and Edge browser.

[0048] Since the container instance contains an operating system without a graphical interface, the browser head execution model in the embodiment of the present invention is headless. Specifically, headless means that a graphical interface is not rendered, which can save a lot of resources.

[0049] In a specific embodiment of the present invention, the Web automation testing method is as follows: Figure 3 As shown, 1. The test engineer issues a test instruction, 2. Jenkins first issues a request to pull the test case to the test machine, 3. The test machine issues a test case request instruction to SVN, 4. SVN responds with a test case request instruction to return the target test case, 5. The test machine informs Jenkins that the test machine has obtained the test case, and then waits for the next instruction from Jenkins, 6. Jenkins issues an instantiation container instruction, a start test instruction, a container self-destruction instruction after the test is completed, and an active destruction of the test case instruction to the test machine, 7. The test machine responds to the instruction to instantiate the container, start the test, and actively destroy the test case after the container instance self-destructs, 8. The test machine generates a test report after the test is completed, and sends the test report to Jenkins, 9. The test report is then sent to the test engineer.

[0050] In order to better implement the Web automated testing method in the embodiment of the present invention, based on the Web automated testing method, the embodiment of the present invention also provides a Web automated testing device, such as Figure 4 As shown, the Web automated testing device 400 includes: The Docker image generation unit 401 is used to package the Cypress test engine, the browser and the browser dependencies based on the Docker engine to generate a Docker image; A test case storage unit 402, used to store multiple test cases in a version control system; The automated testing unit 403 is used to create and execute Jenkins tasks in response to test instructions; Among them, the Jenkins tasks include: obtaining the target test case from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting the target test case from multiple test cases, and executing the target test case based on the container instance.

[0051] The Web automated testing device 400 provided in the above embodiment can implement the technical solution described in the above Web automated testing method embodiment. The specific implementation principles of the above modules or units can refer to the corresponding contents in the above Web automated testing method embodiment, which will not be repeated here.

[0052] like Figure 5 As shown, the present invention also provides a corresponding Web automated testing device 500. The Web automated testing device 500 includes a processor 501, a memory 502 and a display 503. Figure 5 Only some components of the Web automated testing device 500 are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.

[0053] In some embodiments, the processor 501 may be a central processing unit (CPU), a microprocessor or other data processing chip, and is used to run program codes or process data stored in the memory 502, such as the Web automated testing method of the present invention.

[0054] In some embodiments, the processor 501 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 501 may be local or remote. In some embodiments, the processor 501 may be implemented in a cloud platform. In one embodiment, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination thereof.

[0055] In some embodiments, the memory 502 may be an internal storage unit of the Web automation test device 500, such as a hard disk or memory of the Web automation test device 500. In other embodiments, the memory 502 may also be an external storage device of the Web automation test device 500, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the Web automation test device 500.

[0056] Furthermore, the memory 502 may include both an internal storage unit of the Web automated testing device 500 and an external storage device. The memory 502 is used to store application software installed in the Web automated testing device 500 and various data.

[0057] In some embodiments, the display 503 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, etc. The display 503 is used to display information of the Web automation test device 500 and to display a visual user interface. The components 501-503 of the Web automation test device 500 communicate with each other through a system bus.

[0058] In some embodiments of the present invention, when the processor 501 executes the Web automation test program in the memory 502, the following steps may be implemented: Based on the Docker engine, the Cypress test engine, browser, and browser dependencies are packaged to generate a Docker image. Store multiple test cases in a version control system; Create and execute Jenkins tasks in response to test instructions; Among them, the Jenkins tasks include: obtaining target test cases from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting target test cases from multiple test cases, and executing the test cases based on the container instance.

[0059] It should be understood that: when the processor 501 executes the Web automated testing program in the memory 502, in addition to the above functions, other functions may also be implemented, and details may refer to the description of the corresponding method embodiments above.

[0060] Furthermore, the embodiment of the present invention does not specifically limit the type of the Web automation test device 500 mentioned. The Web automation test device 500 may be a portable Web automation test device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, a laptop computer, etc. Exemplary embodiments of portable Web automation test devices include but are not limited to portable Web automation test devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable Web automation test device may also be other portable Web automation test devices. It should also be understood that in some other embodiments of the present invention, the Web automation test device 500 may not be a portable Web automation test device, but a desktop computer with a touch-sensitive surface (such as a touch panel).

[0061] Accordingly, an embodiment of the present invention further provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps or functions in the Web automated testing method provided by the above-mentioned method embodiments can be implemented.

[0062] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.

[0063] The above is a detailed introduction to a Web automated testing method, device, equipment and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A Web automation testing method, It is characterized in that include: Based on the Docker engine, the Cypress test engine, browser, and browser dependencies are packaged to generate a Docker image. Store multiple test cases in a version control system; Create and execute Jenkins tasks in response to test instructions; The Jenkins task includes: obtaining a target test case from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting a target test case from the multiple test cases, and executing the target test case based on the container instance.

2. The Web automation testing method according to claim 1, It is characterized in that The Jenkins task also includes: After obtaining and returning the execution result of the target test case, the container instance is automatically destroyed.

3. The Web automation testing method according to claim 1, It is characterized in that The Jenkins task also includes: After obtaining and returning the execution result of the target test case, the target test case is automatically destroyed.

4. The Web automation testing method according to claim 1, It is characterized in that The Docker engine is installed on the test machine, and executing the target test case based on the container instance includes: Obtaining a target test case from the version control system, and downloading the target test case to a test machine; Controlling the container instance to perform path mapping to obtain an access path of the target test case in the test machine; The target test case is executed based on the container instance and the access path.

5. The Web automation testing method according to claim 1, It is characterized in that The controlling the Docker engine to instantiate the Docker image to obtain a container instance includes: Get the process passing parameters; The Docker image is instantiated based on the process transfer parameter and the Docker engine to obtain a container instance.

6. The Web automation testing method according to claim 5, It is characterized in that The process transfer parameters include the browser type and the browser process startup method.

7. The Web automated testing method according to claim 6, It is characterized in that The browser types include Chrome browser, Firefox browser and Edge browser, and the browser process startup mode is headless.

8. A Web automated testing device, It is characterized in that include: The Docker image generation unit is used to package the Cypress test engine, browser, and browser dependencies based on the Docker engine to generate a Docker image; A test case storage unit, used for storing multiple test cases in a version control system; Automated testing unit, used to create and execute Jenkins tasks in response to test instructions; The Jenkins task includes: obtaining a target test case from the version control system, controlling the Docker engine to instantiate the Docker image to obtain a container instance, extracting a target test case from the multiple test cases, and executing the target test case based on the container instance.

9. A Web automation testing device, It is characterized in that comprising a memory and a processor, wherein: The memory is used to store programs; The processor is coupled to the memory and is used to execute the program stored in the memory to implement the steps in the Web automated testing method described in any one of claims 1 to 7.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the steps of the Web automated testing method described in any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Server instance firmware parallel test method and electronic equipment

    CN121070717A