Recording and playback method suitable for automated test script

By identifying page elements and dynamically adjusting the waiting time during recording and playback in automated test scripts, the problems of low versatility and poor stability of automated test codes in the prior art are solved, and the testing efficiency and quality are improved.

CN119025419APending Publication Date: 2024-11-26WEAPON EQUIP RES INST OF CHINA NAT WEAPON EQUIP GRP
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing operating system automation testing R&D cycle is urgent, and the writing of automated test codes is low in versatility, which has high requirements for the coding ability of test engineers. The recording and playback method fails to effectively identify page element information and dynamically adjust the waiting time, which affects the stability of the test. Sex and reliability.

Method used

A recording and playback method suitable for automated test scripts is proposed. By recording and monitoring user operations on the server side, an automated test script is generated, and the page element status is intelligently recognized during the playback process, and the waiting time is dynamically adjusted. The Inspect function of DevEco Studio is used. Identify click and slide operations, and use the exponential backoff method to adjust the waiting time.

Benefits of technology

It reduces the requirements for the coding ability of the test engineer, improves the testing efficiency and stability, reduces the human error rate, avoids repeated operations, and ensures the quality of the software.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025419A_ABST
    Figure CN119025419A_ABST
Patent Text Reader

Abstract

The invention provides a recording and playback method suitable for an automatic test script, and belongs to the technical field of software testing. The method comprises the steps that a first terminal and a second terminal are initialized, the first terminal is a server side, and the second terminal is a terminal to be tested; the second terminal executes the test file pushed by the first terminal, and the first terminal records a complete process of executing the test file by the second terminal and monitors a user operation received by the second terminal; the first terminal generates an automatic test script based on the recorded complete process of executing the test file by the second terminal and the monitored user operation received by the second terminal; and in response to repeated execution of the test file by the second terminal, the first terminal pushes the automatic test script to the second terminal for repeated playback. According to the method, the compiling process of the automated testing script is simplified through recording and playback, and the automated testing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of software testing, and in particular relates to a recording and playback method suitable for automated testing scripts. Background Art

[0002] With the rapid development of information technology and its wide application in the field of electronic information product manufacturing, the design of handheld terminals is becoming more and more functional, diversified and integrated. Therefore, testing, as an indispensable part of the software life cycle, pays more attention to test efficiency and coverage. However, for the existing operating system automated testing, its R&D cycle is tight, the universality of writing automated test code is low, and high coding skills are required of test engineers.

[0003] Existing recording and playback methods usually record the user's operations on the interface and then play back the recorded script. CN115794577A discloses a recording method, device, medium, equipment and system for automated test scripts. This solution forms an automated test script by recording the coordinates of clicks and slide operations on the interface, but does not identify the page element information during the recording process, nor does it describe the playback operation. CN202310191912.0 discloses a recording method and a playback method for test scripts. This solution mainly expands and improves the recording operation, and does not optimize the playback method. Therefore, it is necessary to identify the page element information during the recording process, and dynamically adjust the waiting time during the playback process to enhance the stability and reliability of the test and further ensure the quality of the software. Summary of the invention

[0004] In order to solve the above technical problems, the present invention proposes a recording and playback method suitable for automated test scripts.

[0005] The first aspect of the present invention provides a recording and playback method suitable for automated test scripts. The method comprises:

[0006] Step S1, initializing a first terminal and a second terminal; wherein: the first terminal is a server, and the second terminal is a terminal to be tested;

[0007] Step S2: the second terminal executes the test file pushed by the first terminal; wherein: the first terminal records the complete process of the second terminal executing the test file, and monitors the user operation received by the second terminal;

[0008] Step S3, the first terminal generates an automated test script for the test file; wherein: the first terminal generates the automated test script based on the recorded second terminal executing the complete process of the test file and the monitored user interaction operations received by the second terminal, and identifies page elements and their attributes;

[0009] Step S4, the second terminal plays back the automated test script; wherein: in response to the second terminal repeatedly executing the test file, intelligently identifying the state of page elements during the playback process, the first terminal pushes the automated test script to the second terminal for multiple playbacks.

[0010] According to the method of the first aspect of the present invention, in step S1: a communication connection between a first terminal and a second terminal is established; a test script generator is initialized at the first terminal; and the second terminal is configured in a readable and writable mode.

[0011] According to the method of the first aspect of the present invention, in step S2:

[0012] The first terminal uses the test script generator to generate a test file by compiling, and pushes the test file to the second terminal; the second terminal loads the test file to a designated loading point, and executes the test file;

[0013] When the second terminal executes the test file, the first terminal records the entire process of the second terminal executing the test file and generates a recording file, and at the same time monitors the user operations received by the second terminal during the entire process of executing the test file through a local thread, and intelligently identifies page element selection and interaction;

[0014] The user operation includes a click operation and a slide operation.

[0015] According to the method of the first aspect of the present invention, in step S3:

[0016] When the first terminal monitors the click operation, it uses the Inspect function in DevEco Studio to identify the page element selected by the user's click operation through the start coordinates and end coordinates of the user's click operation, and checks its properties to encapsulate it into a click event;

[0017] When the first terminal monitors the sliding operation, the Inspect function in DevEco Studio is used to identify the page element selected by the user's sliding operation, as well as the start time, end time, and duration of the sliding operation through the start coordinates and end coordinates of the user's sliding operation, and encapsulate them into a sliding event;

[0018] The click events and the sliding events are inserted into the corresponding positions of the recording file in chronological order and packaged into the automated test script.

[0019] According to the method of the first aspect of the present invention, in step S4: in response to the second terminal repeatedly executing the test file, the first terminal pushes the automated test script to the second terminal; the second terminal calls the automated test script and plays it back multiple times; during the playback process, the page element status is intelligently identified, and the waiting time is dynamically adjusted using an exponential backoff method.

[0020] The second aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the recording and playback method for automated test scripts described in the first aspect of the present disclosure are implemented.

[0021] The third aspect of the present invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the recording and playback method for automated test scripts described in the first aspect of the present disclosure.

[0022] In summary, through the technical solution of the present invention, testers do not need to pay attention to the underlying code implementation, thereby avoiding the testing difficulties caused by programming in different languages. The present invention is mainly used in the repeated regression testing phase. When the developer fixes a defect, in order to ensure that the current modification does not affect the original business or code, the recording and playback method is used to avoid occasional complex problems, save functional testing time, reduce repeated operations, thereby improving testing efficiency, and reducing the requirements for test engineers and reducing the human error rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0024] Figure 1 The figure is a flowchart of a recording and playback method suitable for automated test scripts. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0026] The first aspect of the present invention provides a recording and playback method suitable for automated test scripts. Figure 1 As shown, the method includes:

[0027] Step S1, initializing a first terminal and a second terminal; wherein: the first terminal is a server, and the second terminal is a terminal to be tested;

[0028] Step S2: the second terminal executes the test file pushed by the first terminal; wherein: the first terminal records the complete process of the second terminal executing the test file, and monitors the user operation received by the second terminal;

[0029] Step S3, the first terminal generates an automated test script for the test file; wherein: the first terminal generates the automated test script based on the recorded complete process of the second terminal executing the test file and the monitored user operations received by the second terminal;

[0030] Intelligently identify page elements during recording. Use the Inspect function in DevEco Studio to intelligently identify the selected page elements and view their properties based on the coordinates clicked by user interactions.

[0031] Step S4, the second terminal plays back the automated test script; wherein: in response to the second terminal repeatedly executing the test file, the first terminal pushes the automated test script to the second terminal for multiple playbacks.

[0032] During the playback process, the status of page elements is intelligently identified. The specific operations include: first, setting conditions in the script to check whether the element exists, is visible, interactive, and whether specific attributes meet the presets; second, using assertion statements to verify the status of the element (such as text content, color, style) to ensure that it is in the expected state; finally, for possible situations such as element non-existence or loading timeout, use the try-catch structure to capture exceptions.

[0033] After identifying the status of the page elements, the waiting time is adjusted dynamically. The waiting time is adjusted according to the exponential backoff method to balance the performance and the reliability of the test results to achieve adaptive waiting. The specific implementation strategy includes that when the network request fails or encounters an error, the exponential backoff method allows the request to wait for a random period of time and then retry. If the retry is successful, the playback continues; if it fails again, the waiting time is extended and the strategy of exponentially increasing the waiting time is adopted.

[0034] The specific implementation process of the exponential backoff method includes setting the initial basic waiting time. After each retry fails, the waiting time is multiplied by a random factor to increase the waiting time. In order to avoid synchronization problems caused by multiple clients retrying at the same time, a random factor is added to each retry in this script to reduce conflicts and improve the overall efficiency of the system. At the same time, the maximum number of retries is set to prevent unlimited retries from wasting system resources or deadlocking.

[0035] According to the method of the first aspect of the present invention, in step S1: a communication connection between a first terminal and a second terminal is established; a test script generator is initialized at the first terminal; and the second terminal is configured in a readable and writable mode.

[0036] According to the method of the first aspect of the present invention, in step S2:

[0037] The first terminal uses the test script generator to generate a test file by compiling, and pushes the test file to the second terminal; the second terminal loads the test file to a designated loading point, and executes the test file;

[0038] When the second terminal executes the test file, the first terminal records the entire process of the second terminal executing the test file and generates a recording file, and at the same time monitors user operations received by the second terminal during the entire process of executing the test file through a local thread;

[0039] The user operation includes a click operation and a slide operation.

[0040] According to the method of the first aspect of the present invention, in step S3:

[0041] When the first terminal monitors the click operation, it uses the Inspect function in DevEco Studio to identify the page element selected by the user's click operation, view its properties, and encapsulate it into a click event;

[0042] When the first terminal detects a sliding operation, it uses the Inspect function in DevEco Studio to identify the page element selected by the user's sliding operation, as well as the start time, end time, and duration of the sliding operation, and encapsulates them into a sliding event;

[0043] The click events and the sliding events are inserted into the corresponding positions of the recording file in chronological order and packaged into the automated test script.

[0044] According to the method of the first aspect of the present invention, in step S4: in response to the second terminal repeatedly executing the test file, the first terminal pushes the automated test script to the second terminal; the second terminal calls the automated test script and plays it back multiple times.

[0045] Example 1

[0046] In this embodiment, the method can be executed on the PC side, including: establishing a communication connection with a handheld terminal, the handheld terminal is used to receive user operations; starting recording, compiling the test file by itself and pushing it to the handheld terminal; monitoring the user operations received by the handheld terminal, and analyzing the operation type of the received user operations; when the operation type is a click operation or a sliding operation, analyzing the interface layout; for the above operations, combined with the interface layout structure, calling the event encapsulation method to generate an automated test script.

[0047] Furthermore, before starting recording, the corresponding interface script for starting recording is called.

[0048] Furthermore, the initialization operation includes: initializing the script generator to ensure that hdc_std is successfully connected; returning to the initial interface to wait for user operation.

[0049] Furthermore, the user operation received by the handheld terminal is monitored, and the operation type of the received user operation is analyzed, specifically including: monitoring the user operation received by the handheld terminal through a local thread; and analyzing the operation type of the received user operation through an hdc_std command.

[0050] Furthermore, according to the coordinates of the interface where the user clicks, combined with the layout structure, an event encapsulation method is called to generate an automated test script, specifically including: for a click operation, the click event coordinate information is read, and an event encapsulation method is called to generate a click event; for a sliding operation, an event encapsulation method is called to generate a sliding event, and the offset information corresponding to the sliding operation is determined according to the layout structure. When the sliding operation has an offset, the sliding event, the coordinate information corresponding to the sliding operation, and the offset are written into a py file; and the py file at the end of recording obtains the automated test script.

[0051] Furthermore, when playback is required, the automated test script is called and executed.

[0052] Example 2

[0053] The object to be tested is a handheld terminal, but the object to be tested includes but is not limited to all terminal devices (such as mobile phones, watches, tablets, etc.). The method provided by the present invention may include the following steps:

[0054] Step 1: Establish a connection with a handheld terminal, which is used to receive user operations;

[0055] hdc_std.exe list targets

[0056] Step 2: Reload the file system and change it to read-write mode;

[0057] hdc_std shell mount-o remount,rw /

[0058] Step 3: Load the file system to the specified mount point;

[0059] hdc_std target mount

[0060] Step 4: Compile and push the test file;

[0061] In some embodiments, the construction method is:

[0062] . / build.sh--product-name rk3568--build-target wukong

[0063] In some embodiments, the push method is:

[0064] hdc_std shell mount-o rw,remount /

[0065] hdc_std file send wukong /

[0066] hdc_std shell chmod a+x / wukong

[0067] hdc_std shell mv / wukong / bin /

[0068] Step 5: Start recording;

[0069] hdc_std shell wukong special -r [file name]

[0070] Step 6: Monitor user operations, and intelligently identify page element information under the coordinates based on the type of user operations and the start and end coordinates selected by the user;

[0071] hdc_std shell wukong special-S[file name]-s[starting point coordinates]-e[end point coordinates]

[0072] Step 7: Export the recorded content to PC;

[0073] hdc_std file recv / data / local / tmp / wukong. /

[0074] Step 8: Clear the recorded content of the handheld terminal to ensure smooth operation of the handheld terminal;

[0075] hdc_std shell rm-rf / data / local / tmp /

[0076] In some embodiments, the handheld terminal is in debugging mode and establishes a communication connection with the PC; when the PC starts recording, it first pushes the compiled test file to the handheld terminal to ensure that the UI automation can start normally, and then continues to monitor user operations. When the user operation is completed, the PC can end the current operation by killing the process. Finally, the recorded content is exported to the PC and the recorded content of the handheld terminal is cleared.

[0077] Example 3

[0078] The method provided by the present invention may further comprise the following steps:

[0079] Step 1: Establish a connection with a handheld terminal, which is used to receive user operations;

[0080] hdc_std.exe list targets

[0081] Step 2: Reload the file system and change it to read-write mode;

[0082] hdc_std shell mount-o remount,rw /

[0083] Step 3: Load the file system to the specified mount point;

[0084] hdc_std target mount

[0085] Step 4: Compile and push the test file to empty;

[0086] Step 5: Import the recording;

[0087] hdc_std file send.\wukong / data / local / tmp

[0088] Step 6: Play back the recorded content;

[0089] hdc_std shell wukong special -R [file name]

[0090] Step 7: Add random factors and dynamically adjust the waiting time;

[0091] Import random

[0092] Def dynamic_wait(min_wait,max_wait):

[0093] wait_time=random.uniform(min_wait,max_wait)

[0094] Time.sleep(wait_time)

[0095] Step 8: Clear the recorded content;

[0096] hdc_std shell rm-rf [recording content address]

[0097] In some embodiments, the handheld terminal is in debugging mode and establishes a communication connection with the PC; the PC pushes recorded content to the handheld terminal, plays back the recorded content, and then clears the recorded content in the handheld terminal to ensure smooth operation of the handheld terminal and improve operational efficiency.

[0098] The second aspect of the present invention discloses an electronic device. The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in the recording and playback method for automated test scripts described in the first aspect of the present disclosure are implemented.

[0099] The third aspect of the present invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the recording and playback method for automated test scripts described in the first aspect of the present disclosure.

[0100] In summary, through the technical solution of the present invention, testers do not need to pay attention to the underlying code implementation, thereby avoiding the testing difficulties caused by programming in different languages. The present invention is mainly used in the repeated regression testing phase. When the developer fixes a defect, in order to ensure that the current modification does not affect the original business or code, the recording and playback method is used to avoid occasional complex problems, save functional testing time, reduce repeated operations, thereby improving testing efficiency, and reducing the requirements for test engineers and reducing the human error rate.

[0101] Please note that the technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification. The above-mentioned embodiments only express several implementation methods of the present application, and their descriptions are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present application, several variations and improvements can be made, which all belong to the scope of protection of the present application. Therefore, the scope of protection of the patent in this application shall be based on the attached claims.

Claims

1. A recording and playback method suitable for automated test scripts. It is characterized in that The method comprises: Step S1, initializing a first terminal and a second terminal; wherein: the first terminal is a server, and the second terminal is a terminal to be tested; Step S2: the second terminal executes the test file pushed by the first terminal; wherein: the first terminal records the complete process of the second terminal executing the test file, and monitors the user operation received by the second terminal; Step S3, the first terminal generates an automated test script for the test file; wherein: the first terminal generates the automated test script based on the recorded second terminal executing the complete process of the test file and the monitored user interaction operations received by the second terminal, and identifies page elements and their attributes; Step S4, the second terminal plays back the automated test script; wherein: in response to the second terminal repeatedly executing the test file, intelligently identifying the state of page elements during the playback process, the first terminal pushes the automated test script to the second terminal for multiple playbacks.

2. A recording and playback method suitable for automated test scripts according to claim 1, It is characterized in that In the step S1: a communication connection is established between the first terminal and the second terminal; a test script generator is initialized at the first terminal; and the second terminal is configured to be in a readable and writable mode.

3. A recording and playback method suitable for automated test scripts according to claim 2, It is characterized in that In step S2: The first terminal uses the test script generator to generate a test file by compiling, and pushes the test file to the second terminal; the second terminal loads the test file to a designated loading point, and executes the test file; When the second terminal executes the test file, the first terminal records the entire process of the second terminal executing the test file and generates a recording file, and at the same time monitors the user operations received by the second terminal during the entire process of executing the test file through a local thread, and intelligently identifies page element selection and interaction; The user operation includes a click operation and a slide operation.

4. A recording and playback method suitable for automated test scripts according to claim 3, It is characterized in that In step S3: When the first terminal monitors the click operation, it uses the Inspect function in DevEco Studio to identify the page element selected by the user's click operation through the start coordinates and end coordinates of the user's click operation, and checks its properties to encapsulate it into a click event; When the first terminal monitors the sliding operation, the Inspect function in DevEco Studio is used to identify the page element selected by the user's sliding operation, as well as the start time, end time, and duration of the sliding operation through the start coordinates and end coordinates of the user's sliding operation, and encapsulate them into a sliding event; The click events and the sliding events are inserted into the corresponding positions of the recording file in chronological order and packaged into the automated test script.

5. A recording and playback method suitable for automated test scripts according to claim 4, It is characterized in that In the step S4: in response to the second terminal repeatedly executing the test file, the first terminal pushes the automated test script to the second terminal; The second terminal calls the automated test script and plays it back multiple times; During playback, the status of page elements is intelligently identified, and the exponential backoff method is used to dynamically adjust the waiting time.

6. An electronic device, It is characterized in that The electronic device includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the steps in a recording and playback method applicable to automated test scripts as described in any one of claims 1 to 5 are implemented.

7. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a recording and playback method applicable to automated test scripts as described in any one of claims 1 to 5 are implemented.

Citation Information

Patent Citations

  • Method and device for automatically generating test script and computer readable medium

    CN114356751A

  • Automated test script recording method, device, medium, equipment and system

    CN115794577A