CN114265785A - Method for generating automatic test script based on Charles - Google Patents

Method for generating automatic test script based on Charles Download PDF

Info

Publication number
CN114265785A
CN114265785A CN202111641228.5A CN202111641228A CN114265785A CN 114265785 A CN114265785 A CN 114265785A CN 202111641228 A CN202111641228 A CN 202111641228A CN 114265785 A CN114265785 A CN 114265785A
Authority
CN
China
Prior art keywords
test
test script
script
file
charles
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.)
Pending
Application number
CN202111641228.5A
Other languages
Chinese (zh)
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.)
Wuxi Xuelang Shuzhi Technology Co ltd
Original Assignee
Wuxi Xuelang Shuzhi 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 Wuxi Xuelang Shuzhi Technology Co ltd filed Critical Wuxi Xuelang Shuzhi Technology Co ltd
Priority to CN202111641228.5A priority Critical patent/CN114265785A/en
Publication of CN114265785A publication Critical patent/CN114265785A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention belongs to the field of automatic testing, and discloses a method for generating an automatic testing script based on Charles, which comprises the following steps: self-defining a test script template; opening a Charles tool, browsing a webpage with a required interface automation, and recording http/https session parameters; selecting interface information needing interface automation, and exporting data in a certain format; constructing a script by using a json and a Yaml library of python, analyzing the interface data of the exported data by using a first mode, reading a packet capturing file, analyzing the message information of the request, and intercepting fields defined in a test script template to obtain a test case file in a Yaml format; and generating a test script file corresponding to the test case file according to the test script template. The invention greatly reduces the time for writing the automatic script and the parameter file and saves the labor cost.

Description

Method for generating automatic test script based on Charles
Technical Field
The invention belongs to the technical field of automatic testing, and particularly relates to a method for generating an automatic testing script based on Charles.
Background
With the development of software testing technology, the interface automatic testing is more and more popular as an important means for improving testing efficiency and ensuring testing coverage. However, in the process of writing the interface automation test script, a great amount of manpower is wasted to repeat the writing of the test script and the interface parameters.
The existing Jmeter is a Java-based stress testing tool and supports recording of interfaces. But only supports the interface request of the Http protocol, which requires the installation of a certificate. Many of the actual projects are Http protocols, and in the actual interface automation test, the continuous inheritance of the automation test is not facilitated, the application scenarios are very limited, and the requirements of automatic generation of scripts and parameters of the interface automation cannot be met.
The Jmeter tool recording interface has higher dependence on later-stage interface automation, is not flexible enough, and can not meet the requirement of continuous integration of automation. When the number of the interfaces is large, the scripts and the interface parameters are written by different interfaces one by one, and a great deal of energy and time are consumed.
Disclosure of Invention
In view of this, the invention provides a method for recording the data packet by the Charles tool, analyzing the data packet, and automatically generating the automatic script and the test data, thereby greatly saving the labor cost and improving the automation efficiency.
Specifically, the method for generating the automatic test script based on Charles provided by the invention comprises the following steps:
self-defining a test script template;
opening a Charles tool, browsing a webpage with a required interface automation, and recording http/https session parameters;
selecting interface information needing interface automation, and exporting data in a certain format;
constructing a script by using a json and a Yaml library of python, analyzing interface data of the exported data by using an auto _ switch ═ 1 mode, reading a packet capturing file, analyzing message information of a request, and intercepting fields defined in a test script template to obtain a test case file in a Yaml format;
and generating a test script file corresponding to the test case file according to the test script template.
Furthermore, the test case file in the Yaml format comprises a plurality of key value pairs, wherein the keys are fields defined in the test script template, and the values are values of corresponding fields analyzed from the packet capturing file.
Furthermore, the keys in the Yaml-format test case file comprise a request address, a request protocol, a request mode, a request address, a request header, a case name, return information and verification content.
Furthermore, the test script file runs according to the parameters defined in the test case file, and the test script file can run directly.
Further, the derived data is in a ". chlsj" format.
Furthermore, the test script template comprises a third-party library to be introduced, a test case name, a test script execution sequence, request information sent by the test script, and result verification returned by the test script.
The invention has the following beneficial effects:
the time for writing the automatic script and the parameter file is greatly reduced, and the labor cost is saved.
Drawings
FIG. 1 is a process framework diagram of the present invention;
FIG. 2 is an exemplary diagram of a custom test script template of the present invention;
FIG. 3 is an exemplary diagram of a test case file of the present invention;
FIG. 4 is an exemplary diagram of a test script file of the present invention.
Detailed Description
The invention is further described with reference to the accompanying drawings, but the invention is not limited in any way, and any alterations or substitutions based on the teaching of the invention are within the scope of the invention.
The invention provides a Charles-based recorded data packet, and parameter files, test script data and the like are generated by analyzing the recorded data packet.
The technical scheme of the invention is as follows:
the test method for automatically generating the automatic test script based on the Charles recorded data packet comprises the following steps:
and self-defining a test script template, wherein the test script template comprises a third-party library to be introduced, a test case name, a test script execution sequence, request information sent by the test script and result verification returned by the test script.
Opening a Charles tool, browsing a webpage with a required interface automation, and recording http/https session parameters;
selecting interface information needing interface automation, and exporting data in a format of 'chlsj';
constructing a script by using a json and a Yaml library of python, analyzing interface data of the exported data by using an auto _ switch ═ 1 mode, reading a packet capturing file, analyzing message information of a request, and intercepting fields defined in a test script template to obtain a test case file in a Yaml format; the test case file in the Yaml format comprises a plurality of key value pairs, wherein the keys are fields defined in the test script template, and the values are numerical values of the corresponding fields analyzed from the packet capturing file. The keys in the Yaml format test case file comprise a request address, a request protocol, a request mode, a request address, a request header, a case name, return information and verification content.
The construction of a script using the json and Yaml libraries of python includes the following steps:
reading the packet capture file by using more than a certain number of request parameters through a json library json of python, and generating a json file of the request parameters through json.
And reading the bale plucking file by using Yaml library yaml.load of python, generating a Yaml test case by using a Yaml _ dump function, calling the request parameter of the json file if the request parameter in the test case exceeds 200 characters, and putting the request parameter in the Yaml file if the request parameter does not exceed 200 characters.
And generating a test script file corresponding to the test case file according to the test script template. The test script file runs according to the parameters defined in the test case file, and the test script file can run directly.
In order to make the technical solutions and advantages of the present invention clearer, the present invention is described below with reference to practical examples. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Examples
1. Opening a Charles tool, browsing a required interface automation webpage, recording http/https session parameters, screening interface information needing interface automation writing according to an interface document of a development engineer, exporting the interface information in a format of 'chlsj', analyzing the interface data by using an auto _ switch 1 mode through exported data, and automatically generating two parts of contents, namely a test case and a test script after the data analysis is finished. The auto _ switch is a self-defined mode, and the embodiment has two models, namely, automatically generating a test case and a script, and automatically running the test case and the script, wherein if the auto _ switch is used as the 1 mode, the test case and the test script are automatically generated. If auto _ switch ═ 0 mode is used, then test cases and test scripts are not generated, but rather the test cases and test scripts that have been produced are executed.
2. Analyzing data by reading the packet capturing file, analyzing the message information of the request, intercepting the corresponding field, and generating a test case Yaml as follows:
intercepting keywords in the captured data packet to extract information such as host (request address), schema (request protocol), method (request mode), address (request address), headers (request header), summary (use case name), check _ body (return information and check content), and generating according to the following steps: a test case file in the form of 'Yaml', such as host (request address), schema (request protocol), method (request mode), address (request address), headers (request header), summary (case name), check _ body (check content of returned information), and the like, and an exemplary generated test case file is shown in fig. 3. The test information comprises title, host, scheme, address, mime _ type, heads, timeout, file, cookies, premix and other information; the test case comprises: summary, descriptor, parameter, check _ body, etc.
3. And analyzing the well-defined data, and simultaneously generating a test script file corresponding to the test case according to the well-defined test script template, wherein the well-defined automation script is shown as figure 4 and comprises an introduced package, a test case file and a path, a test step and the like.
4. The generated test script runs according to the test case (parameter file);
5. or test scripts and test cases have been generated, it is possible to run directly in the test mode aoto _ switch ═ 2.
The invention has the following beneficial effects:
the time for writing the automatic script and the parameter file is greatly reduced, and the labor cost is saved.
The word "preferred" is used herein to mean serving as an example, instance, or illustration. Any aspect or design described herein as "preferred" is not necessarily to be construed as advantageous over other aspects or designs. Rather, use of the word "preferred" is intended to present concepts in a concrete fashion. The term "or" as used in this application is intended to mean an inclusive "or" rather than an exclusive "or". That is, unless specified otherwise or clear from context, "X employs A or B" is intended to include either of the permutations as a matter of course. That is, if X employs A; b is used as X; or X employs both A and B, then "X employs A or B" is satisfied in any of the foregoing examples.
Also, although the disclosure has been shown and described with respect to one or an implementation, equivalent alterations and modifications will occur to others skilled in the art based upon a reading and understanding of this specification and the annexed drawings. The present disclosure includes all such modifications and alterations, and is limited only by the scope of the appended claims. In particular regard to the various functions performed by the above described components (e.g., elements, etc.), the terms used to describe such components are intended to correspond, unless otherwise indicated, to any component which performs the specified function of the described component (e.g., that is functionally equivalent), even though not structurally equivalent to the disclosed structure which performs the function in the herein illustrated exemplary implementations of the disclosure. In addition, while a particular feature of the disclosure may have been disclosed with respect to only one of several implementations, such feature may be combined with one or other features of the other implementations as may be desired and advantageous for a given or particular application. Furthermore, to the extent that the terms "includes," has, "" contains, "or variants thereof are used in either the detailed description or the claims, such terms are intended to be inclusive in a manner similar to the term" comprising.
Each functional unit in the embodiments of the present invention may be integrated into one processing module, or each unit may exist alone physically, or a plurality of or more than one unit are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium. The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc. Each apparatus or system described above may execute the storage method in the corresponding method embodiment.
In summary, the above-mentioned embodiment is an implementation manner of the present invention, but the implementation manner of the present invention is not limited by the above-mentioned embodiment, and any other changes, modifications, substitutions, combinations, and simplifications which do not depart from the spirit and principle of the present invention should be regarded as equivalent replacements within the protection scope of the present invention.

Claims (6)

1. The method for generating the automatic test script based on Charles is characterized by comprising the following steps of:
self-defining a test script template;
opening a Charles tool, browsing a webpage with a required interface automation, and recording http/https session parameters;
selecting interface information needing interface automation, and exporting data in a certain format;
constructing a script by using a json and a Yaml library of python, using the exported data to generate a test case and a script mode to analyze interface data, reading a packet capturing file, analyzing message information of a request, and intercepting fields defined in a test script template to obtain a test case file in a Yaml format;
and generating a test script file corresponding to the test case file according to the test script template.
2. The Charles-based method for generating an automated test script according to claim 1, wherein the test case file in the Yaml format comprises a plurality of key value pairs, wherein a key is a field defined in the test script template, and a value is a numerical value obtained by parsing a corresponding field from the capture package file.
3. The Charles-based method for generating an automated test script according to claim 1, wherein the keys in the Yaml-format test case file comprise a request address, a request protocol, a request mode, a request address, a request header, a case name, return information and verification content.
4. The Charles-based method for generating automated test scripts according to claim 1, wherein the test script files are run according to parameters defined in the test case files, and the test script files can be run directly.
5. The Charles-based generation method for automated test scripts according to claim 1, wherein the derived data is in ". chlsj" format.
6. The Charles-based method for generating an automated test script, as claimed in claim 1, wherein the test script template comprises a third party library to be introduced, a test case name, a test script execution sequence, request information sent by the test script, and result verification returned by the test script.
CN202111641228.5A 2021-12-29 2021-12-29 Method for generating automatic test script based on Charles Pending CN114265785A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111641228.5A CN114265785A (en) 2021-12-29 2021-12-29 Method for generating automatic test script based on Charles

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111641228.5A CN114265785A (en) 2021-12-29 2021-12-29 Method for generating automatic test script based on Charles

Publications (1)

Publication Number Publication Date
CN114265785A true CN114265785A (en) 2022-04-01

Family

ID=80831398

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111641228.5A Pending CN114265785A (en) 2021-12-29 2021-12-29 Method for generating automatic test script based on Charles

Country Status (1)

Country Link
CN (1) CN114265785A (en)

Similar Documents

Publication Publication Date Title
CN106776515B (en) Data processing method and device
Tahat et al. Requirement-based automated black-box test generation
CN107122296B (en) Method and apparatus for data assertion for test interface
CN109800258B (en) Data file deployment method, device, computer equipment and storage medium
CN111552633A (en) Interface abnormal call testing method and device, computer equipment and storage medium
CN106649110B (en) Software testing method and system
CN114416547A (en) Test case based test method
CN114443466A (en) Method for converting executable script by using case file, terminal equipment and storage medium
CN112883088B (en) Data processing method, device, equipment and storage medium
CN114265785A (en) Method for generating automatic test script based on Charles
CN111143310B (en) Log recording method and device and readable storage medium
CN113672233B (en) Server out-of-band management method, device and equipment based on Redfish
CN114138633A (en) Method, device and equipment for testing software based on data driving and readable medium
CN113609427B (en) System data resource extraction method and system under no-interface condition
CN103257911B (en) A kind of model testing Tool integration method based on SOA framework
CN114297074A (en) Method for realizing automatic testing of functions, interfaces and performances based on dynamic configuration
CN112860587B (en) UI automatic test method and device
CN113672509A (en) Automatic testing method, device, testing platform and storage medium
CN116962407B (en) Distributed link label processing method and device, distributed link tracking system and distributed system
CN111930608A (en) Automatic testing device and method based on process control
US8977901B1 (en) Generating service call patterns for systems under test
CN109508245A (en) A kind of method and terminal for realizing anomaly analysis
CN116775022A (en) Front-end application component development method based on VUE
CN115640794A (en) Data acquisition method and system for optimizing new energy grid-involved output characteristics
CN114385947A (en) Webpage publishing method, system, device and medium

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