A test script generation method, device and equipment and storage medium
By monitoring the execution of input devices, test scripts are automatically generated, solving the problem of low efficiency in manually writing test scripts by testers and achieving efficient test script generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- ZHONGKE FANGDE SOFTWARE CO LTD
- Filing Date
- 2022-10-20
- Publication Date
- 2026-04-21
AI Technical Summary
The process of testers manually writing test scripts is cumbersome, resulting in low efficiency in software testing.
By monitoring the execution operations of input devices, test data is obtained, and test scripts are automatically generated using preset functions and script execution dependency statements, including locating and assigning values to parameter variables of operation functions, and generating execution statements.
It enables automated generation of test scripts, improving the efficiency of test script generation and reducing human error.
Smart Images

Figure CN115543831B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of testing technology, specifically to a test script generation method, apparatus, device, and storage medium. Background Technology
[0002] Software testing is a crucial process for testers to assess software performance. Testers design test suites based on the software's functionality and then conduct tests to confirm that the software functions correctly.
[0003] Currently, testers need to write test scripts based on the test requirements. The software is then tested by running the test scripts. However, the process of writing test scripts is quite cumbersome, leading to low efficiency in software testing. Summary of the Invention
[0004] In view of this, this application provides a test script generation method, apparatus, device, and storage medium, which can improve the efficiency of test script generation.
[0005] To solve the above problems, the technical solution provided in this application is as follows:
[0006] Firstly, this application provides a method for generating test scripts, the method comprising:
[0007] In response to a trigger operation of the recording button, the system monitors the execution operation performed by the input device on the target software and acquires test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order of each sub-operation in the execution operation.
[0008] Obtain script execution dependency statements; the script execution dependency statements are used to define preset functions and the parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, and the operation functions include action variables;
[0009] The test data is analyzed to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters.
[0010] Using the operation parameter values of each sub-operation, the parameter variables included in the preset function are assigned values respectively to obtain the execution statement of each sub-operation;
[0011] A test script is generated based on the script execution dependency statements and the execution statements of each of the sub-operations. The execution order of the execution statements of each of the sub-operations is determined according to the execution order among the sub-operations in the test data.
[0012] In one possible implementation, the test data is recorded in a first data table, each row of test data in the first data table corresponds to a sub-operation, and the order of the test data in each row of the first data table corresponds to the execution order between the sub-operations.
[0013] The process of parsing the test data to obtain the operation parameter values for each sub-operation includes:
[0014] The test data included in the first data table is parsed row by row. The operation parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data, so as to obtain the first operation parameter table.
[0015] Each row of data in the first operation parameter table corresponds to a sub-operation, and each row of data includes the action parameter value and position parameter value of the sub-operation; the row order of each row of data in the first operation parameter list corresponds to the execution order between the sub-operations.
[0016] In one possible implementation, the step of assigning values to the parameter variables included in the preset function using the operation parameter values of each sub-operation to obtain the execution statement for each sub-operation includes:
[0017] The action statement of the sub-operation corresponding to the first target data is obtained by assigning the action parameter value of the sub-operation to the action variable of the operation function using the action parameter value of the sub-operation included in the first target data. The action statement is composed of the operation function including the assigned action variable. The first target data is a row of data included in the first operation parameter table.
[0018] By using the position parameter values of the sub-operations included in the first target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the first target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0019] In one possible implementation, the test data further includes the execution interval between two sub-operations with adjacent execution order; the preset function further includes an interval duration function, which includes a duration variable; the operation parameters further include an execution interval parameter; the test data is recorded in a second data table, where each row of test data in the second data table corresponds to a sub-operation, and the order of the rows of test data in the second data table corresponds to the execution order between the sub-operations;
[0020] The process of parsing the test data to obtain the operation parameter values for each sub-operation includes:
[0021] The test data included in the second data table is parsed row by row. The operation parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data. The execution interval between two sub-operations with adjacent execution order is used as the execution interval parameter value of the sub-operation to obtain the second operation parameter table.
[0022] The second operation parameter table includes a row of data corresponding to a sub-operation. Each row of data includes the action parameter value, position parameter value, and execution interval parameter value of the sub-operation. The execution interval parameter value is used to indicate the execution interval between the sub-operation and the next sub-operation adjacent to the execution sequence. The row order of each row of data in the second operation parameter table corresponds to the execution order between the sub-operations.
[0023] In one possible implementation, the step of assigning values to the parameter variables included in the preset function using the operation parameter values of each sub-operation to obtain the execution statement for each sub-operation includes:
[0024] The action parameter values of the sub-operations included in the second target data are used to assign values to the action variables of the operation function to obtain the action statement of the sub-operation corresponding to the second target data. The action statement is composed of an operation function including the assigned action variable. The second target data is a row of data included in the second operation parameter table.
[0025] By using the position parameter values of the sub-operations included in the second target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the second target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0026] The execution interval statement for the sub-operation included in the second target data is obtained by assigning the execution interval parameter value of the sub-operation included in the interval duration function to the interval duration function. The execution interval statement is composed of the interval duration function including the assigned duration variable.
[0027] In one possible implementation, the preset function further includes a screenshot function, which includes a storage location variable; the execution statement of each sub-operation also includes a screenshot statement;
[0028] Before generating the test script by executing the dependency statements and the execution statements of each of the sub-operations according to the script, the method further includes:
[0029] The target storage location of each sub-operation is used to assign a value to the storage location variable of the screenshot function, thereby obtaining the screenshot statement for each sub-operation. The target storage location is used to store the screenshot image obtained by executing the sub-operation. The screenshot statement is composed of a screenshot function that includes the assigned storage location variable.
[0030] In one possible implementation, the image name of the screenshot image for each sub-operation is determined according to the execution order of the sub-operations; the image name of the standard image for each sub-operation is the same as the image name of the screenshot image for the sub-operation; the standard image for each sub-operation is stored in the target storage location of the sub-operation; the preset function further includes a comparison function, the comparison function including a path variable; and the method further includes:
[0031] The target storage location of each sub-operation is assigned to the image path to obtain the comparison statement;
[0032] The step of generating a test script based on the script execution dependency statements and the execution statements of each of the sub-operations includes:
[0033] A test script is generated based on the script execution dependency statements, the execution statements of each of the sub-operations, and the comparison statements, wherein the execution order of the comparison statements is later than the execution order of the execution statements of each of the sub-operations.
[0034] Secondly, this application provides a test script generation apparatus, the apparatus comprising:
[0035] The first acquisition unit is configured to, in response to a trigger operation on the recording button, monitor the execution operation performed by the input device on the target software and acquire test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order between each sub-operation in the execution operation;
[0036] The second acquisition unit is used to acquire script execution dependency statements; the script execution dependency statements are used to define preset functions and parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, and the operation functions include action variables;
[0037] A parsing unit is used to parse the test data to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters.
[0038] The first assignment unit is used to assign values to the parameter variables included in the preset function using the operation parameter values of each sub-operation, so as to obtain the execution statement of each sub-operation;
[0039] The generation unit is used to generate a test script based on the script execution dependency statements and the execution statements of each of the sub-operations, wherein the execution order of the execution statements of each of the sub-operations is determined according to the execution order among the sub-operations in the test data.
[0040] In one possible implementation, the test data is recorded in a first data table, each row of test data in the first data table corresponds to a sub-operation, and the order of the test data in each row of the first data table corresponds to the execution order between the sub-operations.
[0041] The parsing unit is used to parse the test data included in the first data table row by row sequentially, determine the action parameter value corresponding to the operation parameter of the sub-operation based on the operation object and operation action type of the sub-operation corresponding to each row of test data, and determine the position parameter value corresponding to the operation parameter of the sub-operation based on the operation position of the sub-operation corresponding to each row of test data, thereby obtaining a first operation parameter table; each row of data in the first operation parameter table corresponds to a sub-operation, and each row of data includes the action parameter value and position parameter value of the sub-operation; the row order of each row of data in the first operation parameter list corresponds to the execution order between the various sub-operations.
[0042] In one possible implementation, the first assignment unit is used to assign values to the action variables of the operation function using the action parameter values of the sub-operations included in the first target data, thereby obtaining the action statement of the sub-operation corresponding to the first target data. The action statement is composed of an operation function including the assigned action variables. The first target data is a row of data included in the first operation parameter table.
[0043] By using the position parameter values of the sub-operations included in the first target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the first target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0044] In one possible implementation, the test data further includes the execution interval between two sub-operations with adjacent execution order; the preset function further includes an interval duration function, which includes a duration variable; the operation parameters further include an execution interval parameter; the test data is recorded in a second data table, where each row of test data in the second data table corresponds to a sub-operation, and the order of the rows of test data in the second data table corresponds to the execution order between the sub-operations;
[0045] The parsing unit is used to parse the test data included in the second data table row by row in sequence, determine the action parameter value corresponding to the operation parameter of the sub-operation according to the operation object and operation action type of the sub-operation corresponding to each row of test data, determine the position parameter value corresponding to the operation parameter of the sub-operation according to the operation position of the sub-operation corresponding to each row of test data, and take the execution interval time between two sub-operations with adjacent execution order as the execution interval parameter value of the sub-operation to obtain the second operation parameter table;
[0046] The second operation parameter table includes a row of data corresponding to a sub-operation. Each row of data includes the action parameter value, position parameter value, and execution interval parameter value of the sub-operation. The execution interval parameter value is used to indicate the execution interval between the sub-operation and the next sub-operation adjacent to the execution sequence. The row order of each row of data in the second operation parameter table corresponds to the execution order between the sub-operations.
[0047] In one possible implementation, the first assignment unit is used to assign values to the action variables of the operation function using the action parameter values of the sub-operations included in the second target data, thereby obtaining the action statement of the sub-operation corresponding to the second target data. The action statement is composed of an operation function including the assigned action variables. The second target data is a row of data included in the second operation parameter table.
[0048] By using the position parameter values of the sub-operations included in the second target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the second target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0049] The execution interval statement for the sub-operation included in the second target data is obtained by assigning the execution interval parameter value of the sub-operation included in the interval duration function to the interval duration function. The execution interval statement is composed of the interval duration function including the assigned duration variable.
[0050] In one possible implementation, the preset function further includes a screenshot function, which includes a storage location variable; the execution statement of each sub-operation also includes a screenshot statement;
[0051] The device further includes:
[0052] The second assignment unit is used to assign values to the storage location variables of the screenshot function using the target storage locations of each sub-operation, thereby obtaining the screenshot statement for each sub-operation. The target storage location is used to store the screenshot image obtained by executing the sub-operation, and the screenshot statement is composed of a screenshot function including the assigned storage location variables.
[0053] In one possible implementation, the image name of the screenshot image for each sub-operation is determined according to the execution order of the sub-operations; the image name of the standard image for each sub-operation is the same as the image name of the screenshot image for the sub-operation; the standard image for each sub-operation is stored in the target storage location of the sub-operation; the preset function further includes a comparison function, the comparison function including a path variable; and the device further includes:
[0054] The third assignment unit is used to assign the target storage location of each of the sub-operations to the image path to obtain the comparison statement;
[0055] The generation unit is used to generate a test script based on the script execution dependency statement, the execution statement of each of the sub-operations, and the comparison statement, wherein the execution order of the comparison statement is later than the execution order of the execution statement of each of the sub-operations.
[0056] Thirdly, this application provides a test script generation device, comprising: a processor, a memory, and a system bus; the processor and the memory are connected via the system bus;
[0057] The memory is used to store one or more programs, the one or more programs including instructions that, when executed by the processor, cause the processor to perform the test script generation method described in the first aspect and any possible implementation thereof.
[0058] Fourthly, this application provides a computer-readable storage medium, characterized in that the computer-readable storage medium stores instructions that, when executed on a terminal device, cause the terminal device to execute the test script generation method described in the first aspect and any possible implementation thereof.
[0059] Therefore, this application has the following beneficial effects:
[0060] This application provides a test script generation method, apparatus, device, and storage medium. The method, in response to a trigger operation of a recorded button, monitors the execution operations performed by an input device on target software, and acquires test data corresponding to the execution operations. Each execution operation includes at least one sub-operation. The test data includes the operation object, operation action type, operation position, and execution order of each sub-operation. The method also acquires script execution dependency statements, which define the functions and variables required to execute the script. The test data is parsed to obtain the operation parameter values for each sub-operation, including action parameters and operation position parameters. Using the operation parameter values of each sub-operation, the parameter variables of a preset function are assigned values to obtain the execution statement for each sub-operation. Based on the script execution dependency statements and the execution statements of each sub-operation, a test script including the script dependency statements and the execution statements for each sub-operation is generated. Thus, based on the acquired test data corresponding to the execution operations of the input device, the test data can be parsed, and the execution statements for each sub-operation can be automatically generated based on the script execution dependency statements. Furthermore, it can generate test scripts based on the script's execution dependencies and the execution statements of each sub-operation, thus automatically generating test scripts without requiring testers to manually write them, thereby improving the efficiency of test script generation. Attached Figure Description
[0061] Figure 1 A schematic diagram illustrating an exemplary application scenario of a test script generation method provided in this application embodiment;
[0062] Figure 2 A flowchart illustrating a test script generation method provided in an embodiment of this application;
[0063] Figure 3 A schematic diagram of a test software display interface provided in an embodiment of this application;
[0064] Figure 4 A schematic diagram of a confirmation window for testing software provided in an embodiment of this application;
[0065] Figure 5 A schematic diagram of a test script provided in an embodiment of this application;
[0066] Figure 6 A schematic diagram of a result display page provided in an embodiment of this application;
[0067] Figure 7 This is a schematic diagram of the structure of a test script generation device provided in an embodiment of this application;
[0068] Figure 8A block diagram of a device for generating test scripts provided in an embodiment of this application. Detailed Implementation
[0069] To facilitate understanding and explanation of the technical solutions provided in the embodiments of this application, the background technology of this application will be described first.
[0070] In the process of managing software, testers need to test the software's functionality and maintain any issues discovered during testing. Testers manually write test scripts for each software function. By running these test scripts, testers can test the software's functionality. However, manually writing test scripts is time-consuming, prone to errors, and inefficient.
[0071] Based on this, this application provides a test script generation method, apparatus, device, and storage medium. The method, in response to a trigger operation on a recording button, monitors the execution operation performed by an input device on target software, and acquires test data corresponding to the execution operation. The execution operation includes at least one sub-operation. The test data includes the operation object, operation action type, operation position, and execution order of each sub-operation. The method also acquires script execution dependency statements, which define the functions and variables required to execute the script. The method parses the test data to obtain the operation parameter values for each sub-operation, including action parameters and position parameters. Using the operation parameter values of each sub-operation, the method assigns values to the parameter variables included in a preset function to obtain the execution statement for each sub-operation. Finally, based on the script execution dependency statements and the execution statements for each sub-operation, a test script including the script dependency statements and the execution statements for each sub-operation is generated. Thus, based on the acquired test data corresponding to the execution operation of the input device, the test data can be parsed, and the execution statements for each sub-operation can be automatically generated based on the script execution dependency statements. Furthermore, it can generate test scripts based on the script's execution dependencies and the execution statements of each sub-operation, thus automatically generating test scripts without requiring testers to manually write them, thereby improving the efficiency of test script generation.
[0072] Let's combine the following... Figure 1 The application scenarios of the test script generation method provided in the embodiments of this application are described. Among them, Figure 1 This is a schematic diagram illustrating an exemplary application scenario of a test script generation method provided in this application. The test script generation method provided in this application can be applied to test software.
[0073] In practical applications, testers run the test software. The tester triggers the record button displayed on the test software interface and begins executing operations on the target software using the input device. The test software responds to the record button trigger by acquiring the test data generated by the execution operations performed on the target software via the input device. The test software then obtains the script execution dependency statements, which are statements that the script depends on, used to define preset functions and their included parameter variables. These script execution dependency statements can be pre-set in the device running the test software for easy access. The test software parses the obtained test data to obtain the operation parameters for each sub-operation. These operation parameters are used to assign values to the parameter variables of the preset functions. Using the operation parameters for each sub-operation, values are assigned to the parameter variables included in the preset functions, resulting in the execution statement for each sub-operation. Finally, a test script is generated based on the script execution dependency statements and the execution statements for each sub-operation. The target software can read and run the test script, reproducing the execution operations and achieving automated testing of the target software. In addition, it can send test scripts to other devices that have the target software and test software installed, and run the test scripts on other devices to test the target software.
[0074] Those skilled in the art will understand that Figure 1 The schematic diagram shown is merely one example in which the embodiments of this application can be implemented. The scope of application of the embodiments of this application is not limited by any aspect of this framework.
[0075] To facilitate understanding of the technical solutions provided in the embodiments of this application, the test script generation method provided in the embodiments of this application will be described below with reference to the accompanying drawings.
[0076] First, it should be noted that the test script generation method provided in this application can be applied to test software. The test software is used to test software. In some possible implementations, the test software can be applied to a computer. This application does not limit the operating environment to which the test software is applicable. As an example, the test software can be test software suitable for Linux (an operating system).
[0077] See Figure 2 As shown, this figure is a flowchart illustrating a test script generation method provided in an embodiment of this application. Figure 2 As shown, the method may include S201-S205.
[0078] S201: In response to a trigger operation on the recording button, listen to the execution operation performed by the input device on the target software, and obtain test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order between each sub-operation in the execution operation.
[0079] The record button is used to trigger listening to the execution operations performed by the input device on the target software. This application does not limit the specific implementation of the triggering operation for the record button. In one possible implementation, the display interface of the test software includes the record button. As an example, the display interface of the test software can be found here. Figure 3 As shown, the test software's display interface includes a "Start Recording" button. Testers can trigger the recording function by clicking the "Start Recording" button. In another possible implementation, testers can trigger the recording function using a shortcut key.
[0080] In response to the trigger operation of the recording button, the testing software begins to listen to the execution operations performed by the input device on the target software and obtains the test data of the execution operations.
[0081] The target software is the software that needs to be tested. Input devices are devices connected to the computer and used to control the computer. Input devices may include, but are not limited to, one or more of a mouse, keyboard, and touch input devices. The operations performed can be determined by the testers based on the functions of the target software that need to be tested.
[0082] In some possible implementations, testers can retrieve recorded data, such as test cases, including execution operations by querying, and control the input device to perform operations against the target software by referring to this recorded data. In the embodiments of this application, test cases are used to describe the recorded data. In other embodiments of this application, no specific limitation is made to the recorded data including execution operations. A test case can refer to a description of a testing task for a specific software product, and its content may include the test object, test environment, input data, test steps, expected results, test scripts, etc. Each target software can correspond to multiple test cases, and each test case has a unique test case number.
[0083] See Figure 3As shown, the test software's display interface can also include input boxes for the software name and test case number. Before triggering the record button, testers can enter the target software name in the software name input box and the test case number for this test in the test case number input box. The software name identifies the target software, and the test case number identifies the test case used in this test. Based on the software name and test case number, the test software can query the test cases corresponding to those names. These test cases indicate the specific content of the operation to be performed, such as the sub-operations, the target object, action type, and location of each sub-operation, and the execution order between sub-operations. The correspondence between the software name, test case number, and test case can be pre-established and stored in a test case library. Based on the test cases, testers can easily determine the specific content of the execution operations corresponding to the functions of the target software to be tested and perform functional tests on the target software. Furthermore, using test cases as a reference standard for execution operations ensures that the determined execution operations are relatively accurate when the target software is tested multiple times, and also facilitates the testers in organizing the testing process of the target software.
[0084] It should be noted that the embodiments of this application do not limit the specific implementation method of the input device performing execution operations on the target software. In one possible implementation, the input device can be controlled to automatically perform execution operations on the target software based on a pre-written script or instructions. In another possible implementation, the input device can be controlled by a tester to perform the execution operation on the target software.
[0085] An execution operation includes at least one sub-operation. A sub-operation is the smallest unit of operation included in an execution operation. Each sub-operation corresponds to an action. For example, an execution operation includes clicking the left mouse button at position A, entering content at position B, and clicking the left mouse button at position C. The three sub-operations included in this execution operation are: {Sub-operation 1: Click the left mouse button at position A}, {Sub-operation 2: Enter content at position B}, and {Sub-operation 3: Click the left mouse button at position C}. It can be seen that an execution operation can include the target object, action type, and position of each sub-operation. When the number of sub-operations included in an execution operation is greater than one, the execution operation also needs to include the execution order of the sub-operations. Furthermore, when the number of sub-operations included in an execution operation is greater than one, the execution operation can also include the execution interval between the sub-operations. For example, after executing {Sub-operation 1: Click the left mouse button at position A}, {Sub-operation 2: Enter content at position B} is executed after a 3-second interval.
[0086] The testing software monitors the operations performed by input devices on the target software and acquires the corresponding test data. As an example, the testing software starts a corresponding number of threads based on the number of input devices to monitor the operations performed by each input device. For example, input devices include a mouse and a keyboard. In response to a trigger operation for recording keystrokes, the testing software starts two threads to monitor the mouse and keyboard operations respectively, and acquires the test data generated based on the mouse and keyboard operations.
[0087] This application does not limit the specific implementation method for acquiring test data. In one possible implementation, test data corresponding to the executed operation can be acquired in real time during the monitoring process. In another possible implementation, test data can be acquired after the execution operation is determined to be completed. As an example, the testing software can determine the end of the execution operation based on the monitored end operation. This application does not limit the specific implementation method for triggering the end operation. For example, the testing software can display an end button in a specific area of the screen. The tester can trigger the end operation by triggering the end button. As another example, the tester can trigger the end operation by triggering a pre-set shortcut key for the end button.
[0088] In this embodiment, the testing software can acquire test data corresponding to the execution operations performed by the input device on the target software based on monitoring of the input device. This test data can be used to enable the testing software to automatically execute test operations on the target software. The test data includes the operation object, operation action type, and operation position of each sub-operation in the execution operation; the test data also includes the execution order between the sub-operations. The operation action type refers to the type of operation action of the sub-operation. The operation action type is related to the device type of the input device. For example, if the input device includes a mouse, the operation action type can include triggering / clicking / double-clicking the left mouse button, triggering / clicking / double-clicking the right mouse button, scrolling up / down the mouse wheel, etc.; if the input device includes a keyboard, the operation action type can include keyboard input, etc.; if the input device includes a touch input device, the operation action type can include touch click, press trigger, etc.
[0089] As an example, the operation is {Sub-operation 1: Click the left mouse button at position A; Sub-operation 2: Input XX at position B}. This operation includes two sub-operations; sub-operation 1 operates on the mouse, the action type is clicking the left mouse button, and the operation position is position A; sub-operation 2 operates on the keyboard, the action type is inputting XX, and the operation position is position B; the execution order of the sub-operations is: sub-operation 1 is executed first, then sub-operation 2 is executed.
[0090] The operation position refers to the location where a sub-operation is performed on an object. In one possible implementation, the operation position can be represented using screen coordinates. It's important to note that, taking a computer screen as an example, the top-left corner of the screen is the origin, the horizontal direction to the right is the positive x-axis, and the vertical direction downwards is the positive y-axis. One pixel is the unit length. The coordinate values range from the maximum value of the computer screen's resolution. Taking the sub-operation {clicking the left mouse button at position A} as an example, the operation position of the sub-operation is the coordinate of position A in the screen coordinate system.
[0091] It should be noted that, in one possible implementation, the testing software may display a confirmation window in response to a recording button press. See also Figure 4 As shown in the figure, this is a schematic diagram of a confirmation window provided in an embodiment of this application. The confirmation window may include a confirmation button and confirmation content. The confirmation content is used to prompt the tester to confirm the start of recording by pressing the confirmation button. After confirming the start of recording, the tester clicks the confirmation button in the confirmation window. In response to the confirmation button triggering operation, the test software starts listening to the execution operation performed by the input device on the target software and obtains the test data corresponding to the execution operation. In addition, the confirmation window may also include a cancel button. The confirmation content is also used to prompt the tester to choose not to start recording by triggering the cancel button. By displaying the confirmation window, the tester is prompted to start obtaining the test data corresponding to the execution operation, which can avoid the tester accidentally triggering the record button and obtaining invalid test data, thus making the obtained test data more accurate.
[0092] In some possible implementations, in response to a recording button press, the testing software automatically creates a data file in a preset directory under a preset target path, storing the acquired test data in this data file. The filename of the data file can be determined based on the software name and test case number of the target software. The data file storing the test data can be a CSV (Comma-Separated Values) format file. For example, if the tester enters the software name "mspaint" and the test case number "mspa001" in the testing software's display interface, in response to a recording button press, the testing software will automatically create a folder [mspaint] corresponding to the software name, and within the [mspaint] folder, a test data directory [mspa001] corresponding to the test case number, to store the acquired test data. Simultaneously, it will also create a log directory and a replay_data directory; the log directory stores software operation logs, and the replay_data directory stores data corresponding to subsequent playback operations.
[0093] Furthermore, after acquiring the test data, the testing software can display the test data on the display interface for testers to view. This application does not limit the method of displaying test data. As one example, the test software's display interface includes an area for displaying test data. As another example, after generating test data, a pop-up window is generated to display the test data. Based on the displayed test data, testers can verify whether the test data matches the required test operations, ensuring that the test operations meet the testing needs of the target software.
[0094] S202: Obtain script execution dependency statements; the script execution dependency statements are used to define preset functions and the parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, and the operation functions include action variables.
[0095] Script execution dependency statements are statements upon which the script is executed. Script execution dependency statements can include one or more statements. Script execution dependency statements are used to define the preset functions involved in generating the script and the parameter variables of these preset functions. In this embodiment, the test data corresponding to the executed operation includes operation information in two aspects: operation action type and operation location. The preset functions include a positioning function and an operation function. The positioning function includes a position variable, which is used to determine the operation location of the executed operation. The operation function includes an action variable, which is used to determine the operation action type of the executed operation.
[0096] In one possible implementation, script execution dependencies are stored as dependency packages on the device that needs to run the script. Testers can pre-store the dependency packages containing the script execution dependencies in a preset storage location, allowing the test software to read the script execution dependencies from the preset storage location. It should be noted that this application does not limit the triggering method for obtaining script execution dependencies. In one possible implementation, after obtaining the test data corresponding to the execution operation, the generation of a test script based on the test data is automatically triggered; after obtaining the test data corresponding to the execution operation, the script execution dependencies are automatically obtained so that the test script can be subsequently generated based on the script execution dependencies and the test data. In another possible implementation, the generation of the test script based on the test data is triggered by the tester. Figure 4 For example, the test software's display interface includes a "Generate Script" button. Testers can trigger the generation of test scripts based on test data by clicking the "Generate Script" button. After the tester triggers the "Generate Script" button, the test software will automatically obtain the script's execution dependencies.
[0097] S203: Parse the test data to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters.
[0098] After obtaining the script execution dependencies, you need to assign values to the parameter variables of the preset functions defined in the script execution dependencies. Specifically, you need to assign values to the position variables of the positioning function and the action variables of the operation function.
[0099] The test data corresponding to the executed operations is parsed. Based on the operation parameter values of each sub-operation included in the test data, values are assigned to the location functions and variables included in the operation functions of the script execution dependency statements.
[0100] In one possible implementation, for step S203: parsing the test data to obtain the operation parameter value of each sub-operation, this application provides two specific implementation methods, which are described below.
[0101] S204: Using the operation parameter values of each sub-operation, assign values to the parameter variables included in the preset function to obtain the execution statement of each sub-operation.
[0102] After obtaining the operation parameter values for each sub-operation, these operation parameter values are used to assign values to the parameter variables included in the preset function. Specifically, for each sub-operation included in the execution operation, the action parameter values included in the sub-operation's operation parameter values are assigned values to the action variables included in the operation function of the preset function, and the position parameter values included in the sub-operation's operation parameter values are assigned values to the position variables included in the positioning function of the preset function. Based on the obtained preset function with the assigned values, the corresponding execution statement for that sub-operation is generated. Running the execution statement for each sub-operation in the execution operation can reconstruct the execution process for each sub-operation, realizing the automatic execution of the execution operation for the target software.
[0103] It should be noted that, in this embodiment, the execution statement of a sub-operation may include multiple statements with different functions. In one possible implementation, the execution statement of a sub-operation includes an action statement and a position statement. The action statement is used to perform the operation action of the sub-operation. The position statement is used to determine the operation position of the sub-operation. Regarding step S204: using the operation parameter value of each sub-operation to assign values to the parameter variables included in the preset function to obtain the execution statement of each sub-operation, this embodiment provides a specific implementation method, please refer to the following.
[0104] S205: Generate a test script based on the script execution dependency statements and the execution statements of each of the sub-operations, wherein the execution order of the execution statements of each of the sub-operations is determined according to the execution order of each sub-operation in the test data.
[0105] The test script includes script execution dependencies and execution statements for each sub-operation. The execution statements for each sub-operation depend on the script execution dependencies. The test script can contain multiple lines of statements. The test script has a fixed number of lines containing script execution dependencies. See, as an example... Figure 5 As shown in the figure, this is a schematic diagram of a test script provided in an embodiment of this application. Lines 1 to 12 of the test script are script execution dependency statements.
[0106] The execution order of the sub-operations within the test script is determined by the execution order of the sub-operations in the test data. In one possible implementation, the execution statements are executed line by line according to their line numbers in the test script. Based on the execution order of the sub-operations in the test data, the execution statements of each sub-operation are written into the test script line by line until the execution statement of the last sub-operation is included, resulting in a complete test script.
[0107] After the test script is generated, a notification window will be displayed. This window shows a message indicating that the test script generation is complete. For example, the message might read "Script generated." By viewing this notification window, testers can quickly understand the progress of the test script generation, facilitating subsequent processing. The generated test script can be stored in a preset location for testers to access or for the test software to use.
[0108] Taking the aforementioned embodiment as an example, the tester inputs the software name "mspaint" and the test case number "mspa001" in the test software's display interface. In response to the trigger operation of the record button, the test software automatically creates a folder named "[mspaint]" corresponding to the software name, and within the "[mspaint]" folder, creates a test data directory named "[mspa001]" corresponding to the test case number, to store the acquired test data. Based on this, the test software automatically creates a folder named "[mspa001]" within the "[mspaint]" folder to store the test scripts generated based on the test data. The test script can be named "mspa001.py".
[0109] The test script generation method provided in this application can automatically generate test scripts for reproducing the execution of a given operation based on test data from manually executed operations and script execution dependencies. This eliminates the need for testers to manually write test scripts, improving efficiency and reducing labor costs. Furthermore, running the generated test scripts enables automated testing of the target software, improving testing efficiency and allowing for rapid batch testing of regression tests or tedious, repetitive tasks. In addition, the generated test scripts can be applied to other operating environments and compatible systems or devices, facilitating the testing of target software.
[0110] In some possible implementations, the test data corresponding to the acquired execution operations can be stored in a data table. The testing software can then determine the test operations to be performed by parsing the data table.
[0111] The following describes two specific implementation methods for step S203 of this application embodiment: parsing test data to obtain the operation parameter value of each sub-operation.
[0112] The first possible implementation: Test data is recorded in a first data table. The test data includes the target object, action type, operation location, and execution order of each sub-operation in the execution operation. Each row of test data in the first data table corresponds to one sub-operation. The order of the rows of test data in the first data table corresponds to the execution order of the sub-operations.
[0113] The first data table contains multiple rows of test data, each row corresponding to a sub-operation; the sorting of the multiple rows of test data in the data table corresponds to the execution order of the various sub-operations.
[0114] As an example, suppose the operation performed by the tester controlling the input device includes four sub-operations: {Sub-operation 1: Right-click to open the target software's desktop menu; Sub-operation 2: Left-click to select "Open Software" from the menu; Sub-operation 3: Left-click to open the "File" option in the target software's menu bar; Sub-operation 4: Left-click to trigger the "Exit" button in the "File" option bar}. The test data corresponding to this operation consists of four rows of test data, each row corresponding to each sub-operation. Specifically, each row of test data includes the target object, action type, and position of each sub-operation; and the order of the rows corresponds to the execution order of the sub-operations. See Table 1 for the test data.
[0115] Serial Number Operation Action Type Operating position 1 button.right (65,850) 2 button.left (153,372) 3 button.left (478,244) 4 button.left (508,510)
[0116] Table 1
[0117] The sequence number is used to identify the sorting of test data in different rows, which corresponds to the execution order of the four sub-operations in the execution operation.
[0118] The test data in row number 1 corresponds to sub-operation 1: right-click to open the target software's desktop menu. Sub-operation 1 targets the "button", the action type is "button.right", and the position is (65, 850). Here, "button.right" means right-clicking the mouse; (65, 850) represents the position coordinates of the right-click operation in the screen coordinate system.
[0119] The test data in row number 2 corresponds to sub-operation 2: Click the left mouse button to select "Open Software" from the menu. Sub-operation 2 targets the "button", the action type is "button.left", and the operation position is (153, 372). Here, "button.left" means clicking the left mouse button; (153, 372) represents the position coordinates of the left mouse button click operation in the screen coordinate system.
[0120] The test data in row number 3 corresponds to sub-operation 3: clicking the left mouse button to open the "File" option in the target software's menu bar. Sub-operation 3 targets the "button", the action type is "button.left", and the operation position is (478, 244). Here, "button.left" means clicking the left mouse button; (478, 244) represents the position coordinates of the left mouse button click operation in the screen coordinate system.
[0121] The test data in row number 4 corresponds to sub-operation 4: clicking the left mouse button to trigger the "Exit" button in the "File" option bar. Sub-operation 4 targets the "button", the action type is "button.left", and the operation position is (508, 510). Here, "button.left" means clicking the left mouse button; (508, 510) represents the position coordinates of the left mouse button click in the screen coordinate system.
[0122] For the test data corresponding to the first implementation method, this application embodiment provides a specific implementation method for parsing the test data to obtain the operation parameter value of each sub-operation.
[0123] The test data included in the first data table is parsed row by row. The operation parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data, thus obtaining the first operation parameter table.
[0124] The first data table contains multiple rows of data, with each row corresponding to a sub-operation in the execution operation. The testing software parses the test data in the first data table row by row. By parsing row by row, the software can sequentially obtain the operation object, operation action type, and operation position of each sub-operation in the execution operation.
[0125] The parsed sub-operations, along with their corresponding operation objects and action types, allow us to determine the action parameter values for those sub-operations. In some possible implementations, a pre-established correspondence between operation objects, action types, and action parameter values is used.
[0126] Based on the established correspondence between the operation object, operation action type, and action parameter values, the action parameter value of the sub-operation corresponding to a row of test data in the first data table can be determined according to the operation object and operation action type included in that row of test data. For example, a correspondence can be pre-set between {the operation object is the right mouse button and the operation action type is click} and {the action parameter value is 0}; thus, when the parsed sub-operation corresponds to the right mouse button and the operation action type is click, the action parameter value is determined to be 0. As another example, a correspondence can be pre-set between {the operation object is the left mouse button and the operation action type is click} and {the action parameter value is 1}; thus, when the parsed sub-operation corresponds to the left mouse button and the operation action type is click, the action parameter value is determined to be 1. In another possible implementation, the data type of the operation object and the data type of the operation action type are the same as the data type of the action parameter, allowing the operation object and operation action type to be directly used as the action parameter value of the operation parameter.
[0127] The position parameters of the sub-operation are determined based on the operation position obtained from the parsing. In some possible implementations, the operation position is a coordinate, and the coordinate value of the operation position is used as the value of the position parameter. In another possible implementation, the operation position is data used to indicate the coordinates included in the screen coordinate system. First, the coordinates in the screen coordinate system corresponding to the operation position are determined based on the operation position, and then the coordinate values of the obtained coordinates are used as the values of the position parameters in the operation parameters. For example, the operation position is a vector of relative position based on a preset standard position. Based on the operation position and the coordinates of the standard position in the screen coordinate system, the coordinate values of the screen coordinate system corresponding to the operation position are determined. The obtained coordinate values of the screen coordinate system corresponding to the operation position are used as the values of the position parameters.
[0128] Taking the first data table shown in Table 1 as an example. In row 1, the test data's object is "button" and the action type is "button.right", so the action parameter value is 0; the operation position is "(65,850)", so the position parameter value is (65,850). In row 2, the test data's object is "button" and the action type is "button.left", so the action parameter value is 1; the operation position is "(153,372)", so the position parameter value is (153,372). In row 3, the test data's object is "button" and the action type is "button.left", so the action parameter value is 1; the operation position is "(478,244)", so the position parameter value is (478,244). If the test data in row number 4 has the operation object "button" and the operation action type "button.left", then the action parameter value is 1; if the operation position is "(508,510)", then the position parameter value is (508,510).
[0129] The first operation parameter table may include a multi-row list. Each row corresponds to a sub-operation. Each row includes the action parameter value and position parameter value corresponding to a sub-operation. The order of the rows in the first operation parameter table is consistent with the execution order of the sub-operations corresponding to each row. The resulting first operation parameter table is shown in Table 2:
[0130] [0,(65,850)] [1,(153,372)] [1,(478,244)] [1,(508,510)]
[0131] Table 2
[0132] After obtaining the first operation parameter table, the execution statement of the sub-operation corresponding to each row list can be generated based on the action parameter value and position parameter value in each row list included in the first operation parameter table.
[0133] Based on the first operation parameter table, this application embodiment provides step S204: using the operation parameter values of each sub-operation, assigning values to the parameter variables included in the preset function respectively, to obtain a specific implementation of the execution statement of each sub-operation.
[0134] Take one row of data from the first operation parameter table as the first target data. Generate the execution statement for the sub-operation corresponding to the first target data based on the action parameter values and position parameter values included in the first target data.
[0135] It should be noted that the embodiments of this application do not limit the method for determining the first target data. In one possible implementation, the data in each row of the first operation parameter table is sequentially used as the first target data to obtain the execution statement of the sub-operation corresponding to each row of data.
[0136] The execution statements for the sub-operation corresponding to the first target data include action statements and position statements. The action statements are used to execute the operation according to the action type of the sub-operation corresponding to the first target data. The position statements are used to determine the position of the operation to be executed for the sub-operation corresponding to the first target data.
[0137] Based on the action parameter values included in the first target data, values are assigned to the action variables of the operation functions included in the preset function. Based on the operation functions after the action variables are assigned values, action statements of the operation action type that execute the sub-operation corresponding to the first target data can be generated.
[0138] As an example, taking the first row of data [0, (65, 850)] in Table 2 above as the first target data, the operation functions are mouse.press() and mouse.release(), and the action variables included in the operation functions are press() and release(). Using the action parameter value 0 to assign a value to the action variables included in the operation functions, the resulting operation functions including the assigned action variables are mouse.press(button.right) and mouse.release(button.right). The action statements generated based on the operation functions including the assigned action variables are mouse.press(button.right) and mouse.release(button.right). mouse.press(button.right) is used to press the right mouse button. mouse.release(button.right) is used to release the right mouse button after it has been pressed. Thus, clicking the right mouse button can be achieved based on mouse.press(button.right) and mouse.release(button.right).
[0139] The location parameter values are obtained from the first target data, and these values are used to assign values to the location variables of the positioning function. Based on the assigned location variable values, the positioning function is used to generate a location statement.
[0140] As an example, taking the first row of data in Table 2 as the first target data, the positioning function is `mouse.position = ()`, and the position variables included in the positioning function are (). Using the position parameter value (65, 850) to assign values to the position variables included in the positioning function, the resulting positioning function including the assigned position variables is `mouse.position = (65, 850)`. The position statement generated based on the positioning function including the assigned position variables is `mouse.position = (65, 850)`. The position statement `mouse.position = (65, 850)` is used to determine the operation position of the mouse.
[0141] It should be noted that the position statements of the sub-operations corresponding to the first target data are executed earlier in the test script than the action statements of the sub-operations corresponding to the first target data. Based on the obtained position and action statements of the sub-operations corresponding to the first target data, the operation action type determined by the action statement can be executed at the execution operation position determined by the position statement, thereby restoring the sub-operations corresponding to the first target list.
[0142] A second possible implementation: Test data is recorded in a second data table. The test data includes the target object, action type, location, execution interval between adjacent sub-operations, and execution order for each sub-operation. Each row of test data in the second data table corresponds to one sub-operation. The order of the rows of test data in the second data table corresponds to the execution order of the sub-operations.
[0143] The execution interval duration is the execution interval duration between two sub-operations that are adjacent in execution order; for example, the execution interval duration can be the duration between the end time of the sub-operation that is executed first and the start time of the sub-operation that is executed second, which are two sub-operations that are adjacent in execution order.
[0144] Correspondingly, the preset function also includes an interval duration function, which includes a duration variable; the operation parameters also include an execution interval parameter.
[0145] As an example, suppose the operation performed by the tester controlling the input device includes four sub-operations: {Sub-operation 1: Right-click to open the target software's desktop menu; Sub-operation 2: Left-click to select "Open Software" from the menu; Sub-operation 3: Left-click to open the "File" option in the target software's menu bar; Sub-operation 4: Left-click to trigger the "Exit" button in the "File" option bar}. The test data for this operation consists of four rows of test data, each row corresponding to each sub-operation. Specifically, each row includes the target object, action type, position of each sub-operation, and execution interval between adjacent sub-operations. The order of the rows corresponds to the execution order of the sub-operations. See Table 3 for the test data.
[0146] Serial Number Operation Action Type Operating position Execution interval 1 button.right (65,850) 2.51 2 button.left (153,372) 2.09 3 button.left (478,244) 3.77 4 button.left (508,510) 3.5
[0147] Table 3
[0148] The sequence number is used to identify the sorting of test data in different rows, which corresponds to the execution order of the four sub-operations in the execution operation.
[0149] The test data in row number 1 corresponds to sub-operation 1: right-click to open the desktop menu of the target software. Sub-operation 1 targets the "button", the action type is "button.right", the position is (65, 850), and the execution interval between sub-operation 1 and the next adjacent sub-operation (sub-operation 2) is 2.51 seconds. Here, "button.right" represents right-clicking the mouse, (65, 850) represents the position coordinates of the right-click operation in the screen coordinate system, and 2.51 indicates that sub-operation 2 will begin execution 2.51 seconds after sub-operation 1 finishes.
[0150] The test data in row number 2 corresponds to sub-operation 2: clicking the left mouse button to select "Open Software" from the menu. Sub-operation 2 targets the "button", the action type is "button.left", the position is (153, 372), and the execution interval between sub-operation 2 and the next adjacent sub-operation (sub-operation 3) is 2.09 seconds. Here, "button.left" represents clicking the left mouse button; (153, 372) represents the position coordinates of the left mouse button click in the screen coordinate system; 2.09 indicates that sub-operation 3 will begin execution 2.09 seconds after sub-operation 2 finishes.
[0151] The test data in row number 3 corresponds to sub-operation 3: clicking the left mouse button to open the "File" option in the target software's menu bar. Sub-operation 3 targets the "button", the action type is "button.left", the position is (478, 244), and the execution interval between sub-operation 3 and the next adjacent sub-operation (sub-operation 4) is 3.77 seconds. Here, "button.left" represents clicking the left mouse button; (478, 244) represents the position coordinates of the left mouse button click in the screen coordinate system; and 3.77 indicates that sub-operation 4 will begin execution 3.77 seconds after sub-operation 3 finishes.
[0152] The test data in row number 4 corresponds to sub-operation 4: clicking the left mouse button to trigger the "Exit" button in the "File" option bar. Sub-operation 4 targets the "button", the action type is "button.left", the operation position is (508, 510), and the execution interval between sub-operation 4 and the next adjacent sub-operation is 3.5 seconds. Here, "button.left" represents clicking the left mouse button; (508, 510) represents the position coordinates of the left mouse button click in the screen coordinate system; 3.5 indicates that after sub-operation 4 finishes execution, the next sub-operation (end operation) will begin after a 3.5-second interval.
[0153] The next sub-operation after sub-operation 4 is the end operation, and the corresponding test data is empty.
[0154] For the test data corresponding to the second implementation method, this application embodiment provides a specific implementation method for parsing the test data to obtain the operation parameter value of each sub-operation.
[0155] The test data included in the second data table is parsed row by row according to the execution interval duration. The action parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data. The execution interval duration between two sub-operations with adjacent execution order is used as the execution interval parameter value to obtain the second operation parameter table.
[0156] The second data table contains multiple rows of data, with each row corresponding to a sub-operation in the execution operation. The testing software parses the test data in the second data table row by row. By parsing row by row, it can sequentially obtain the operation object, operation action type, operation position of each sub-operation, and the execution interval between two adjacent sub-operations in the execution operation.
[0157] Based on the parsed sub-operation's corresponding operation object and operation action type, the action parameter value of that sub-operation can be determined. In some possible implementations, the data types of the operation object and operation action type differ from the data type of the action parameter. A pre-established correspondence between the operation object / action type and the action parameter value is established. Based on this established correspondence, the action parameter value of the sub-operation corresponding to a row of test data in the second data table can be determined according to the operation object and operation action type included in that row. In another possible implementation, the data types of the operation object and operation action type are the same as the data type of the action parameter, allowing the operation object and operation action type to be directly used as the action parameter value.
[0158] The position parameter value of the sub-operation is determined based on the operation position obtained from the parsing. In some possible implementations, the operation position is the coordinate in the screen coordinate system, and the coordinate value of the operation position is used as the value of the position parameter. In another possible implementation, the operation position is data used to indicate the coordinates included in the screen coordinate system. First, the coordinates included in the screen coordinate system are determined based on the operation position, and then the coordinate values of the obtained coordinates are used as the value of the position parameter. For example, the operation position is a vector of relative position based on a preset standard position. Based on the operation position and the coordinates of the standard position in the screen coordinate system, the coordinate value of the screen coordinate system corresponding to the operation position is determined. The obtained coordinate value of the screen coordinate system corresponding to the operation position is used as the value of the position parameter.
[0159] Parsing the test data in the second data table yields the execution interval between two adjacent sub-operations. This execution interval is then used as the execution interval parameter value for the sub-operation that executes first.
[0160] Taking the second data table shown in Table 3 as an example. In row 1, the test data's object is "button" and the action type is "button.right", with an action parameter value of 0; the operation position is "(65,850)", with a position parameter value of (65,850); the execution interval is "2.51", with an execution interval parameter value of 2.51. In row 2, the test data's object is "button" and the action type is "button.left", with an action parameter value of 1; the operation position is "(153,372)", with a position parameter value of (153,372); the execution interval is "2.09", with an execution interval parameter value of 2.09. The test data in row 3 has the operation object "button" and the operation action type "button.left", with an action parameter value of 1; the operation position is "(478,244)", with a position parameter value of (478,244); and the execution interval duration is "3.77", with an execution interval parameter value of 3.77. The test data in row 4 has the operation object "button" and the operation action type "button.left", with an action parameter value of 1; the operation position is "(508,510)", with a position parameter value of (508,510); and the execution interval duration is "3.5", with an execution interval parameter value of 3.5.
[0161] The second operation parameter table may include a multi-row list. Each row corresponds to a sub-operation. Each row includes the action parameter value and position parameter value corresponding to a sub-operation. The order of the rows in the second operation parameter table is consistent with the execution order of the sub-operations corresponding to each row. The resulting second operation parameter table is shown in Table 4.
[0162] [0,(65,850),2.51] [1,(153,372),2.09] [1,(478,244),3.77] [1,(508,510),3.5]
[0163] Table 4
[0164] After obtaining the second operation parameter table, the execution statement for the sub-operation corresponding to each row list can be generated based on the action parameter value, position parameter value, and execution interval duration included in the second operation parameter table.
[0165] Based on the second operation parameter table, this application embodiment provides step S204: using the operation parameter values of each sub-operation, assigning values to the parameter variables included in the preset function respectively, to obtain a specific implementation of the execution statement of each sub-operation.
[0166] Use one row of data from the second operation parameter table as the second target data. Based on the action parameter values, position parameter values, and execution interval parameter values included in the second target data, generate the execution statement for the sub-operation corresponding to the second target data.
[0167] It should be noted that the embodiments of this application do not limit the method for determining the second target data. In one possible implementation, the data in each row of the second operation parameter table is sequentially used as the second target data to obtain the execution statement of the sub-operation corresponding to each row of data.
[0168] The execution statements for the sub-operations corresponding to the second target data include action statements, position statements, and execution interval statements. The action statements are used to execute operations according to the action type of the sub-operation corresponding to the second target data. The position statements determine the position of the sub-operation to be executed. The execution interval statements control the duration between the end execution time of the execution statement for the sub-operation corresponding to the second target data and the start execution time of the execution statement for the next sub-operation in the order of execution.
[0169] Based on the action parameter values included in the second target data, values are assigned to the action variables of the operation functions included in the preset function. Based on the operation functions after the action variables are assigned values, action statements of the operation action type that execute the sub-operation corresponding to the second target data can be generated.
[0170] The method of generating action statements based on action parameter values is similar to the method of generating action statements based on action parameter values in the first possible implementation method mentioned above. Please refer to the description above for details, which will not be repeated here.
[0171] The location parameter values are obtained from the second target data, and these values are used to assign values to the location variables of the positioning function. Based on the assigned location variable values, the positioning function is used to generate a location statement.
[0172] The method of generating position statements based on position parameter values is similar to the method of generating position statements based on position parameter values in the first possible implementation described above. Please refer to the description above for details, which will not be repeated here.
[0173] The interval duration function and the duration variables included in the interval duration function are defined by the script execution dependency statements. After obtaining the execution interval duration included in the second target data, the execution interval duration is used to assign values to the duration variables included in the interval duration function. Based on the assigned values to the duration variables, the interval duration function generates the execution interval statement.
[0174] As an example, taking the first row of data [0, (65, 850), 2.51] in Table 4 above as the second target data, the interval duration function is `sleep()`, and the duration variables included in the interval duration function are the variables that need to be written in parentheses. Using the execution interval duration of 2.51 to assign values to the duration variables included in the interval duration function, the resulting interval duration function including the assigned duration variables is `sleep(2.51)`. The execution interval statement generated based on the interval duration function including the assigned duration variables is `sleep(2.51)`. The execution interval statement `sleep(2.51)` is used to control the time interval between the end execution time of the sub-operation corresponding to the first row of data in Table 4 and the start execution time of the sub-operation corresponding to the second row of data.
[0175] It should be noted that the execution order of the position statements of the sub-operations corresponding to the second target data is earlier than the execution order of the action statements of the sub-operations corresponding to the second target data, and the execution order of the action statements of the sub-operations corresponding to the second target data is earlier than the execution order of the execution interval statements of the sub-operations corresponding to the second target data. Based on the obtained position statements, action statements, and execution interval statements of the sub-operations corresponding to the second target data, the operation action type determined by the action statement can be executed at the execution operation position determined by the position statement, thereby restoring the sub-operations corresponding to the second target data. Furthermore, after executing the action statement, the execution interval statement can be executed to ensure that there is a certain time interval between the sub-operation corresponding to the second target data and the next sub-operation whose execution order is the sub-operation corresponding to the second target data, which facilitates the target software's response to the executed sub-operations and obtains a more accurate execution result.
[0176] In one possible implementation, during the execution of the test script, it is also necessary to take a screenshot of the target software's display interface. The resulting screenshot is compared with a standard image of the target software's display interface to obtain the test results for the target software. The test script generated by the test software also includes a screenshot statement for taking a screenshot of the target software's display interface. Based on this, this application embodiment provides another test script generation method. The preset function defined by the script execution dependency statement also includes a screenshot function. The screenshot function includes a storage location variable. The screenshot function is used to perform a screenshot operation and store the generated screenshot image in the storage space indicated by the assigned storage location variable. As an example, the screenshot function is screen_shot = screenshot().
[0177] In addition to the steps described above, before generating the test script based on the script execution dependency statements and the execution statements of each of the sub-operations in step S205, the following steps are also included:
[0178] The target storage location of each sub-operation is used to assign a value to the storage location variable of the screenshot function, thereby obtaining the screenshot statement for each sub-operation. The screenshot statement consists of a screenshot function including the assigned storage location variable, and the target storage location is used to store the screenshot image obtained by executing the sub-operation.
[0179] The target storage location for a sub-operation is a pre-determined location for storing screenshots obtained after simulating the execution of the sub-operation during the test script's execution. The target storage location of the sub-operation is used as its storage location parameter. For example, in response to a trigger operation on the record button, the test software automatically creates a folder named [mspaint] corresponding to the software name. During the test script generation process corresponding to test data with test case number mspa001, the generated screenshots are stored in a folder named [mspa001] created within the [mspaint] folder. The [mspa001] folder created within the [mspaint] folder serves as the folder for storing screenshots. The target storage location is represented as mspaint / mspa001. It should be noted that when an operation includes multiple sub-operations, the target storage locations for each sub-operation may differ. The target storage locations for each sub-operation can be pre-defined.
[0180] By assigning values to the target storage locations of each sub-operation as the storage location variables of the screenshot function, the screenshot statements for each sub-operation are obtained. The screenshot statement is the screenshot function after the storage location variables have been assigned values.
[0181] In some possible implementations, the screenshot function also includes a name variable. The name variable is used to determine the name of the screenshot image. The name variable is determined based on the execution order of the sub-operations. Taking the screenshot function `screen_shot = screenshot()` and the target storage location as `mspaint / mspa001` as an example, the screenshot statement for the first sub-operation in the execution order is `screen_shot.screenshot_activate_window('mspaint / mspa001', 1)`. Executing this screenshot statement will capture a screenshot of the target software's display interface, resulting in a screenshot image named `1.png` stored at the `mspaint / mspa001` location.
[0182] The test script can also compare the standard images corresponding to each sub-operation with the generated screenshot images of that sub-operation to obtain test results. The standard images corresponding to each sub-operation are screenshots of the display interface shown by the target software in response to the execution of each sub-operation. These standard images serve as a standard for judging the normal operation of the target software and are used to compare with screenshot images obtained during subsequent execution of the test script, thereby automatically determining the test results. In one possible implementation, the image name of the screenshot image for each sub-operation is determined according to the execution order of the sub-operation. The image name of the standard image for each sub-operation is the same as the image name of the screenshot image for that sub-operation. Furthermore, the standard image for each sub-operation is stored in the target storage location of the sub-operation. In a test script generation method provided in this application embodiment, the preset function defined by the script execution dependency statement also includes a comparison function. The comparison function includes a path variable. The comparison function is used to read the image stored under the path indicated by the assigned path variable and compare the images.
[0183] In addition to the steps described above, before generating the test script based on the script execution dependency statements and the execution statements of each of the sub-operations in step S205, the following steps are also included:
[0184] Assign the target storage location of each sub-operation to the path variable to obtain the comparison statement corresponding to each sub-operation.
[0185] In one possible implementation, each sub-operation has a corresponding, individually executed comparison statement. In another possible implementation, all sub-operations have the same target storage location, and by running a comparison statement once, the target storage location can be accessed to read the screenshot images of each sub-operation and the standard images corresponding to each sub-operation, thus enabling the comparison of the screenshot images of each sub-operation and the corresponding standard images.
[0186] As an example, comparison statements include statements that retrieve the standard image and screenshot image of the sub-operation to be compared, as well as statements that execute the comparison between the standard image and the screenshot image of the sub-operation. As an example, comparison statements include `similar = similar(str(case_path), click_cnt)` and `similar.compare_image()`. Here, `str(case_path)` is the assigned path variable, and its value is the target storage location. `click_cnt` is the number of sub-operations included in the operation, which is the number of screenshot images to be compared. Based on the value of `click_cnt`, the range of values for the execution order of the sub-operations can be determined. By running the statement `similar = similar(str(case_path), click_cnt)`, the target storage location can be accessed, and the screenshot images and standard images with the same image names, determined according to the execution order of the various sub-operations, can be retrieved for comparison. By running `similar.compare_image()`, you can compare the screenshot image to be compared with a standard image.
[0187] Further, S205: The step of generating a test script based on the script execution dependency statements and the execution statements of each of the sub-operations includes:
[0188] A test script is generated based on the script execution dependency statements, the execution statements for each of the sub-operations, and the comparison statements.
[0189] In this configuration, the execution order of the comparison statements is later than the execution order of the execution statements for each sub-operation. This ensures that after a screenshot is obtained by executing the statements, it is compared with a standard image to obtain the comparison results, and thus the test results for the target software are obtained.
[0190] It should be noted that, in one possible implementation, the testing software can load the generated test script and use it to perform subsequent tests on the target software. The testing software can acquire the test script in response to a script loading operation. This application does not limit the specific implementation of triggering the script loading operation. In one possible implementation, the tester triggers the script loading operation by pressing a button on the testing software's display interface. As an example, the testing software's display interface includes an "Import Script" button. The tester can trigger the script loading operation by clicking the "Import Script" button. In another possible implementation, the testing software is pre-configured to periodically check for test script files in a specific storage space. After detecting the existence of a test script, the testing software automatically triggers the script loading operation. The testing software can also display a script loading page, which displays the script name and execution status data of the test script. The execution status data indicates the execution status of the test script. As an example, the execution status data includes an execution state. The execution state includes an unexecuted state and an executed state. In some possible implementations, the execution status data of the test script also includes the number of times the test script was executed, the completion time of the test script, and the execution result of the test script. When the execution status is "executed," the corresponding number of times the test script was executed, the execution time of the test script, and the execution result of the test script are all null values.
[0191] See Figure 6 As shown in the figure, this is a schematic diagram of a result display page provided in an embodiment of this application. The script loading page includes the script name of the test script and the execution status data of the test script. The execution status data of the test script includes the execution status of the test script, the completion time of the test script, and the execution result of the test script. The script name of the test script is "mspaint001". Here, "mspaint" is the name of the target software, and 001 is the test case number. The execution status is "not executed", and the execution result and completion time are both empty values.
[0192] Based on the test script generation method provided in the embodiments of this application, the embodiments of this application also provide a test script generation apparatus, see [link to relevant documentation]. Figure 7 As shown in the figure, this is a schematic diagram of a test script generation device provided in an embodiment of this application. The test script generation device includes:
[0193] The first acquisition unit 701 is configured to, in response to a trigger operation on the recording button, monitor the execution operation performed by the input device on the target software and acquire test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order of each sub-operation in the execution operation.
[0194] The second acquisition unit 702 is used to acquire script execution dependency statements; the script execution dependency statements are used to define preset functions and parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, and the operation functions include action variables;
[0195] The parsing unit 703 is used to parse the test data to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters.
[0196] The first assignment unit 704 is used to assign values to the parameter variables included in the preset function using the operation parameter values of each sub-operation, so as to obtain the execution statement of each sub-operation;
[0197] The generation unit 705 is used to generate a test script based on the script execution dependency statements and the execution statements of each of the sub-operations, wherein the execution order of the execution statements of each of the sub-operations is determined according to the execution order between the sub-operations in the test data.
[0198] In one possible implementation, the test data is recorded in a first data table, each row of test data in the first data table corresponds to a sub-operation, and the order of the test data in each row of the first data table corresponds to the execution order between the sub-operations.
[0199] The parsing unit 703 is used to parse the test data included in the first data table row by row sequentially, determine the action parameter value corresponding to the operation parameter of the sub-operation based on the operation object and operation action type of the sub-operation corresponding to each row of test data, and determine the position parameter value corresponding to the operation parameter of the sub-operation based on the operation position of the sub-operation corresponding to each row of test data, thereby obtaining a first operation parameter table; each row of data in the first operation parameter table corresponds to a sub-operation, and each row of data includes the action parameter value and position parameter value of the sub-operation; the row order of each row of data in the first operation parameter list corresponds to the execution order between the various sub-operations.
[0200] In one possible implementation, the first assignment unit 704 is used to assign values to the action variables of the operation function using the action parameter values of the sub-operations included in the first target data, thereby obtaining the action statement of the sub-operation corresponding to the first target data. The action statement is composed of an operation function including the assigned action variables. The first target data is a row of data included in the first operation parameter table.
[0201] By using the position parameter values of the sub-operations included in the first target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the first target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0202] In one possible implementation, the test data further includes the execution interval between two sub-operations with adjacent execution order; the preset function further includes an interval duration function, which includes a duration variable; the operation parameters further include an execution interval parameter; the test data is recorded in a second data table, where each row of test data in the second data table corresponds to a sub-operation, and the order of the rows of test data in the second data table corresponds to the execution order between the sub-operations;
[0203] The parsing unit 703 is used to parse the test data included in the second data table row by row, determine the action parameter value corresponding to the operation parameter of the sub-operation according to the operation object and operation action type of the sub-operation corresponding to each row of test data, determine the position parameter value corresponding to the operation parameter of the sub-operation according to the operation position of the sub-operation corresponding to each row of test data, and take the execution interval time between two sub-operations with adjacent execution order as the execution interval parameter value of the sub-operation to obtain the second operation parameter table;
[0204] The second operation parameter table includes a row of data corresponding to a sub-operation. Each row of data includes the action parameter value, position parameter value, and execution interval parameter value of the sub-operation. The execution interval parameter value is used to indicate the execution interval between the sub-operation and the next sub-operation adjacent to the execution sequence. The row order of each row of data in the second operation parameter table corresponds to the execution order between the sub-operations.
[0205] In one possible implementation, the first assignment unit 704 is used to assign values to the action variables of the operation function using the action parameter values of the sub-operations included in the second target data, thereby obtaining the action statement of the sub-operation corresponding to the second target data. The action statement is composed of an operation function including the assigned action variables. The second target data is a row of data included in the second operation parameter table.
[0206] By using the position parameter values of the sub-operations included in the second target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the second target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
[0207] The execution interval statement for the sub-operation included in the second target data is obtained by assigning the execution interval parameter value of the sub-operation included in the interval duration function to the interval duration function. The execution interval statement is composed of the interval duration function including the assigned duration variable.
[0208] In one possible implementation, the preset function further includes a screenshot function, which includes a storage location variable; the execution statement of each sub-operation also includes a screenshot statement;
[0209] The device further includes:
[0210] The second assignment unit is used to assign values to the storage location variables of the screenshot function using the target storage locations of each sub-operation, thereby obtaining the screenshot statement for each sub-operation. The target storage location is used to store the screenshot image obtained by executing the sub-operation, and the screenshot statement is composed of a screenshot function including the assigned storage location variables.
[0211] In one possible implementation, the image name of the screenshot image for each sub-operation is determined according to the execution order of the sub-operations; the image name of the standard image for each sub-operation is the same as the image name of the screenshot image for the sub-operation; the standard image for each sub-operation is stored in the target storage location of the sub-operation; the preset function further includes a comparison function, the comparison function including a path variable; and the device further includes:
[0212] The third assignment unit is used to assign the target storage location of each of the sub-operations to the image path to obtain the comparison statement;
[0213] The generation unit is used to generate a test script based on the script execution dependency statement, the execution statement of each of the sub-operations, and the comparison statement, wherein the execution order of the comparison statement is later than the execution order of the execution statement of each of the sub-operations.
[0214] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0215] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0216] This application provides a test script generation device, including a memory and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors, the one or more programs including the test script generation method described in one or more of the above embodiments.
[0217] Figure 8 This is a block diagram illustrating a device 800 for generating test scripts according to an exemplary embodiment. For example, the test script generation device 800 may be a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, medical device, fitness equipment, personal digital assistant, etc.
[0218] Reference Figure 8 The device 800 may include one or more of the following components: a processing component 802, a memory 804, a power supply component 806, a multimedia component 808, an audio component 810, an input / output (I / O) interface 812, a sensor component 814, and a communication component 816.
[0219] Processing component 802 typically controls the overall operation of device 800, such as operations associated with display, telephone calls, data communication, camera operation, and recording. Processing component 802 may include one or more processors 820 to execute instructions to complete all or part of the steps of the methods described above. Furthermore, processing component 802 may include one or more modules to facilitate interaction between processing component 802 and other components. For example, processing component 802 may include a multimedia module to facilitate interaction between multimedia component 808 and processing component 802.
[0220] Memory 804 is configured to store various types of data to support the operation of device 800. Examples of this data include instructions for any application or method operating on device 800, contact data, phonebook data, messages, pictures, videos, etc. Memory 804 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0221] Power supply component 806 provides power to various components of device 800. Power supply component 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to device 800.
[0222] Multimedia component 808 includes a screen that provides an output interface between the device 800 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors may sense not only the boundaries of the touch or swipe action but also the duration and pressure associated with the touch or swipe operation. In some embodiments, multimedia component 808 includes a front-facing camera and / or a rear-facing camera. When the device 800 is in an operating mode, such as a shooting mode or a video mode, the front-facing camera and / or the rear-facing camera may receive external multimedia data. Each front-facing camera and rear-facing camera may be a fixed optical lens system or have focal length and optical zoom capabilities.
[0223] Audio component 810 is configured to output and / or input audio signals. For example, audio component 810 includes a microphone (MIC) configured to receive external audio signals when device 800 is in an operating mode, such as call mode, recording mode, and voice information processing mode. The received audio signals may be further stored in memory 804 or transmitted via communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
[0224] I / O interface 812 provides an interface between processing component 802 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to, home buttons, volume buttons, power buttons, and lock buttons.
[0225] Sensor assembly 814 includes one or more sensors for providing status assessments of various aspects of device 800. For example, sensor assembly 814 can detect the on / off state of device 800, the relative positioning of components such as the display and keypad of device 800, and can also detect changes in the position of device 800 or a component of device 800, the presence or absence of user contact with device 800, the orientation or acceleration / deceleration of device 800, and temperature changes of device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. Sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, sensor assembly 814 may also include an accelerometer, a gyroscope, a magnetometer, a pressure sensor, or a temperature sensor.
[0226] Communication component 816 is configured to facilitate wired or wireless communication between device 800 and other devices. Device 800 can access wireless networks based on communication standards, such as WiFi, 2G, or 3G, or combinations thereof. In one exemplary embodiment, communication component 816 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, communication component 816 also includes a near-field communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on radio frequency information processing (RFID) technology, Infrared Data Association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0227] In an exemplary embodiment, device 800 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the methods described above.
[0228] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 804 including instructions, which can be executed by a processor 820 of device 800 to perform the above-described method. For example, the non-transitory computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.
[0229] Furthermore, it should be noted that this application also provides a computer program product or computer program, which may include computer instructions, which may be stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor may execute the computer instructions, causing the computer device to perform the aforementioned actions. Figure 2 The description of the test script generation method in the corresponding embodiments is already provided and will not be repeated here. Furthermore, the beneficial effects of using the same method will also not be repeated. For technical details not disclosed in the computer program products or computer program embodiments related to this application, please refer to the description of the method embodiments of this application.
[0230] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems or apparatus disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and relevant parts can be referred to the method section.
[0231] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0232] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0233] The above provides a detailed description of a test script generation method, a test script generation device, and a readable storage medium provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for generating test scripts, characterized in that, Applied to testing software, the method includes: In response to a trigger operation of the recording button, the system monitors the execution operation performed by the input device on the target software and acquires test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order of each sub-operation in the execution operation. Obtain script execution dependency statements; the script execution dependency statements are used to define preset functions and the parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, the operation functions include action variables, and the script execution dependency statements are pre-set on the device running the test software; The test data is analyzed to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters. Using the operation parameter values of each sub-operation, the parameter variables included in the preset function are assigned values respectively to obtain the execution statement of each sub-operation; A test script is generated based on the script execution dependency statements and the execution statements of each of the sub-operations. The execution order of the execution statements of each of the sub-operations is determined according to the execution order among the sub-operations in the test data.
2. The method according to claim 1, characterized in that, The test data is recorded in a first data table. Each row of test data in the first data table corresponds to a sub-operation. The order of the test data in each row of the first data table corresponds to the execution order of each sub-operation. The process of parsing the test data to obtain the operation parameter values for each sub-operation includes: The test data included in the first data table is parsed row by row. The operation parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data, so as to obtain the first operation parameter table. Each row of data in the first operation parameter table corresponds to a sub-operation, and each row of data includes the action parameter value and position parameter value of the sub-operation; the row order of each row of data in the first operation parameter list corresponds to the execution order between the sub-operations.
3. The method according to claim 2, characterized in that, The step of assigning values to the parameter variables included in the preset function using the operation parameter values of each sub-operation to obtain the execution statement of each sub-operation includes: The action statement of the sub-operation corresponding to the first target data is obtained by assigning the action parameter value of the sub-operation to the action variable of the operation function using the action parameter value of the sub-operation included in the first target data. The action statement is composed of the operation function including the assigned action variable. The first target data is a row of data included in the first operation parameter table. By using the position parameter values of the sub-operations included in the first target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the first target data is obtained. The position statement is composed of a positioning function including the assigned position variables.
4. The method according to claim 1, characterized in that, The test data also includes the execution interval between two adjacent sub-operations; the preset function also includes an interval function, which includes a duration variable; the operation parameters also include an execution interval parameter; the test data is recorded in a second data table, where each row of test data in the second data table corresponds to a sub-operation, and the order of the rows of test data in the second data table corresponds to the execution order between the sub-operations; The process of parsing the test data to obtain the operation parameter values for each sub-operation includes: The test data included in the second data table is parsed row by row. The operation parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation object and operation action type of the sub-operation corresponding to each row of test data. The position parameter value corresponding to the operation parameter of the sub-operation is determined according to the operation position of the sub-operation corresponding to each row of test data. The execution interval between two sub-operations with adjacent execution order is used as the execution interval parameter value of the sub-operation to obtain the second operation parameter table. The second operation parameter table includes a row of data corresponding to a sub-operation. Each row of data includes the action parameter value, position parameter value, and execution interval parameter value of the sub-operation. The execution interval parameter value is used to indicate the execution interval between the sub-operation and the next sub-operation that is adjacent in the execution sequence. The row order of each row in the second operation parameter table corresponds to the execution order between the various sub-operations.
5. The method according to claim 4, characterized in that, The step of assigning values to the parameter variables included in the preset function using the operation parameter values of each sub-operation to obtain the execution statement of each sub-operation includes: The action parameter values of the sub-operations included in the second target data are used to assign values to the action variables of the operation function to obtain the action statement of the sub-operation corresponding to the second target data. The action statement is composed of an operation function including the assigned action variable. The second target data is a row of data included in the second operation parameter table. By using the position parameter values of the sub-operations included in the second target data to assign values to the position variables of the positioning function, the position statement of the sub-operation corresponding to the second target data is obtained. The position statement is composed of a positioning function including the assigned position variables. The execution interval statement for the sub-operation included in the second target data is obtained by assigning the execution interval parameter value of the sub-operation included in the interval duration function to the interval duration function. The execution interval statement is composed of the interval duration function including the assigned duration variable.
6. The method according to claim 1, characterized in that, The preset function also includes a screenshot function, which includes a storage location variable; the execution statement of each sub-operation also includes a screenshot statement; Before generating the test script by executing the dependency statements and the execution statements of each of the sub-operations according to the script, the method further includes: The target storage location of each sub-operation is used to assign a value to the storage location variable of the screenshot function, thereby obtaining the screenshot statement for each sub-operation. The target storage location is used to store the screenshot image obtained by executing the sub-operation. The screenshot statement is composed of a screenshot function that includes the assigned storage location variable.
7. The method according to claim 6, characterized in that, The image name of the screenshot image of each sub-operation is determined according to the order of execution of the sub-operations. The image name of the standard image of each sub-operation is the same as the image name of the screenshot image of the sub-operation. The standard image of each sub-operation is stored in the target storage location of the sub-operation. The preset function further includes a comparison function, which includes a path variable, and the method further includes: The target storage location of each sub-operation is assigned to the image path to obtain the comparison statement; The step of generating a test script based on the script execution dependency statements and the execution statements of each of the sub-operations includes: A test script is generated based on the script execution dependency statements, the execution statements of each of the sub-operations, and the comparison statements, wherein the execution order of the comparison statements is later than the execution order of the execution statements of each of the sub-operations.
8. A test script generation device, characterized in that, The apparatus, used in testing software, includes: The first acquisition unit is configured to, in response to a trigger operation on the recording button, monitor the execution operation performed by the input device on the target software and acquire test data corresponding to the execution operation; the execution operation includes at least one sub-operation; the test data includes the operation object, operation action type, operation position, and execution order between each sub-operation in the execution operation; The second acquisition unit is used to acquire script execution dependency statements; the script execution dependency statements are used to define preset functions and parameter variables included in the preset functions; the preset functions include positioning functions and operation functions, the positioning functions include position variables, the operation functions include action variables, and the script execution dependency statements are preset on the device running the test software; A parsing unit is used to parse the test data to obtain the operation parameter values for each sub-operation; the operation parameters include action parameters and position parameters. The first assignment unit is used to assign values to the parameter variables included in the preset function using the operation parameter values of each sub-operation, so as to obtain the execution statement of each sub-operation; The generation unit is used to generate a test script based on the script execution dependency statements and the execution statements of each of the sub-operations, wherein the execution order of the execution statements of each of the sub-operations is determined according to the execution order among the sub-operations in the test data.
9. A test script generation device, characterized in that, include: Processor, memory, system bus; The processor and the memory are connected via the system bus; The memory is used to store one or more programs, the one or more programs including instructions that, when executed by the processor, cause the processor to perform the test script generation method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed on a terminal device, cause the terminal device to perform the test script generation method according to any one of claims 1-7.
Citation Information
Patent Citations
Test case script generation method and generation device, and electronic device
CN109189688A
Method for generating test case, and related device
CN110825618A