CN112988578A - Automatic testing method and device - Google Patents

Automatic testing method and device Download PDF

Info

Publication number
CN112988578A
CN112988578A CN202110260174.1A CN202110260174A CN112988578A CN 112988578 A CN112988578 A CN 112988578A CN 202110260174 A CN202110260174 A CN 202110260174A CN 112988578 A CN112988578 A CN 112988578A
Authority
CN
China
Prior art keywords
test
test script
flow
sub
statement
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
CN202110260174.1A
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.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
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 China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202110260174.1A priority Critical patent/CN112988578A/en
Publication of CN112988578A publication Critical patent/CN112988578A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3684Test management for test design, e.g. generating new test cases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • G06F11/3688Test management for test execution, e.g. scheduling of test suites

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention discloses an automatic testing method and device, and relates to the technical field of computers. One embodiment of the method comprises: acquiring a test script statement written for a target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly and realizing the operation of the test flow indication at the position; determining a test script statement for realizing a sub-flow in a test flow, and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow; and executing the test script on the object to be tested to realize the automatic test of the object to be tested. According to the embodiment, the test script which is suitable for developers and testers is generated by acquiring the test script statements compiled based on the component identifiers, so that the position of the target component can be positioned through the component identifiers when the test script is executed, the operations such as clicking and inputting are automatically realized, and the development efficiency and the test efficiency are improved.

Description

Automatic testing method and device
Technical Field
The invention relates to the technical field of computers, in particular to an automatic testing method and device.
Background
Existing software test schemes are typically: the method comprises the steps that a developer manually performs unit testing in the development process, after the unit testing is passed and integrated codes are completed, the tester performs the integrated testing, test cases are manually input and output one by one in the integrated testing process, test reports are output, and the test cases are fed back to the developer to perform bug (defect) repair and code improvement.
In the process of implementing the invention, the prior art at least has the following problems:
the degree of dependence of software testing on manual operation is high, the time cost and the labor cost are high, and bug positioning is difficult and the error rate is high; meanwhile, a developer manually executes a test in the development process, so that the development progress is influenced.
Disclosure of Invention
In view of this, embodiments of the present invention provide an automated testing method and apparatus, which generate a test script suitable for developers and testers at the same time by obtaining a test script statement compiled based on a component identifier, so that a position of a target component can be located through the component identifier when the test script is executed, and further operations such as clicking, inputting and the like are automatically implemented, manual operation is not required, problems can be found in time, and development efficiency and testing efficiency are improved.
To achieve the above object, according to an aspect of an embodiment of the present invention, an automated testing method is provided.
The automatic testing method of the embodiment of the invention comprises the following steps: acquiring a test script statement written for a target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly, and realizing the operation indicated by the test flow at the position; determining a test script statement for realizing a sub-flow in the test flow, and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow; and executing the test script on the object to be tested to realize the automatic test of the object to be tested.
Optionally, the test script includes a unit test script and/or an integrated test script; generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow, wherein the test script generation comprises the following steps: writing a test script statement for realizing the sub-flow into the unit test script according to the execution sequence of the sub-flow; or according to the execution sequence of the sub-processes, writing the test script statements for realizing the sub-processes into the unit test scripts; and packaging a plurality of unit test scripts to obtain the integrated test script.
Optionally, the determining a test script statement for implementing a sub-process in the test process includes: determining a target component set corresponding to a sub-process in the test process; and taking a test script statement written for the target component of the target component set as a test script statement for realizing the sub-flow in the test flow.
Optionally, the executing the test script on the object to be tested includes: if the test type is determined to be the unit test, executing the unit test script on the object to be tested; and if the test type is determined to be the integration test, executing the integration test script on the object to be tested.
Optionally, the test script statement includes a component positioning statement and a component operating statement; the component positioning statement is used for positioning the position of the target component on the object to be detected according to the component identifier of the target component; the component operation statement is used for realizing the operation indicated by the test flow at the position.
Optionally, for a target component belonging to a set of set waiting components, the test script statement further includes: a wait statement provided between the component locate statement and the component operate statement; wherein the wait statement is used for waiting for a set time or waiting for the target component selected by the selector to appear.
Optionally, the target component of the waiting component set satisfies any one or more of the following waiting conditions: and the loading time is greater than a set loading time threshold, the page rendering time is greater than a set rendering time threshold, and a result is returned by depending on an interface when the operation indicated by the test flow is realized.
Optionally, the component identifier is a class name corresponding to the target component; the positioning the position of the target assembly on the object to be measured according to the assembly identifier of the target assembly comprises: searching for a label of the target component; wherein the tag is to indicate a function of the target component; and positioning the position of the target assembly on the object to be detected according to the class name and the label.
Optionally, the method further comprises: and configuring a unique component identifier for the target component, and writing the target component and the corresponding component identifier into a configuration file.
Optionally, the method further comprises: acquiring a screenshot script statement written for a set test node; generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow, wherein the generating comprises the following steps: generating an initial test script according to the execution sequence of the sub-flows and the test script statements for realizing the sub-flows; and inserting the screenshot script statement at the test node position of the initial test script to generate a final test script.
Optionally, the test node is an abstract node meeting a set screenshot condition according to the sub-process.
Optionally, the screenshot condition includes an interface return error and/or a page response exception.
Optionally, after the step of executing the test script on the object to be tested, the method further includes: and printing the test information obtained in the process of executing the test script to a log file.
To achieve the above object, according to another aspect of the embodiments of the present invention, an automated testing apparatus is provided.
An automated testing apparatus according to an embodiment of the present invention includes: the acquisition module is used for acquiring a test script statement written for the target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly, and realizing the operation indicated by the test flow at the position; the generating module is used for determining a test script statement for realizing a sub-flow in the test flow and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow; and the test module is used for executing the test script on the object to be tested to realize the automatic test of the object to be tested.
Optionally, the test script includes a unit test script and/or an integrated test script; the generating module is further configured to write a test script statement for implementing the sub-flow into the unit test script according to the execution sequence of the sub-flow; or according to the execution sequence of the sub-processes, writing the test script statements for realizing the sub-processes into the unit test scripts; and packaging a plurality of unit test scripts to obtain the integrated test script.
Optionally, the generating module is further configured to determine a target component set corresponding to a sub-process in the test process; and taking a test script statement written for the target component of the target component set as a test script statement for realizing the sub-flow in the test flow.
Optionally, the test module is further configured to execute the unit test script on the object to be tested if it is determined that the test type is a unit test; and if the test type is determined to be the integration test, executing the integration test script on the object to be tested.
Optionally, the test script statement includes a component positioning statement and a component operating statement; the component positioning statement is used for positioning the position of the target component on the object to be detected according to the component identifier of the target component; the component operation statement is used for realizing the operation indicated by the test flow at the position.
Optionally, for a target component belonging to a set of set waiting components, the test script statement further includes: a wait statement provided between the component locate statement and the component operate statement; wherein the wait statement is used for waiting for a set time or waiting for the target component selected by the selector to appear.
Optionally, the target component of the waiting component set satisfies any one or more of the following waiting conditions: and the loading time is greater than a set loading time threshold, the page rendering time is greater than a set rendering time threshold, and a result is returned by depending on an interface when the operation indicated by the test flow is realized.
Optionally, the component identifier is a class name corresponding to the target component; the test script statement is also used for searching a label of the target component; wherein the tag is to indicate a function of the target component; and positioning the position of the target assembly on the object to be detected according to the class name and the label.
Optionally, the apparatus further comprises: and the configuration module is used for configuring a unique component identifier for the target component and writing the target component and the corresponding component identifier into a configuration file.
Optionally, the apparatus further comprises: the screenshot module is used for acquiring a screenshot script statement written for a set test node; the generating module is further configured to generate an initial test script according to the execution sequence of the sub-processes and the test script statements for implementing the sub-processes; and inserting the screenshot script statement at the test node position of the initial test script to generate a final test script.
Optionally, the test node is an abstract node meeting a set screenshot condition according to the sub-process.
Optionally, the screenshot condition includes an interface return error and/or a page response exception.
Optionally, the apparatus further comprises: and the output module is used for printing the test information obtained in the process of executing the test script to a log file.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided an electronic apparatus.
An electronic device of an embodiment of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the automatic testing method of the embodiment of the invention.
To achieve the above object, according to still another aspect of embodiments of the present invention, there is provided a computer-readable medium.
A computer-readable medium of an embodiment of the present invention has a computer program stored thereon, which when executed by a processor implements an automated testing method of an embodiment of the present invention.
One embodiment of the above invention has the following advantages or benefits: through obtaining the test script statement compiled based on the component identification, the test script suitable for developers and testers is generated, so that the position of the target component can be positioned through the component identification when the test script is executed, the operations such as clicking and inputting are automatically realized, manual operation is not needed, problems can be found in time, and the development efficiency and the test efficiency are improved.
By generating the unit test script and the integrated test script, developers can conveniently verify the updated part or the newly developed part through the unit test script when updating codes or developing new functions, and then verify whether the updated part or the newly developed part affects other functional modules of the system by using the integrated test script, so that accurate positioning of the bug is facilitated, and meanwhile, the high quality of the codes can be guaranteed. And determining the test script statements of the sub-flows based on the target components corresponding to the sub-flows in the test flows, so that the test scripts can be automatically generated conveniently.
And according to different test types, the test scripts of the corresponding types are executed, so that the flexibility is good. The test script statements are divided into component positioning statements and component operating statements according to functions, so that other functional statements can be added in the test script statements conveniently. And adding a waiting statement between the component positioning statement and the component operation statement to enable the component operation statement to be successfully executed. And a waiting component set is constructed by setting a waiting condition, so that the flexibility is good.
And uniquely determining a target assembly based on the class name and the label corresponding to the target assembly, so as to be convenient for subsequently positioning the position of the target assembly on the object to be detected. The unique component identifier is set for the target component, so that the position of the target component on the object to be tested can be conveniently positioned subsequently, and a test script matched with the target component can be written. Through the processes of screenshot storage and printing test on the test nodes, developers can conveniently position the bug and correct codes, the developers can conveniently feed back the bug, and the labor cost of manual test and manual report output of the developers is reduced.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a schematic diagram of the main steps of an automated testing method according to an embodiment of the invention;
FIG. 2 is a schematic flow chart of an automated testing method according to another embodiment of the present invention;
FIG. 3 is a schematic flow chart of an automated testing method according to another embodiment of the present invention;
FIG. 4 is a schematic diagram of the main modules of an automated test equipment according to an embodiment of the present invention;
FIG. 5 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
FIG. 6 is a schematic diagram of a computer apparatus suitable for use in an electronic device to implement an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
Terms related to the embodiments of the present invention are explained below.
Automated testing: generally referred to as automation of software testing. The software test is to run a system or an application program under a preset condition and evaluate a running result, wherein the preset condition comprises a normal condition and an abnormal condition. Automated testing is a process that translates human-driven testing behavior into machine execution.
Assembly of: is a simple encapsulation of data and methods. The components may have their own properties and methods. An attribute is a simple visitor to component data. The method is some simple and visible function of the component.
Script: generally refers to an executable file written in a certain format using a particular descriptive language.
Unit testing: refers to checking and verifying the smallest unit of testability in software. The unit in the unit test is an artificially specified minimum tested function module, and may be, for example, a function, a component, a segment of code, or the like.
And (3) integration test: also called assembly test or combination test. On the basis of unit test, all modules are assembled into a subsystem or a system according to design requirements (such as according to a structure diagram) to carry out integrated test.
Test case: the method refers to the description of testing tasks performed on a specific software product, and embodies testing schemes, methods, techniques and strategies. The contents of the test object, the test environment, the input data, the test steps, the expected results, the test scripts and the like are included, and finally, a document is formed. A test case may be considered to be a set of test inputs, execution conditions, and expected results tailored for a particular purpose to verify that a particular software requirement is met.
In the process of front-end development, if a developer modifies a certain module of the system or newly develops certain functions, the original module of the system may be affected, and for the situation of multi-person collaborative development and update iteration, the code is usually difficult to maintain and has a disordered structure, so that the test is a very important link. However, as in the background art, the test scheme in the prior art has a large dependence on manual operation, low efficiency, and difficulty in positioning the bug, so the embodiment provides an automated test method applicable to the front end, which is as follows.
Example one
FIG. 1 is a schematic diagram of the main steps of an automated testing method according to an embodiment of the invention. As shown in fig. 1, the automated testing method according to the embodiment of the present invention mainly includes the following steps:
step S101: and acquiring a test script statement written for the target component. The target component is a component contained in the object to be measured. The test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly and realizing the operation indicated by the test flow at the position.
The component identifier may be a unique id representing the target component, or may be a class name (class) defined for the target component in the code of the object to be tested. The unique id may be, for example: a Universal Unique Identifier (UUID), a Global Unique Identifier (GUID), an id generated based on a Snowflake algorithm (Snowflake), and the like.
The object to be tested can be set in a self-defined manner, for example, the object to be tested can be an application to be tested, a functional module (such as a login module and a search module) in the application, a minimum testable unit of the application, and the like. For the condition that the component identification is the unique id, the unique id needs to be configured for the target component in advance, the target component and the corresponding unique id are written into a configuration file, so that the unique id of the target component can be obtained from the configuration file, and then a test script statement is written according to the unique id. For the case that the component identification is a class name, the class name can be directly obtained from the written code, and then a test script statement is written according to the class name.
When writing a test script statement, the function and the operation flow of an application to be tested (i.e. the application to be tested is developed and completed) or an application under development need to be analyzed, a test case and a test flow are determined, and then the test script statement is written based on the test case and the test flow. After the test script statements are written, the test script statements are stored, and the test script statements can be directly obtained when a test is needed (for example, when a test instruction is received).
Step S102: and determining a test script statement for realizing the sub-flow in the test flow, and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow. Before determining the test script statement of the sub-flow, the test flow needs to be decomposed to obtain a minimum flow unit, and then the sub-flow is constructed based on the minimum flow unit.
Wherein, the minimum process unit is a part which can not be separated again in the test process. For example, the minimum flow unit may be a process flow of locating a user name input box, or a process flow of inputting a user name in a user name input box. The sub-flow may be the minimum flow unit itself or a combination of adjacent minimum flow units, such as a process flow of locating a user name input box, and a process flow of inputting a user name (including a process flow of locating a user name input box and a process flow of inputting a user name in a user name input box).
The determination process of the test script statement for implementing the sub-flow may be: and determining a target component set corresponding to the sub-flow in the test flow, and then taking a test script statement written for the target component of the target component set as the test script statement for realizing the sub-flow in the test flow. Wherein the target component set comprises target components required to operate to implement the functions of the sub-flow. For example, if the sub-process is used to enter a username, then the set of target components includes the target component of the username entry box. For another example, if the sub-process is used to enter a user name and a password, the target component set includes two target components, namely a user name entry box and a password entry box.
And after determining the test script statements for realizing the sub-flows, writing the determined test script statements into the test script according to the execution sequence of the sub-flows in the test flow. Through the processing, the sequence of each test script statement in the test script, namely the execution sequence of the corresponding sub-flow in the test flow.
Step S103: and executing the test script on the object to be tested to realize the automatic test of the object to be tested. And running a test script on the object to be tested to finish the automatic test.
The test script of the embodiment is suitable for developers and testers at the same time, so that the developers can use the test script to perform self-test in the development process, find problems in time, accurately position and correct the problems, ensure the high quality of codes and improve the development efficiency; and manual operation of testers can be reduced, and the testing efficiency is improved.
Example two
Fig. 2 is a schematic main flow chart of an automated testing method according to another embodiment of the present invention. As shown in fig. 2, the automated testing method according to the embodiment of the present invention mainly includes the following steps:
step S201: acquiring a component identifier of the target component, and compiling a test script statement according to the component identifier. As described in the first embodiment, the component identifier of the target component may be configured in advance, or a class name defined for the target component in the code of the object to be tested may be directly used as the component identifier. There are two ways in which the component identification may be obtained, as follows.
And if the component identification of the target component is the unique id, acquiring the component identification of the target component from the configuration file. And if the component identifier of the target component is the class name defined for the target component in the code of the object to be detected, acquiring the component identifier of the target component from the code.
And after the component identification is obtained, compiling a test script statement according to the component identification. The test script statement includes a component location statement and a component operation statement. The component positioning statement is used for positioning the position of the target component in the object to be measured according to the component identification of the target component. The component operation statement is used for realizing the operation indicated by the test flow at the position of the target component in the object to be tested. The operation is an operation which is determined to be required to be executed on the target component based on the test flow, and the operation can be clicking, inputting and the like.
Specifically, if the component identification of the target component is a unique id, the component location statement may be: last clicktext2 ═ await page $ ('# checktext 2'); where the const is a key used to define a constant, and the statement is used to locate a target component whose id is checktext 2. Accordingly, the component operation statements may be: wash clicktext2.click (); this statement is used to perform a click operation on a target component whose id is checktext 2.
If the component identifier of the target component is the class name defined for the target component in the code of the object to be detected, because the class name can be repeated and the target component cannot be uniquely determined, when writing a component positioning statement, the label of the target component needs to be searched, and the position of the target component in the object to be detected is positioned based on class and the label. Wherein the label is used to indicate the function of the target component.
For example, the class names of the two target components, namely the user name input box and the password input box, are inputlogin, the label of the user name input box is 'please input the user name', the label of the password input box is 'please input the password', the target component containing the label of 'please input the user name' and the class name of inputlogin is the user name input box, and the target component containing the label of 'please input the password' and the class name of inputlogin is the password input box.
Step S202: and determining a test script statement for realizing the sub-flow in the test flow. After the test script statements are written for the target component, the test script statements for implementing each sub-flow in the test flow are determined from the test script statements.
For convenience of illustration, in the embodiment, the sub-flow is the smallest flow unit of the test flow. Taking the test login function as an example, the test process comprises six sub-processes, namely a sub-process 1, a positioning user name input box, a sub-process 2, a user name input box, a sub-process 3, a positioning password input box, a sub-process 4, a password input box, a sub-process 5, a positioning login button, a sub-process 6 and a click login button.
When determining the test script statements corresponding to the six sub-flows, firstly determining target components required to be operated for realizing each sub-flow to form a target component set, and then taking the test script statements written for the target components of the target component set as the test script statements for realizing the sub-flows. Still taking the test login function as an example, the target components to be operated in the sub-processes 1 to 6 are a user name input box, a password input box, a login button and a login button in sequence. At this time, only one target component is in the target component set corresponding to each sub-process.
Suppose the id of the user name input box is nameInput, the id of the password input box is passdinput, the id of the login button is LoginBtn, the user name is zhang, and the password is 123456 (the specific values of the user name and the password can be obtained from the test case). The test script statement of sub-flow 1 is:
const inputinfo1=await page.$('#nameInput');
the test script statement of sub-flow 2 is:
await inputinfo1.type ("zhangsan");
the test script statement of sub-flow 3 is:
const inputinfo1=await page.$('#passwordInput');
the test script statement of sub-flow 4 is:
await inputinfo1.type("123456");
the test script statement of sub-flow 5 is:
const clickqueren1=await page.$('#LoginBtn');
the test script statement of sub-flow 6 is:
await clickqueren1.click();
step S203: and generating a unit test script according to the execution sequence of the sub-flows and the test script statements for realizing the sub-flows. Still taking the test login function as an example, the test flow is: firstly, positioning a target component with the id of nameInput, and inputting a text of Zhang III to the target component; then, positioning a target assembly with id of passwordInput, and inputting '123456' to the target assembly; and finally, positioning the target component with id being LoginBtn, and clicking the target component. Therefore, the six script statements are combined according to the execution sequence of the sub-flow, and the following unit test script is obtained:
const inputinfo1=await page.$('#nameInput');
await inputinfo1.type ("zhangsan");
const inputinfo1=await page.$('#passwordInput');
await inputinfo1.type("123456");
const clickqueren1=await page.$('#LoginBtn');
await clickqueren1.click();
step S204: judging whether the test type is a unit test or an integration test, and if the test type is the unit test, executing the step S205; if it is the integration test, step S206 is executed. The test types include unit test and integrated test, and can be carried in the test instruction. The test instructions are used to trigger execution of an automated test method.
Step S205: and executing the unit test script on the object to be tested to complete the automatic test. And for the test type of the unit test, executing a corresponding unit test script on the object to be tested.
Step S206: and packaging the plurality of unit test scripts to obtain an integrated test script. When each functional module to be tested is developed and integrated test is required, the unit test scripts corresponding to the developed functional modules can be packaged and combined to obtain the integrated test scripts. The package here is to introduce a method for referring to each unit test script in the script code of the integrated test script.
Step S207: and executing the integrated test script on the object to be tested to complete the automatic test. And for the test type of the integration test, executing a corresponding integration test script on the object to be tested.
In a preferred embodiment, the target component satisfying any one or more of the following waiting conditions may be timed to wait for a predicted time or to wait for the next component to be executed (i.e., the target component selected by the selector) to appear before proceeding with the operation. Wherein, the waiting condition is as follows: the loading time is greater than a set loading time threshold, the page rendering time is greater than a set rendering time threshold, and the result is returned by the interface when the operation indicated by the test flow is realized (namely, the operation can be executed only when the result returned by the back-end interface is waited).
In the embodiment, the waiting function is realized by adding a waiting statement between the component positioning statement and the component operating statement of the target component meeting the waiting condition. For example, the wait statement is awake page, wait ForSelector ('# userPhone', { visible: true }). This statement is used to wait for the presence of a component on the page whose id is userPhone.
The second embodiment can generate the unit test script and the integrated test script, so that developers can verify the updated part or the newly developed part through the unit test script when updating codes or developing new functions, and then verify whether the updated part or the newly developed part affects other functional modules of the system by using the integrated test script, thereby accurately positioning the bug, ensuring the high quality of the codes, avoiding finding problems when later-stage promotion is carried out, and further improving the development and test efficiency.
The first embodiment and the second embodiment realize the automatic test of the object to be tested, but do not show the test process and the test result. In order to facilitate positioning of problems by developers and feedback of problems by testers, screenshots can be taken on specified test nodes, test information is printed and output, and meanwhile, test reports can be output, so that the developers and the testers can conveniently check the test reports. See example three for details.
Fig. 3 is a main flow diagram of an automated testing method according to another embodiment of the present invention. As shown in fig. 3, the automated testing method of the embodiment of the present invention mainly includes the following steps:
step S301: acquiring a component identifier of the target component, and compiling a test script statement according to the component identifier. The specific implementation of this step is shown in step S201, which is not described herein again.
Step S302: and acquiring a screenshot script statement written for the set test node. And writing a screenshot script statement for the test node in advance. And the test nodes are abstracted according to the sub-processes and meet the set screenshot conditions. Screenshot conditions include interface return errors and/or page response exceptions. The page response exception here may be that the page is not responsive for more than a set time (e.g., 30 seconds).
Step S303: and determining a test script statement for realizing the sub-flow in the test flow. The specific implementation of this step is shown in step S202, which is not described herein again.
Step S304: and generating a unit test script according to the execution sequence of the sub-flows, the test script statement and the screenshot script statement for realizing the sub-flows. For a sub-process (corresponding to at least one test node) needing to be subjected to screenshot, generating an initial test script according to the execution sequence of the sub-process and a test script statement for realizing the sub-process; and then, inserting a screenshot script statement at the test node position of the initial test script to generate a final test script. The initial test script and the final test script generated here are both unit test scripts.
For the sub-flows which do not need to be subjected to screenshot, the unit test script is generated according to the execution sequence of the sub-flows and the test script statements for realizing the sub-flows. The specific implementation is shown in step S203, which is not described herein again.
Step S305: judging whether the test type is a unit test or an integration test, and if the test type is the unit test, executing a step S306; if it is the integration test, step S307 is executed. The specific implementation of this step is shown in step S204, which is not described herein again.
Step S306: the unit test script is executed on the object to be tested, and step S309 is executed. By executing the unit test script, the test information corresponding to the sub-flow needing to be subjected to screenshot can be stored to the specified position.
Step S307: and packaging the plurality of unit test scripts to obtain an integrated test script. The specific implementation of this step is shown in step S206, which is not described herein again.
Step S308: and executing the integrated test script on the object to be tested. By executing the integrated test script, the test information corresponding to the sub-process needing to be subjected to screenshot can be stored to the specified position.
Step S309: and printing the test information obtained in the process of executing the test script to a log file, and outputting a test report. In the embodiment, the test information obtained in the process of executing the test script is printed and output in the form of a log, stored locally and output as a test report.
According to the automatic testing method of the third embodiment, the problems of positioning of developers and the problems of feedback of testers are facilitated by storing screenshots, printing test logs and outputting test reports at the test nodes, so that the labor cost of manual report output of the testers is reduced, and the testing process is more standard.
FIG. 4 is a schematic diagram of the main modules of an automated test equipment according to an embodiment of the present invention. As shown in fig. 4, the automatic testing apparatus 400 according to the embodiment of the present invention mainly includes:
an obtaining module 401, configured to obtain a test script statement written for a target component. The target component is a component contained in the object to be measured. The test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly and realizing the operation indicated by the test flow at the position. The component identifier may be a unique id representing the target component, or may be a class name defined for the target component in the code of the object to be tested.
The object to be tested can be set in a self-defined manner, for example, the object to be tested can be an application to be tested, a functional module in the application, a minimum testable unit of the application, and the like. For the condition that the component identification is the unique id, the unique id needs to be configured for the target component in advance, the target component and the corresponding unique id are written into a configuration file, so that the unique id of the target component can be obtained from the configuration file, and then a test script statement is written according to the unique id. For the case that the component identification is a class name, the class name can be directly obtained from the written code, and then a test script statement is written according to the class name.
When writing a test script statement, the function and the operation flow of an application to be tested (i.e. the application to be tested is developed and completed) or an application under development need to be analyzed, a test case and a test flow are determined, and then the test script statement is written based on the test case and the test flow. After the test script statements are written, the test script statements are stored, and the test script statements can be directly obtained when a test is needed (for example, when a test instruction is received).
A generating module 402, configured to determine a test script statement for implementing a sub-process in the test flow, and generate a test script according to the execution sequence of the sub-process and the test script statement for implementing the sub-process. And determining a target component set corresponding to the sub-flow in the test flow, and then taking a test script statement written for the target component of the target component set as the test script statement for realizing the sub-flow in the test flow. Wherein the target component set comprises target components required to operate to implement the functions of the sub-flow.
And after determining the test script statements for realizing the sub-flows, writing the determined test script statements into the test script according to the execution sequence of the sub-flows in the test flow. Through the processing, the sequence of each test script statement in the test script, namely the execution sequence of the corresponding sub-flow in the test flow.
A testing module 403, configured to execute the testing script on the object to be tested, so as to implement an automated testing on the object to be tested. And running a test script on the object to be tested to finish the automatic test.
In addition, the automatic testing apparatus 400 according to the embodiment of the present invention may further include: a configuration module, a screenshot module, and an output module (not shown in FIG. 4). The configuration module is used for configuring a unique component identifier for the target component and writing the target component and the corresponding component identifier into a configuration file. And the screenshot module is used for acquiring screenshot script statements written for the set test nodes. And the output module is used for printing the test information obtained in the process of executing the test script to a log file.
It can be seen from the above description that, by acquiring the test script statements compiled based on the component identifiers, a test script applicable to developers and testers is generated, so that the position of the target component can be located through the component identifiers when the test script is executed, operations such as clicking and inputting are automatically realized, manual operation is not needed, problems can be found in time, and the development efficiency and the test efficiency are improved.
Fig. 5 illustrates an exemplary system architecture 500 to which the automated test method or automated test apparatus of embodiments of the invention may be applied.
As shown in fig. 5, the system architecture 500 may include terminal devices 501, 502, 503, a network 504, and a server 505. The network 504 serves to provide a medium for communication links between the terminal devices 501, 502, 503 and the server 505. Network 504 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 501, 502, 503 to interact with a server 505 over a network 504 to receive or send messages or the like. The terminal devices 501, 502, 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 505 may be a server that provides various services, such as a background management server that processes test instructions sent by an administrator using the terminal apparatuses 501, 502, 503. The background management server may obtain the test script statements, generate the test script, execute the test script, and feed back a processing result (e.g., a test result) to the terminal device.
It should be noted that the automated testing method provided in the embodiment of the present application is generally executed by the server 505, and accordingly, the automated testing apparatus is generally disposed in the server 505.
It should be understood that the number of terminal devices, networks, and servers in fig. 5 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The invention also provides an electronic device and a computer readable medium according to the embodiment of the invention.
The electronic device of the present invention includes: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors realize the automatic testing method of the embodiment of the invention.
The computer readable medium of the present invention has stored thereon a computer program which, when executed by a processor, implements an automated testing method of an embodiment of the present invention.
Referring now to FIG. 6, shown is a block diagram of a computer system 600 suitable for use with the electronic device implementing an embodiment of the present invention. The electronic device shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 6, the computer system 600 includes a Central Processing Unit (CPU)601 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage section 608 into a Random Access Memory (RAM) 603. In the RAM 603, various programs and data necessary for the operation of the computer system 600 are also stored. The CPU 601, ROM 602, and RAM 603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
The following components are connected to the I/O interface 605: an input portion 606 including a keyboard, a mouse, and the like; an output portion 607 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage section 608 including a hard disk and the like; and a communication section 609 including a network interface card such as a LAN card, a modem, or the like. The communication section 609 performs communication processing via a network such as the internet. The driver 610 is also connected to the I/O interface 605 as needed. A removable medium 611 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 610 as necessary, so that a computer program read out therefrom is mounted in the storage section 608 as necessary.
In particular, the processes described above with respect to the main step diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program containing program code for performing the method illustrated in the main step diagram. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 609, and/or installed from the removable medium 611. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 601.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present invention, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present invention may be implemented by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor includes an acquisition module, a generation module, and a testing module. The names of these modules do not in some cases constitute a limitation on the module itself, and for example, the acquiring module may also be described as a "module that acquires a test script statement written for a target component".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: acquiring a test script statement written for a target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly, and realizing the operation indicated by the test flow at the position; determining a test script statement for realizing a sub-flow in the test flow, and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow; and executing the test script on the object to be tested to realize the automatic test of the object to be tested.
According to the technical scheme of the embodiment of the invention, the test script which is suitable for developers and testers is generated by acquiring the test script statement compiled based on the component identifier, so that the position of the target component can be positioned through the component identifier when the test script is executed, the operations such as clicking, inputting and the like are automatically realized, manual operation is not needed, the problem can be found in time, and the development efficiency and the test efficiency are improved.
The product can execute the method provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in this embodiment, reference may be made to the method provided by the embodiment of the present invention.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (17)

1. An automated testing method, comprising:
acquiring a test script statement written for a target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly, and realizing the operation indicated by the test flow at the position;
determining a test script statement for realizing a sub-flow in the test flow, and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow;
and executing the test script on the object to be tested to realize the automatic test of the object to be tested.
2. The method of claim 1, wherein the test script comprises a unit test script and/or an integrated test script;
generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow, wherein the test script generation comprises the following steps:
writing a test script statement for realizing the sub-flow into the unit test script according to the execution sequence of the sub-flow; or
Writing a test script statement for realizing the sub-flow into the unit test script according to the execution sequence of the sub-flow;
and packaging a plurality of unit test scripts to obtain the integrated test script.
3. The method of claim 1, wherein determining a test script statement that implements a sub-flow of the test flow comprises:
determining a target component set corresponding to a sub-process in the test process;
and taking a test script statement written for the target component of the target component set as a test script statement for realizing the sub-flow in the test flow.
4. The method of claim 2, wherein said executing the test script on the object under test comprises:
if the test type is determined to be the unit test, executing the unit test script on the object to be tested;
and if the test type is determined to be the integration test, executing the integration test script on the object to be tested.
5. The method of claim 1, wherein the test script statements comprise component position statements and component operation statements; wherein the content of the first and second substances,
the component positioning statement is used for positioning the position of the target component on the object to be detected according to the component identification of the target component;
the component operation statement is used for realizing the operation indicated by the test flow at the position.
6. The method of claim 5, wherein for a target component belonging to a set of set wait components, the test script statement further comprises: a wait statement provided between the component locate statement and the component operate statement; wherein the wait statement is used for waiting for a set time or waiting for the target component selected by the selector to appear.
7. The method of claim 6, wherein the target component of the set of waiting components satisfies any one or more of the following waiting conditions:
and the loading time is greater than a set loading time threshold, the page rendering time is greater than a set rendering time threshold, and a result is returned by depending on an interface when the operation indicated by the test flow is realized.
8. The method of claim 1, wherein the component identifier is a class name corresponding to the target component;
the positioning the position of the target assembly on the object to be measured according to the assembly identifier of the target assembly comprises:
searching for a label of the target component; wherein the tag is to indicate a function of the target component;
and positioning the position of the target assembly on the object to be detected according to the class name and the label.
9. The method of claim 1, further comprising:
and configuring a unique component identifier for the target component, and writing the target component and the corresponding component identifier into a configuration file.
10. The method of claim 1, further comprising: acquiring a screenshot script statement written for a set test node;
generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow, wherein the generating comprises the following steps:
generating an initial test script according to the execution sequence of the sub-flows and the test script statements for realizing the sub-flows;
and inserting the screenshot script statement at the test node position of the initial test script to generate a final test script.
11. The method according to claim 10, wherein the test node is a node abstracted from the sub-process and satisfying a set screenshot condition.
12. The method of claim 11, wherein the screenshot conditions include an interface return error and/or a page response exception.
13. The method according to any of claims 1-12, wherein after the step of executing the test script on the object under test, the method further comprises:
and printing the test information obtained in the process of executing the test script to a log file.
14. An automated testing apparatus, comprising:
the acquisition module is used for acquiring a test script statement written for the target component; the test script statement is used for positioning the position of the target assembly in the object to be tested according to the assembly identification of the target assembly, and realizing the operation indicated by the test flow at the position;
the generating module is used for determining a test script statement for realizing a sub-flow in the test flow and generating a test script according to the execution sequence of the sub-flow and the test script statement for realizing the sub-flow;
and the test module is used for executing the test script on the object to be tested to realize the automatic test of the object to be tested.
15. The apparatus of claim 14, wherein the test script comprises a unit test script and/or an integrated test script;
the generating module is further configured to write a test script statement for implementing the sub-flow into the unit test script according to the execution sequence of the sub-flow; or
Writing a test script statement for realizing the sub-flow into the unit test script according to the execution sequence of the sub-flow;
and packaging a plurality of unit test scripts to obtain the integrated test script.
16. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-13.
17. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-13.
CN202110260174.1A 2021-03-10 2021-03-10 Automatic testing method and device Pending CN112988578A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110260174.1A CN112988578A (en) 2021-03-10 2021-03-10 Automatic testing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110260174.1A CN112988578A (en) 2021-03-10 2021-03-10 Automatic testing method and device

Publications (1)

Publication Number Publication Date
CN112988578A true CN112988578A (en) 2021-06-18

Family

ID=76334674

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110260174.1A Pending CN112988578A (en) 2021-03-10 2021-03-10 Automatic testing method and device

Country Status (1)

Country Link
CN (1) CN112988578A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113468076A (en) * 2021-08-19 2021-10-01 平安普惠企业管理有限公司 Application program exception testing method, device, equipment and storage medium
CN115170062A (en) * 2022-06-22 2022-10-11 壹沓科技(上海)有限公司 Automatic process development method, device and equipment

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113468076A (en) * 2021-08-19 2021-10-01 平安普惠企业管理有限公司 Application program exception testing method, device, equipment and storage medium
CN115170062A (en) * 2022-06-22 2022-10-11 壹沓科技(上海)有限公司 Automatic process development method, device and equipment

Similar Documents

Publication Publication Date Title
US9983984B2 (en) Automated modularization of graphical user interface test cases
US11157390B2 (en) Automatic software defect repair
US20150026664A1 (en) Method and system for automated test case selection
CN110674047B (en) Software testing method and device and electronic equipment
CN106557878B (en) Development project management method and device
CN109614325B (en) Method and device for determining control attribute, electronic equipment and storage medium
CN112241360A (en) Test case generation method, device, equipment and storage medium
CN103180834A (en) An automated operating system test framework
CN112988578A (en) Automatic testing method and device
US11422917B2 (en) Deriving software application dependency trees for white-box testing
CN112988588B (en) Client software debugging method and device, storage medium and electronic equipment
CN113138937A (en) Test method and device
CN111240987A (en) Migration program detection method and device, electronic equipment and computer readable storage medium
CN108885574B (en) System for monitoring and reporting performance and correctness issues at design, compilation, and runtime
Agarwal et al. Copilot Evaluation Harness: Evaluating LLM-Guided Software Programming
CN110609786A (en) Software testing method and device, computer equipment and storage medium
Ben Charrada et al. An automated hint generation approach for supporting the evolution of requirements specifications
CN113377648A (en) Software system diagnosis method and device, electronic equipment and computer readable medium
CN113626307A (en) Data verification method and device based on K8S container platform
CN111176718A (en) Script online method and device, storage medium and electronic equipment
CN111258910B (en) Static link library function verification method and device, electronic equipment and storage medium
CN114116499A (en) Method, device, equipment and storage medium for evaluating code quality
CN117632710A (en) Method, device, equipment and storage medium for generating test code
CN116339742A (en) Method, device and storage medium for acquiring function
CN115686479A (en) File creation method and related device

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