CN114281680B - Web automatic testing method and system - Google Patents

Web automatic testing method and system Download PDF

Info

Publication number
CN114281680B
CN114281680B CN202111471750.3A CN202111471750A CN114281680B CN 114281680 B CN114281680 B CN 114281680B CN 202111471750 A CN202111471750 A CN 202111471750A CN 114281680 B CN114281680 B CN 114281680B
Authority
CN
China
Prior art keywords
test
code
data
test case
assertion
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202111471750.3A
Other languages
Chinese (zh)
Other versions
CN114281680A (en
Inventor
徐基法
刘超
张悦
边智慧
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202111471750.3A priority Critical patent/CN114281680B/en
Publication of CN114281680A publication Critical patent/CN114281680A/en
Application granted granted Critical
Publication of CN114281680B publication Critical patent/CN114281680B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The invention provides a web automation test method and a web automation test system, wherein the method comprises the steps of obtaining a recording code uploaded by a client, wherein the recording code is obtained by a user through a Playwrite code recording command at the client; generating a script file of a Pytest test case according to the recorded code, wherein the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data; and responding to the test case and the configuration parameters selected by the user, calling an execution command of the corresponding script file in a headless mode, and sending the execution command to the Celery to asynchronously execute the web test task. And automatically rewriting the playwrite recording code into a Pytest test case code, realizing the problem that one case is suitable for a plurality of test data by utilizing the pre-processing and parameter configuration characteristics of Pytest, outputting a finishing test report, realizing repeated automatic execution of the test case, and improving the test efficiency.

Description

Web automatic testing method and system
Technical Field
The invention relates to the technical field of automatic testing, in particular to a web automatic testing method and system.
Background
Currently, UI (User Interface Design, interface design) automation tools are mostly implemented based on Selenium, which interacts with a browser through WebDriver, and Web testing is implemented through custom test scripts.
The use of Selenium for Web automation test cannot be used in Web conforming to RESTFUL protocol, and the use of browser is necessary for self-writing test script execution and during test, and the use has high dependence and complexity, and cannot support the automatic running of test cases at the back end in Linux/Unix server.
The prior patent application 202110506580 provides a method and a device for realizing automatic test of web applications, and provides a method and a device for generating test case codes through a Playwrite code recording function, manually adding assertion codes into the codes and capturing a screenshot, and running the edited codes in a playwrite headless mode. The code recorded each time in the technology can only support one test data test (manually input test data when the code is recorded) to be used, and cannot be suitable for one test case and multiple test data scenes.
Disclosure of Invention
The invention provides a web automatic test method and a web automatic test system, which are used for solving the problem that the existing test method cannot be suitable for multiple test scenes.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
the first aspect of the invention provides a web automation test method, which comprises the following steps:
the method comprises the steps of obtaining a recording code uploaded by a client, wherein the recording code is obtained by a user through a playwrite code recording command at the client;
generating a script file of a Pytest test case according to the recorded code, wherein the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data;
and responding to the test case and the configuration parameters selected by the user, calling an execution command of the corresponding script file in a headless mode, and sending the execution command to the Celery to asynchronously execute the web test task.
Further, the specific process of recording the code at the client by the user is as follows:
a user initiates a code recording instruction at the front end, the rear end executes a splicing playwrite code recording command, and a browser is opened;
and the user operates in the newly opened browser window, and closes the browser window after the operation is completed to generate a code file, wherein the operation is an execution action to be tested by the current test case.
Further, the specific process of generating the script file of the Pytest case according to the recording code is as follows:
according to the test case ID, obtaining case information from a database, and creating a test file under a specified directory;
creating a class object with a test case ID as a name, and adding a Pytest parameter annotation method;
creating a test function, wherein the test function parameters comprise a playwrite parameter page, test data and assertion data;
acquiring the recording code, and extracting a part of codes from the recording code to serve as running codes of the test function;
dividing the code line with preset keywords in the running code by commas, and taking the test data as the subscript of the matched sequence of the current code line;
and adding an assertion judgment at the end of the running code, traversing the assertion parameter list, and adding an assertion statement according to the assertion type.
Further, the use case information includes a use case name, test data, and assertion data.
Further, the extracting part of codes from the recorded codes as the running codes of the test function specifically includes:
in the recording code, a first appearance position of the keyword 'with' is extracted, and codes between two rows of the first appearance position and the keyword 'page. Close' are added as the running codes.
Further, after the test file is created, before the class object named as the test case ID is created, the method further includes the steps of: judging whether logging is needed, if not, creating a class object with the test case ID as a name, and if so, creating a pre-function.
Further, the specific process of creating the pre-function is as follows:
acquiring login data of test case configuration, and creating a prefix feature function logic, wherein the action range is a current object;
extracting a first appearance position of a keyword 'page. Goto' from the recorded code, and adding codes between two rows of the first appearance position of the keyword 'with' to serve as execution codes of a login function;
traversing the execution code of the login function, dividing the code line with the keyword 'fill' in the code by commas, and taking login data as the subscript of the matched sequence of the current code line.
Further, the configuration parameters include a record video option and a screenshot option.
A second aspect of the present invention provides a web automated testing system, comprising a client and a server,
the client is used for receiving the instruction and obtaining a recording code through a playwrite code recording command;
the server side is used for generating script files of Pytest test cases according to the recording codes, calling execution commands of the corresponding script files in a headless mode in response to the test cases and configuration parameters selected by a user, and sending the execution commands to the Celery to asynchronously execute test tasks; the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data.
Further, the server side comprises an application management module, a test case management module, a Pytest test case script generation module and a test case execution module;
the application management module is used for maintaining application information, creating test applications and filling in application names, application descriptions and application addresses;
the test case management module is used for creating test cases, maintaining test case names, test case descriptions, login judgment, test data and assertion data;
the Pytest test case script generation module receives the recorded codes uploaded by the client and generates a Pytest test case script file based on the recorded codes;
the test case execution module is used for executing the test case and generating a test record and supporting the check of a test report.
The network service control device according to the second aspect of the present invention can implement the methods according to the first aspect and the respective implementation manners of the first aspect, and achieve the same effects.
The effects provided in the summary of the invention are merely effects of embodiments, not all effects of the invention, and one of the above technical solutions has the following advantages or beneficial effects:
according to the invention, the recorded codes obtained through playwrite are automatically rewritten into Pytest test case codes, a group of test data corresponds to a plurality of groups of assertion data by utilizing the parameter configuration characteristics of Pytest, so that the problem that one test case is applicable to a plurality of test data is solved, a finishing test report is output, repeated automatic execution of the test case is realized, and the test efficiency is improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the description of the embodiments or the prior art will be briefly described below, and it will be obvious to those skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a schematic flow chart of an embodiment of the method of the present invention;
FIG. 2 is a flow chart of a client implementation in an embodiment of the method of the present invention;
FIG. 3 is a flowchart of a server implementation in an embodiment of the method of the present invention;
fig. 4 is a schematic diagram of an embodiment of the system of the present invention.
Detailed Description
In order to clearly illustrate the technical features of the present solution, the present invention will be described in detail below with reference to the following detailed description and the accompanying drawings. The following disclosure provides many different embodiments, or examples, for implementing different structures of the invention. In order to simplify the present disclosure, components and arrangements of specific examples are described below. Furthermore, the present invention may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. It should be noted that the components illustrated in the figures are not necessarily drawn to scale. Descriptions of well-known components and processing techniques and processes are omitted so as to not unnecessarily obscure the present invention.
The implementation of the embodiment of the invention depends on a client and a server, a user creates the test cases on line at the server, inputs case structured data (such as case description, input and assertion data and the like), logs in the test case list under the client request of own name, selects the test cases of the code to be recorded, and calls the code recording command to record the code by the client and uploads the code to the server. After receiving the code file, the server side automatically generates a test script file with a test beginning in a test script directory, automatically creates a test object in the test script file, respectively creates a function name with a test_beginning by a method of pre/post conditions, test data acquisition and the like and a recorded code, adds a Pytest parameter annotation (parameter) before recording the code function, takes a test data variable name as a function parameter, sequentially replaces data to be filled in the recording script with the test data variable, and adds assertion information into the method of the recorded code to complete the automatic generation of the Pytest test script. The user can select the test cases to be executed at the server, a plurality of test cases are executed concurrently by adopting a Pytest distributed plug-in (Pytest-xdist), and a visual test report is automatically generated by means of a Pytest-html module. Meanwhile, aiming at the requirement of parallel testing of a plurality of applications, the method that the server calls the Celery asynchronous task is high and supports test case execution, so that the writing work of test scripts is greatly reduced, and the Web automatic testing efficiency is improved.
As shown in fig. 1, an embodiment of the present invention provides a web automation test method, which includes the following steps:
s1, acquiring a recording code uploaded by a client, wherein the recording code is obtained by a user through a playwrite code recording command at the client;
s2, generating a script file of a Pytest test case according to the recording code, wherein the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data;
s3, responding to the test case and the configuration parameters selected by the user, calling the execution command of the corresponding script file in a headless mode, and sending the execution command to the Celery to asynchronously execute the web test task.
As shown in fig. 2, in step S1, the specific process of recording the code by the user at the client is as follows:
a user logs in a client, inquires a test case list created under the name of the user through an interface, selects a test case of a code to be recorded, and initiates a code recording command to the rear end, wherein the test case contains test application information such as system address information;
a user initiates a code recording instruction at the front end, the rear end executes a splicing playwrite code recording command, and a browser is opened;
and the user operates in the newly opened browser window, and closes the browser window after the operation is completed to generate a code file, wherein the operation is an execution action to be tested by the current test case.
After generating the recording code, the user initiates an uploading instruction at the front end, and the back end uploads the newly recorded code file to the server.
The client also comprises a step of verifying the user during the code recording process, specifically: after the user logs in the client, the user validity is verified by calling the interface, and after the user passes the verification, the test case inquiry interface is called to inquire the created test case list.
As shown in fig. 3, in step S2, the server receives the recorded code content uploaded by the client. The specific process of generating the script file of the Pytest test case according to the recording code is as follows:
according to the Test case ID, obtaining case information from a database, creating a test+item ID+case ID under a specified directory as a Test script file with a file name, and introducing a common module of Playwrite and Pytest into the Test script file;
according to the case ID, a test data list and an assertion data list are obtained from a database, a class object with the name of the test case ID is created, a method with test+run+case Id is created in the object by adding a Pytest parameter annotation method, a Pytest parameter annotation function (Pytest. Mark. Parameter, parameterized test data and assertion data are added before the method, matching is carried out according to the sequence, and the function parameters are added with a fix pre-treatment according to whether login treatment is needed; creating a test function, wherein the test function parameters comprise a playwrite parameter page, test data and assertion data;
acquiring the recording code, and extracting a part of codes from the recording code to serve as running codes of the test function;
dividing the code line with preset keywords in the running code by commas, and taking the test data as the subscript of the matched sequence of the current code line;
and adding an assertion judgment at the end of the running code, traversing the assertion parameter list, and adding an assertion statement according to the assertion type. The assertion type comprises characters, space, paths and states, and an added assertion statement such as assertPage. Url= assertdata [0];
after the code block is formed, writing the created test+item ID+case ID into a Test script file with a file name, and storing the Test script file.
The use case information includes a use case name, test data, and assertion data.
The operation code for extracting part of codes from the recorded codes as the test function is specifically as follows:
in the recording code, a first appearance position of the keyword 'with' is extracted, and codes between two rows of the first appearance position and the keyword 'page. Close' are added as the running codes.
After the test file is created, before the class object with the test case ID as the name is created, the method further comprises the steps of: judging whether logging is needed, if not, creating a class object with the test case ID as a name, and if so, creating a pre-function.
The specific process of creating the pre-function is as follows:
acquiring login data of test case configuration, and creating a prefix feature function logic, wherein the action range is a current object;
extracting a first appearance position of a keyword 'page. Goto' from the recorded code, and adding codes between two rows of the first appearance position of the keyword 'with' to serve as execution codes of a login function;
traversing the execution code of the login function, dividing the code line with the keyword 'fill' in the code by commas, and taking login data as the subscript of the matched sequence of the current code line.
In step S3, the user selects the test case set to be executed online, selects whether to record parameters such as video and screenshot, initiates a test case execution instruction to the back end, generates a Pytest test case execution command according to the parameters, calls and sends the Pytest case execution command to the Celery in a headless mode to asynchronously execute the test task, and the system automatically generates a test record, so that the user can check the test report online. The configuration parameters include a record video option and a screenshot option.
As shown in fig. 4, an embodiment of the present invention provides a web automation test system, including a server 1 and a client 2,
the client 2 is configured to receive an instruction, and obtain a recording code through a playwrite code recording command; the server 1 is used for generating a script file of a Pytest test case according to the recording code, responding to the test case and configuration parameters selected by a user, calling an execution command of the corresponding script file in a headless mode, and sending the execution command to a Celery to asynchronously execute a test task; the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data.
The server 1 comprises an application management module 11, a test case management module 12, a Pytest test case script generation module 13 and a test case execution module 14;
the application management module 11 is used for maintaining application information, creating test applications, and filling in application names, application descriptions and application addresses; the test case management module 12 is used for creating test cases, maintaining test case names, test case descriptions, login judgment, test data and assertion data; the Pytest test case script generation module 13 receives the recorded codes uploaded by the client and generates Pytest test case script files based on the recorded codes; the test case execution module 14 is used for executing test cases and generating test records, and supports checking of test reports.
While the foregoing description of the embodiments of the present invention has been presented in conjunction with the drawings, it should be understood that it is not intended to limit the scope of the invention, but rather, it is intended to cover all modifications or variations within the scope of the invention as defined by the claims of the present invention.

Claims (8)

1. A web automation test method, the test method comprising the steps of:
the method comprises the steps of obtaining a recording code uploaded by a client, wherein the recording code is obtained by a user through a playwrite code recording command at the client;
generating a script file of a Pytest test case according to the recorded code, wherein the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data;
responding to the test case and the configuration parameters selected by the user, calling the execution command of the corresponding script file in a headless mode, and sending the execution command to the Celery to asynchronously execute the web test task;
the specific process of generating the script file of the Pytest test case according to the recording code is as follows:
according to the test case ID, obtaining case information from a database, and creating a test file under a specified directory;
creating a class object with a test case ID as a name, and adding a Pytest parameter annotation method;
creating a test function, wherein the test function parameters comprise a Playwrite parameter page, test data and assertion data;
acquiring the recording code, and extracting a part of codes from the recording code to serve as running codes of the test function;
dividing the code line with preset keywords in the running code by commas, and taking the test data as the subscript of the matched sequence of the current code line;
and adding an assertion judgment at the end of the running code, traversing the assertion parameter list, and adding an assertion statement according to the assertion type.
2. The web automation test method of claim 1, wherein the specific process of recording the code by the user at the client is:
the user initiates a code recording instruction at the front end, the rear end executes a spliced Playright code recording command, and a browser is opened;
and the user operates in the newly opened browser window, and closes the browser window after the operation is completed to generate a code file, wherein the operation is an execution action to be tested by the current test case.
3. The web automated test method of claim 1, wherein the use case information comprises a use case name, test data, and assertion data.
4. The web automation test method of claim 1, wherein the extracting part of codes from the recorded codes as the running codes of the test function is specifically:
in the recording code, a first appearance position of the keyword 'with' is extracted, and codes between two rows of the first appearance position and the keyword 'page. Close' are added as the running codes.
5. The web automation test method of claim 1, further comprising the steps of, after the creating the test file, before creating the class object named test case ID: judging whether logging is needed, if not, creating a class object with the test case ID as a name, and if so, creating a pre-function.
6. The web automation test method of claim 5, wherein the specific process of creating the pre-function is:
acquiring login data of test case configuration, and creating a prefix feature function logic, wherein the action range is a current object;
extracting a first appearance position of a keyword 'page. Goto' from the recorded code, and adding codes between two rows of the first appearance position of the keyword 'with' to serve as execution codes of a login function;
traversing the execution code of the login function, dividing the code line with the keyword 'fill' in the code by commas, and taking login data as the subscript of the matched sequence of the current code line.
7. The web automated testing method of claim 1, wherein the configuration parameters include a record video option and a screenshot option.
8. A web automation test system comprises a client and a server, and is characterized in that,
the client is used for receiving the instruction and obtaining a recording code through a playwrite code recording command;
the server side is used for generating a script file of the Pytest test case according to the recording code, responding to the test case and the configuration parameters selected by a user, calling an execution command of the corresponding script file in a headless mode, and sending the execution command to the Celery to asynchronously execute a test task; the test case comprises test data and assertion data, and one group of the test data at least corresponds to one group of assertion data;
the server side comprises an application management module, a test case management module, a Pytest test case script generation module and a test case execution module;
the application management module is used for maintaining application information, creating test applications and filling in application names, application descriptions and application addresses;
the test case management module is used for creating test cases, maintaining test case names, test case descriptions, login judgment, test data and assertion data;
the Pytest test case script generation module receives the recorded codes uploaded by the client and generates a Pytest test case script file based on the recorded codes;
the test case execution module is used for executing the test case and generating a test record and supporting the check of a test report;
according to the recording code, the specific process for generating the script file of the Pytest test case is as follows:
according to the test case ID, obtaining case information from a database, and creating a test file under a specified directory;
creating a class object with a test case ID as a name, and adding a Pytest parameter annotation method;
creating a test function, wherein the test function parameters comprise a Playwrite parameter page, test data and assertion data;
acquiring the recording code, and extracting a part of codes from the recording code to serve as running codes of the test function;
dividing the code line with preset keywords in the running code by commas, and taking the test data as the subscript of the matched sequence of the current code line;
and adding an assertion judgment at the end of the running code, traversing the assertion parameter list, and adding an assertion statement according to the assertion type.
CN202111471750.3A 2021-12-03 2021-12-03 Web automatic testing method and system Active CN114281680B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111471750.3A CN114281680B (en) 2021-12-03 2021-12-03 Web automatic testing method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111471750.3A CN114281680B (en) 2021-12-03 2021-12-03 Web automatic testing method and system

Publications (2)

Publication Number Publication Date
CN114281680A CN114281680A (en) 2022-04-05
CN114281680B true CN114281680B (en) 2024-01-12

Family

ID=80871005

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111471750.3A Active CN114281680B (en) 2021-12-03 2021-12-03 Web automatic testing method and system

Country Status (1)

Country Link
CN (1) CN114281680B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114637692B (en) * 2022-05-17 2022-08-19 杭州优诗科技有限公司 Test data generation and test case management method
CN116070214B (en) * 2022-08-30 2024-04-02 荣耀终端有限公司 Safety testing method and electronic equipment
CN115658496A (en) * 2022-10-21 2023-01-31 北京志凌海纳科技有限公司 Extensible Web automatic test method, system, equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101241467A (en) * 2008-03-05 2008-08-13 罗笑南 Automatized white box test system and method facing to WEB application
CN108073515A (en) * 2017-12-06 2018-05-25 郑州云海信息技术有限公司 A kind of Multi-server automated testing methods and system
CN110851356A (en) * 2019-10-30 2020-02-28 河海大学 Selenium-based Web application automatic test framework and construction method and system thereof
CN112988605A (en) * 2021-05-10 2021-06-18 云账户技术(天津)有限公司 Method and device for realizing WEB application automatic test

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101241467A (en) * 2008-03-05 2008-08-13 罗笑南 Automatized white box test system and method facing to WEB application
CN108073515A (en) * 2017-12-06 2018-05-25 郑州云海信息技术有限公司 A kind of Multi-server automated testing methods and system
CN110851356A (en) * 2019-10-30 2020-02-28 河海大学 Selenium-based Web application automatic test framework and construction method and system thereof
CN112988605A (en) * 2021-05-10 2021-06-18 云账户技术(天津)有限公司 Method and device for realizing WEB application automatic test

Also Published As

Publication number Publication date
CN114281680A (en) 2022-04-05

Similar Documents

Publication Publication Date Title
CN114281680B (en) Web automatic testing method and system
CN108876121A (en) Worksheet method, apparatus, computer equipment and storage medium
CN109977389A (en) List input method, device, computer equipment and storage medium
CN105373478B (en) Automated testing method and system
CN106656927B (en) Method and device for adding Linux account into AD domain
CN108923997B (en) Cloud service node automatic testing method and device based on python
CN109560996B (en) Automatic testing system and method for terminal of Internet of things
CN110351259A (en) A kind of method and device obtaining APP authentication information based on network packet capturing
CN112181477B (en) Complex event processing method and device and terminal equipment
WO2020186680A1 (en) Interface testing method based on modeling platform
CN107665170B (en) Flow testing method and device
CN105204991A (en) Internet of things test method and device
CN112187580B (en) Automatic testing framework and testing method for gateway plug-in
CN103152391A (en) Journal output method and device
CN114741283A (en) Automatic interface testing method and device based on python design
CN106034113A (en) Data processing method and data processing device
Roussev et al. API-based forensic acquisition of cloud drives
CN111506311A (en) Internet rapid iterative development, integration and release method and middlebox enabling engine
CN111596899A (en) Database migration method, system, equipment and storage medium based on Java development
CN103019931B (en) The check processing method and apparatus of Asn.1 interface
CN114416547A (en) Test case based test method
CN113590564B (en) Data storage method, device, electronic equipment and storage medium
CN109741780A (en) A kind of method and its system based on linux system test SSD performance
CN105446867A (en) Method and apparatus for generating test data
CN112069062A (en) Method and device for editing and generating software test bug module

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant