Script recording method and device for automated testing, computer device and medium

By listening to page-triggered events and using a recursive algorithm to generate UI automated test scripts, the problem of low recording efficiency in existing technologies is solved, achieving highly automated script recording and reducing the skill requirements for recording personnel.

CN115481025BActive Publication Date: 2026-02-10CHINA PING AN LIFE INSURANCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211142757.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-20
Publication Date
2026-02-10
Estimated Expiration
2042-09-20

AI Technical Summary

Technical Problem

The existing technology for recording UI automation test scripts is inefficient, requiring manual recording of page element attribute information, resulting in poor script generation efficiency and susceptibility to page changes.

Method used

By listening to page-triggered events, a recursive algorithm is used to extract the document object model of the target element, determine the access path and location information, and generate an executable script. This process is highly automated and requires no knowledge of page element attributes.

Benefits of technology

It improves the efficiency of test script generation, reduces the skill requirements of recording personnel, and achieves efficient recording of automated tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115481025B_ABST
    Figure CN115481025B_ABST
Patent Text Reader

Abstract

The application relates to a script recording method and device for automated testing, computer equipment and a medium. When a recording start instruction is acquired, the method listens to a trigger event of a current page, determines an element corresponding to the trigger event as a target element when the trigger event meets a preset condition, extracts a document object model of the target element, uses a recursive algorithm to perform upward searching on the document object model until a root element label corresponding to the current page is found, determines access path and position information corresponding to the target element, extracts attribute information of the access path, determines a target selector corresponding to the access path according to the attribute information, acquires a recording end instruction, generates an executable script according to the access path, the position information and the target selector, obtains the script by triggering page information recording, has high automation and strong operability, does not need to understand the attributes of page elements, thereby reducing the ability requirement on a recording personnel and improving the generation efficiency of a test script.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated testing technology, and in particular to a method, apparatus, computer equipment, and medium for recording scripts for automated testing. Background Technology

[0002] Currently, recording User Interface (UI) tests is a crucial part of the testing process. UI automation testing tools can automate repetitive, time-consuming, and simple tasks, reducing testers' workload and improving testing efficiency. Before using UI automation testing tools to run test cases automatically, testers must first write test scripts as UI automation test cases. When recording UI automation test cases, it's necessary to select the page elements to be operated on in the test steps and record their relevant information as parameters for executing the script.

[0003] Recording test scripts using common automated testing frameworks typically requires installing specific applications on a computer, using dedicated debugging packages, and connecting the phone and computer via a data cable. While automated testing frameworks can assist in identifying the XPath of page elements, testers need to hard-code this information into the automated test script. Furthermore, to write high-quality automated test scripts, testers need to understand the relevant attributes of page elements in the test case execution actions, including page address, element XPath access path, element fullXPath access path, and element's page coordinates. They then need to select appropriate parameters based on the scenario of the test case steps. Otherwise, if page elements change and cause the test case to fail, the test script may need to be rewritten, resulting in a low recording success rate and poor test script generation efficiency. Therefore, how to automatically record test scripts to improve test script generation efficiency has become an urgent problem to be solved. Summary of the Invention

[0004] In view of this, embodiments of this application provide a method, apparatus, computer device, and medium for automatically recording test scripts to solve the problem of how to automatically record test scripts and improve the efficiency of test script generation.

[0005] In a first aspect, embodiments of this application provide a script recording method for automated testing, the script recording method comprising:

[0006] When a recording start command is received, the system listens for trigger events on the current page. If the trigger event meets a preset condition, the element corresponding to the trigger event is determined to be the target element.

[0007] Extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, thereby determining the access path and location information corresponding to the target element;

[0008] Extract the attribute information of the access path, and determine the target selector corresponding to the access path based on the attribute information;

[0009] Upon receiving the recording end command, an executable script is generated based on the access path, the location information, and the target selector.

[0010] In one embodiment, the script recording method further includes:

[0011] The communication results are obtained by communicating with the native code of the recording device through a JS plugin imported in the page manager;

[0012] When the communication result indicates that the recording device is in recording mode, it is determined that a recording start command has been obtained.

[0013] In one embodiment, after generating the executable script, the method further includes:

[0014] Switch the recording status of the recording device to non-recording mode;

[0015] If the result of communication between the JS plugin and the native recording device indicates that the recording device is not in a recording state, then script recording will stop.

[0016] In one implementation, listening for triggering events on the current page includes:

[0017] The JS plugin listens for trigger events on the current page.

[0018] When the trigger duration of the triggered event is detected to be greater than the duration threshold, it is determined that the triggered event meets the preset conditions.

[0019] In one implementation, after listening to the triggering event of the current page, the method further includes:

[0020] If the triggering event is detected to have stopped triggering, it is determined that a recording end command has been obtained;

[0021] Generating an executable script based on the access path, the location information, and the target selector includes:

[0022] A recording pop-up window is generated based on the access path, the location information, and the target selector;

[0023] Collect the case information entered in the recording pop-up window;

[0024] The case information is associated with the access path, the location information, and the target selector to generate an executable script.

[0025] In one embodiment, determining that the element corresponding to the triggering event is the target element includes:

[0026] Locate the trigger position of the event;

[0027] Based on the mapping table between the trigger location and the elements and positions on the current page, the target element corresponding to the trigger location is determined, wherein the target element is the element corresponding to the trigger event.

[0028] In one embodiment, determining the target selector corresponding to the access path based on the attribute information includes:

[0029] The attribute information is matched using preset matching rules to obtain matching results;

[0030] If the matching result contains an ID element, then the ID selector is selected as the target selector;

[0031] If the matching result is hierarchical, then the class selector is selected as the target selector;

[0032] If the matching result is a text node, then the content of the target element is obtained, and a search selector is generated based on the content, and the search selector is used as the target selector.

[0033] Secondly, embodiments of this application provide a script recording device for automated testing, the script recording device comprising:

[0034] The recording element determination module is used to listen for trigger events on the current page when a recording start command is received, and determine the element corresponding to the trigger event as the target element when the trigger event meets preset conditions.

[0035] The recording element parsing module is used to extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, thereby determining the access path and location information corresponding to the target element;

[0036] The selector determination module is used to extract the attribute information of the access path and determine the target selector corresponding to the access path based on the attribute information.

[0037] The script generation module is used to generate an executable script based on the access path, the location information, and the target selector when the recording end instruction is received.

[0038] In one embodiment, the script recording device further includes:

[0039] The communication module is used to communicate with the native recording device through a JS plugin imported in the page manager and obtain the communication results.

[0040] The start command determination module is used to determine that a recording start command has been obtained when the communication result indicates that the recording device is in a recording state.

[0041] In one embodiment, the script recording device further includes:

[0042] The state switching module is used to switch the recording state of the recording device to a non-recording state after generating the executable script;

[0043] The stop recording module is used to stop script recording if the result of communication between the JS plugin and the native recording device indicates that the recording device is not in a recording state.

[0044] In one embodiment, the recording element determination module includes:

[0045] The event listening unit is used to listen for event triggering on the current page through the JS plugin;

[0046] The event determination unit is used to determine that the triggering event meets preset conditions when the triggering duration of the triggering event is detected to be greater than the duration threshold.

[0047] In one embodiment, the script recording device further includes:

[0048] The end command determination module is used to determine that a recording end command has been obtained if the triggering event stops triggering after listening to the triggering event of the current page.

[0049] The script generation module includes:

[0050] A pop-up generation unit is used to generate a recording pop-up based on the access path, the location information, and the target selector;

[0051] An information collection unit is used to collect the case information entered in the recording pop-up window;

[0052] The script generation unit is used to associate the case information with the access path, the location information, and the target selector to generate an executable script.

[0053] In one embodiment, the recording element determination module includes:

[0054] A location positioning unit is used to locate the triggering position of the triggering event;

[0055] An element determination unit is used to determine the target element corresponding to the trigger position based on the trigger position and the mapping table of elements and positions in the current page, wherein the target element is the element corresponding to the trigger event.

[0056] In one embodiment, the selector determination module includes:

[0057] The matching unit is used to match the attribute information with a preset matching rule to obtain a matching result;

[0058] The first selector determining unit is configured to select an ID selector as the target selector if the matching result contains an ID element.

[0059] The second selector determination unit is used to select a class selector as the target selector if the matching result is hierarchical.

[0060] The third selector determination unit is used to obtain the content of the target element if the matching result is a text node, generate a search selector based on the content, and use the search selector as the target selector.

[0061] Thirdly, embodiments of this application provide a computer device, the computer device including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the script recording method as described in the first aspect.

[0062] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the script recording method as described in the first aspect.

[0063] The beneficial effects of this application embodiment compared with the prior art are as follows: When a recording start instruction is obtained, this application listens for trigger events on the current page. When the trigger event meets preset conditions, the element corresponding to the trigger event is determined as the target element. The document object model of the target element is extracted, and a recursive algorithm is used to search upwards on the document object model until the root element tag corresponding to the current page is found. The access path and location information corresponding to the target element are determined, and the attribute information of the access path is extracted. Based on the attribute information, the target selector corresponding to the access path is determined. When a recording end instruction is obtained, an executable script is generated based on the access path, the location information, and the target selector. The script is obtained by recording through trigger page information, which has a high degree of automation and strong operability. It does not require knowledge of the attributes of page elements, thereby reducing the ability requirements of the recording personnel and improving the generation efficiency of test scripts. Attached Figure Description

[0064] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0065] Figure 1 This is a schematic diagram of an application environment for an automated testing script recording method provided in Embodiment 1 of this application;

[0066] Figure 2 This is a flowchart illustrating an automated testing script recording method provided in Embodiment 2 of this application;

[0067] Figure 3 This is a flowchart illustrating an automated testing script recording method provided in Embodiment 3 of this application;

[0068] Figure 4 This is a schematic diagram of the structure of an automated testing script recording device provided in Embodiment 4 of this application;

[0069] Figure 5 This is a schematic diagram of the structure of a computer device provided in Embodiment 5 of this application. Detailed Implementation

[0070] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0071] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0072] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0073] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0074] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0075] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0076] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.

[0077] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0078] It should be understood that the sequence number of each step in the following embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0079] To illustrate the technical solution of this application, specific embodiments are described below.

[0080] The script recording method for automated testing provided in Embodiment 1 of this application can be applied to, for example, Figure 1 In this application environment, the client communicates with the server. Clients include, but are not limited to, handheld computers, desktop computers, laptops, ultra-mobile personal computers (UMPCs), netbooks, cloud computing devices, and personal digital assistants (PDAs). The server can be implemented using a standalone server or a server cluster consisting of multiple servers.

[0081] See Figure 2 This is a flowchart illustrating an automated testing script recording method provided in Embodiment 2 of this application. The aforementioned automated testing script recording method is applied to... Figure 1 The server-side component in this application is equipped with a computer device capable of supporting the application (APP) running on the client side to display corresponding pages. In this application, the page can be an HTML5 page formed using Hyper Text Markup Language (HTML). The user performs corresponding operations on the page displayed in the APP, and the server collects the corresponding operation information to execute a script recording method. Figure 2 As shown, the script recording method for this automated test may include the following steps:

[0082] Step S201: When the recording start command is received, listen for the trigger event on the current page. When the trigger event meets the preset conditions, determine the element corresponding to the trigger event as the target element.

[0083] In this application, the user starts the recording mode in the client's APP, that is, gives a recording start command. The server connected to the client (i.e. the execution device of the script recording method of this application) can obtain the recording start command after the client gives the recording start command, and thus enter the process of listening to the triggering event of the current page.

[0084] The current page is the page that the user opens in the client's APP. This page can be developed based on HTML5. The current page displays corresponding elements, such as images and text, and each element corresponds to its position on the current page.

[0085] Every element on the current page can be triggered, forming a trigger event. Triggering can refer to performing corresponding operations through mouse operation, touch screen operation, or other input devices. Operations can refer to clicking, dragging, etc.

[0086] The preset conditions are set according to requirements to determine the target element. Since there may be multiple elements on the current page, and users may trigger an event targeting a specific element, accidental operation is possible. Therefore, these preset conditions are set to prevent accidental selection of the target element. The purpose of these preset conditions is to prevent accidental operation; therefore, different preset conditions can be set based on the understanding of accidental operation. For example, the preset condition can be a duration threshold. If the trigger duration of the event is less than this duration threshold, it can be considered an accidental operation; if the trigger duration of the event is greater than or equal to this duration threshold, it can be considered a normal operation.

[0087] The purpose of triggering an event is to trigger a specific element on the current page. When the triggering event meets the conditions, the corresponding element can be identified as the target element, which means that the user wants to record the target element.

[0088] Optionally, determining the element that triggered the event as the target element includes:

[0089] Locate the trigger point of the event;

[0090] Based on the mapping table between the trigger location and the elements and positions on the current page, determine the target element corresponding to the trigger location, where the target element is the element corresponding to the trigger event.

[0091] In essence, a triggering event targets a specific location on the page. This location may or may not contain elements. Therefore, after receiving a triggering event that meets preset conditions, the triggering location is positioned. Positioning can be categorized as relative positioning, absolute positioning, fixed positioning, and static positioning. Relative positioning moves the element relative to its previous position in the normal flow, while absolute positioning positions it relative to the body.

[0092] Each page has a mapping table between elements and their positions, so the corresponding element can be determined based on the starting position.

[0093] Step S202: Extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, and determine the access path and location information corresponding to the target element.

[0094] In this application, the Document Object Model (DOM) of the target element is the element's DOM, which is a standard programming interface for processing Extensible Markup Language (EXPLAIN). It is a platform- and language-independent Application Programming Interface (API) that allows dynamic access to programs and scripts to update their content, structure, and style. HTML and XML documents are defined through specification sections. The document can be further processed, and the results can be added to the current page. The DOM is essentially a tree-based API document, requiring the entire document to be represented in memory during processing.

[0095] When creating an HTML5 webpage, each element corresponds to a DOM element. By recursively searching upwards from this DOM element, the root element of that DOM element, which is the root element (HTML tag) of the current page, can be found. From this root element (HTML tag) to the element's tags, the access path of that element can be determined. This access path can include XPath (relative path) and FullXPath (absolute path), thus determining the element's coordinates and other positional information within the current page.

[0096] Step S203: Extract the attribute information of the access path, and determine the target selector corresponding to the access path based on the attribute information.

[0097] In this application, attribute information can refer to information in the access path that can characterize element features. Element features can refer to attribute features such as the category of a page element. For example, if a page element contains dynamic attributes, then the page element can be determined to be a dynamic page element. The first feature is distinguished from the second feature. The first feature can refer to the ID attribute in a page element, while the second feature can refer to the dynamic attribute in a page element. When a page element contains an ID attribute, that is, when the element feature contains the first feature, an ID selector is used to generate the corresponding page element path. When a page element contains dynamic attributes, that is, when the element feature contains the second feature, a class selector is used to generate the corresponding page element path.

[0098] It should be understood that multiple page elements can exist simultaneously within a single page. Similarly, multiple page elements can exist simultaneously within a test case. Different selectors can be used to generate page paths for different page elements, which helps to distinguish between different page elements and achieve accurate and efficient positioning of page elements.

[0099] Recording requires the use of element paths, which are generated by corresponding generation rules. These rules can be set according to actual application requirements. For example, if the application scenario requires test cases to not contain dynamic elements, then it is not necessary to use specific element path generation rules. In this case, specific element path generation rules could refer to the rules corresponding to ID selectors and class selectors, in which case regular path generation rules would suffice.

[0100] The above element path generation rules are used when recording test cases. The generation rules are determined based on the user's selection, and the selected element path generation rules are used to generate page element paths for the test cases.

[0101] Optionally, based on the attribute information, the target selector corresponding to the access path includes:

[0102] The matching results are obtained by matching the attribute information with the preset matching rules.

[0103] If the matching result contains an ID element, then the ID selector is selected as the target selector;

[0104] If the matching result is a variable level, then the class selector is selected as the target selector;

[0105] If the matching result is a text node, the content of the target element is obtained, and a search selector is generated based on the content. The search selector is then used as the target selector.

[0106] The preset matching rules can include various matching conditions such as matching ID elements, variable levels, and text nodes. The corresponding selectors can include ID selectors, class selectors, and text selectors. Specifically, if the page element path contains an ID, the ID selector should be used first to generate the script; to avoid adding ID operations to the business code, if the page element path contains dynamic elements during recording, the class selector can be used first to generate the script; when the page element is identified as a text node and the corresponding content is not empty, its node text content can be recorded, a query text selector can be generated, and the text selector can be used to generate the script.

[0107] As can be seen, when an element path contains an `id` element, the `id` should be used as the selector to improve the success rate of script tests. When the path contains class selectors for common UI components such as pop-ups, these are usually dynamically generated on the page, and the hierarchy of element XPaths is not fixed. Therefore, class should be used as the selector to improve the success rate of script tests. When the element is a text node, a selector is automatically generated based on the element's content, and the sequence of child elements is ignored, which can reduce the probability of XPath failure when page functionality changes.

[0108] Step S204: Upon receiving the recording end instruction, generate an executable script based on the access path, location information, and target selector.

[0109] In this application, the basic data required for the test script are the access path, location information, and target selector. Based on this, the corresponding elements can be uniquely determined, and thus can be used to construct the test script for execution and implementation testing.

[0110] Optionally, script recording methods also include:

[0111] The communication results are obtained by communicating with the native code of the recording device through a JS plugin imported in the page manager;

[0112] When the communication result indicates that the recording device is in recording mode, it is determined that a recording start command has been obtained.

[0113] Among them, the page supported by the aforementioned server needs to collect the user's operations on the APP's display page. At this time, a custom JS (JavaScript) plugin can be introduced in the page manager to communicate with the native part of the APP, thereby obtaining the user's operations in the APP. The recording device is also the client. For example, when the user starts recording in the APP, the corresponding communication result obtained through the native part is that the client is in recording state, that is, the recording start command is obtained.

[0114] Optionally, after generating the executable script, the following may also be included:

[0115] Switch the recording device to a non-recording state;

[0116] If the result of communication between the JS plugin and the native recording device is that the recording device is not in recording mode, then script recording will stop.

[0117] Once the executable script is generated, recording is complete, and the recording state switches to non-recording state. The communication result obtained through native means that the script recording has stopped.

[0118] Optionally, the events to be listened to on the current page include:

[0119] Listen for triggered events on the current page using a JS plugin;

[0120] When the trigger duration of a triggered event is detected to be greater than the duration threshold, it is determined that the triggered event meets the preset conditions.

[0121] When a JS plugin is introduced, the listening functionality can be integrated into the plugin. This involves the plugin listening for page events, parsing the triggered events, and obtaining the event duration to determine whether the user triggered the event for a long or short period. Events shorter than a duration threshold are considered short-term triggers, while those longer are considered long-term triggers. Since short-term triggers might be false triggers, the duration threshold is used as a preset condition.

[0122] In this embodiment, upon receiving a recording start command, the system listens for trigger events on the current page. When a trigger event meets preset conditions, the element corresponding to the trigger event is identified as the target element. The document object model of the target element is extracted, and a recursive algorithm is used to search upwards through the document object model until the root element tag of the current page is found. The access path and location information corresponding to the target element are determined, and the attribute information of the access path is extracted. Based on the attribute information, the target selector corresponding to the access path is determined. Upon receiving a recording end command, an executable script is generated based on the access path, location information, and target selector. The script is obtained by recording based on the trigger page information, resulting in a high degree of automation and strong operability. It does not require knowledge of the page element attributes, thereby reducing the skill requirements for recording personnel and improving the efficiency of test script generation.

[0123] See Figure 3 This is a flowchart illustrating an automated testing script recording method provided in Embodiment 3 of this application. Figure 3 As shown, the script recording method for this automated test may include the following steps:

[0124] Step S301: When the recording start command is received, listen for the trigger event on the current page. When the trigger event meets the preset conditions, determine the element corresponding to the trigger event as the target element.

[0125] Step S302: Extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, and determine the access path and location information corresponding to the target element.

[0126] Step S303: Extract the attribute information of the access path, and determine the target selector corresponding to the access path based on the attribute information.

[0127] Steps S301 to S303 are the same as those steps S201 to S203 above, and can be referred to the description of steps S201 to S203, which will not be repeated here.

[0128] Step S304: If the triggering event is detected to stop triggering, it is determined that the recording end command has been obtained.

[0129] In this application, during recording, the user needs to continuously trigger the corresponding element, that is, continuously trigger the element on the motor page, until the required recording duration is reached. This recording duration can be set according to requirements. It should be noted that if the aforementioned duration threshold is used during the process, the recording duration can be equal to or greater than the duration threshold.

[0130] In step S301, the trigger event is monitored, thus allowing real-time acquisition of the trigger start time and trigger end time. The trigger end time is also the time when the trigger event stops, at which point it can be determined that the recording end command has been obtained. Of course, the recording end command can also be obtained by the user operating the APP, in which case the trigger duration of the trigger event does not need to meet the recording duration.

[0131] Step S305: Generate a recording pop-up window based on the access path, location information, and target selector.

[0132] In this application, after the stop is triggered, a corresponding recording pop-up window is generated. The recording pop-up window can display information such as the access path, location information, and target selector. At the same time, the user can fill in the corresponding case information to realize customization, naming, etc., so as to facilitate the subsequent differentiation of the recorded scripts.

[0133] Step S306: Collect the case information entered in the recording pop-up window, associate the case information with the access path, location information and target selector, and generate an executable script.

[0134] In this application, after the user enters case information in the recording pop-up window, the case information is associated with the access path, location information and target selector to generate a corresponding executable script. In addition to information such as naming, the case information may also include information such as script execution conditions, which are used to execute the corresponding script under the corresponding execution conditions.

[0135] In this embodiment, upon receiving a recording start command, the system listens for trigger events on the current page. When a trigger event meets preset conditions, the element corresponding to the trigger event is identified as the target element. The document object model of the target element is extracted, and a recursive algorithm is used to search upwards through the document object model until the root element tag of the current page is found. The access path and location information corresponding to the target element are determined, and the attribute information of the access path is extracted. Based on the attribute information, the target selector corresponding to the access path is determined. If the trigger event is detected to stop triggering, a recording end command is obtained. Based on the access path, location information, and target selector, a recording pop-up is generated. The case information entered in the recording pop-up is collected, and the case information is associated with the access path, location information, and target selector to generate an executable script. The script is obtained by recording triggered page information, which has a high degree of automation and strong operability. It does not require knowledge of the attributes of page elements, thereby reducing the ability requirements of the recording personnel and improving the efficiency of test script generation.

[0136] Corresponding to the script recording method for automated testing in the above embodiments, Figure 4 This diagram illustrates a structural block diagram of an automated testing script recording device provided in Embodiment 4 of this application. The script recording device is applied to… Figure 1 The server-side component in this application is equipped with a computer device capable of supporting the corresponding client-side APP, which displays relevant pages on the client. In this application, the page can be an HTML5 page. Users perform corresponding operations on the pages displayed in the APP, and the server collects the corresponding operation information to execute a script recording method. For ease of explanation, only the parts relevant to the embodiments of this application are shown.

[0137] See Figure 4 The script recording device includes:

[0138] The recording element determination module 41 is used to listen to the trigger event of the current page when the recording start instruction is received, and determine the element corresponding to the trigger event as the target element when the trigger event meets the preset conditions.

[0139] The recording element parsing module 42 is used to extract the document object model of the target element. It uses a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, and determines the access path and location information of the target element.

[0140] Selector determination module 43 is used to extract the attribute information of the access path and determine the target selector corresponding to the access path based on the attribute information.

[0141] The script generation module 44 is used to generate an executable script based on the access path, location information, and target selector when the recording end command is received.

[0142] Optionally, the above-mentioned script recording device also includes:

[0143] The communication module is used to communicate with the native recording device through a JS plugin imported in the page manager and obtain the communication results.

[0144] The start command determination module is used to determine that a recording start command has been obtained when the communication result indicates that the recording device is in recording mode.

[0145] Optionally, the above-mentioned script recording device also includes:

[0146] The state switching module is used to switch the recording state of the recording device to a non-recording state after the executable script is generated;

[0147] The Stop Recording module is used to stop script recording if the recording device is not in recording mode when communicating with the native recording device via the JS plugin.

[0148] Optionally, the recording element determination module 41 mentioned above includes:

[0149] The event listener unit is used to listen for events triggered on the current page via a JS plugin;

[0150] The event determination unit is used to determine that the triggering event meets preset conditions when the triggering duration of the detected event exceeds the duration threshold.

[0151] Optionally, the above-mentioned script recording device also includes:

[0152] The end command determination module is used to determine whether a recording end command has been obtained if the triggering event stops being detected after listening to the triggering event on the current page.

[0153] The script generation module 44 mentioned above includes:

[0154] The pop-up generation unit is used to generate recording pop-ups based on the access path, location information, and target selector.

[0155] The information collection unit is used to collect case information entered in the recording pop-up window;

[0156] The script generation unit is used to associate case information with access paths, location information, and target selectors to generate executable scripts.

[0157] Optionally, the recording element determination module 41 mentioned above includes:

[0158] The location positioning unit is used to locate the trigger position of the triggering event;

[0159] The element determination unit is used to determine the target element corresponding to the trigger position based on the trigger position and the mapping table of elements and positions on the current page. The target element is the element corresponding to the trigger event.

[0160] Optionally, the selector determining module 43 mentioned above includes:

[0161] The matching unit is used to match the attribute information with preset matching rules to obtain the matching result;

[0162] The first selector determination unit is used to select the ID selector as the target selector if the matching result contains an ID element.

[0163] The second selector determination unit is used to select the class selector as the target selector if the matching result is a variable level.

[0164] The third selector determination unit is used to obtain the content of the target element if the matching result is a text node, generate a search selector based on the content, and use the search selector as the target selector.

[0165] It should be noted that the information interaction and execution process between the above modules are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, which will not be repeated here.

[0166] Figure 5 This is a schematic diagram of the structure of a computer device provided in Embodiment 5 of this application. Figure 5 As shown, the computer device of this embodiment includes: at least one processor ( Figure 5 Only one is shown in the diagram), a memory, and a computer program stored in the memory and executable on at least one processor, which, when executed by the processor, implements the steps in the script recording method embodiments for any of the above-described automated tests.

[0167] This computer device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 5The examples of computer devices are merely examples and do not constitute a limitation on computer devices. Computer devices may include more or fewer components than shown in the illustration, or combinations of certain components, or different components, such as network interfaces, displays, and input devices.

[0168] The processor referred to can be a CPU, but it can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0169] Memory includes readable storage media, internal memory, etc., wherein internal memory can be the RAM of a computer device, providing an environment for the operation of the operating system and computer-readable instructions stored in the readable storage media. The readable storage media can be the hard drive of a computer device, or in other embodiments, it can be an external storage device of the computer device, such as a plug-in hard drive, Smart Media Card (SMC), Secure Digital (SD) card, or Flash Card. Furthermore, memory can include both internal storage units and external storage devices of a computer device. Memory is used to store the operating system, applications, bootloader, data, and other programs, such as program code for computer programs. Memory can also be used to temporarily store data that has been output or will be output.

[0170] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above device can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here. If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the above method embodiments. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. A computer-readable medium can include at least: any entity or device capable of carrying computer program code, a recording medium, a computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0171] The implementation of all or part of the processes in the methods of the above embodiments can also be accomplished by a computer program product. When the computer program product is run on a computer device, it enables the computer device to execute the steps in the above method embodiments.

[0172] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0173] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0174] In the embodiments provided in this application, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0175] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0176] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for recording scripts for automated testing, characterized in that, The script recording method includes: When a recording start command is received, the system listens for trigger events on the current page. If the trigger event meets a preset condition, the element corresponding to the trigger event is determined to be the target element. Extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, thereby determining the access path and location information corresponding to the target element; Extract the attribute information of the access path, and determine the target selector corresponding to the access path based on the attribute information; Upon receiving the recording end command, an executable script is generated based on the access path, the location information, and the target selector. The communication results are obtained by communicating with the native code of the recording device through a JS plugin imported in the page manager; The events triggered by the current page that are being monitored include: The JS plugin listens for trigger events on the current page; When the trigger duration of the triggered event is detected to be greater than the duration threshold, it is determined that the triggered event meets the preset conditions; The step of determining the target selector corresponding to the access path based on the attribute information includes: The attribute information is matched using preset matching rules to obtain matching results; If the matching result contains an ID element, then the ID selector is selected as the target selector; If the matching result is hierarchical, then the class selector is selected as the target selector; If the matching result is a text node, then the content of the target element is obtained, and a search selector is generated based on the content, and the search selector is used as the target selector; This includes: when the element path contains an id element, the id is selected as the selector; when the class selector of the UI component of the page pop-up is included, the class is selected as the selector because the page is dynamically generated and the element XPath hierarchy is not fixed; when the element is a text node, a selector is automatically generated to search by element content, and the sequence of child elements is ignored.

2. The script recording method according to claim 1, characterized in that, The script recording method also includes: When the communication result indicates that the recording device is in recording mode, it is determined that a recording start command has been obtained.

3. The script recording method according to claim 2, characterized in that, After generating the executable script, the following is also included: Switch the recording status of the recording device to non-recording mode; If the result of communication between the JS plugin and the native code of the recording device indicates that the recording device is not in a recording state, then script recording will stop.

4. The script recording method according to claim 1, characterized in that, After listening for events triggered on the current page, it also includes: If the triggering event is detected to have stopped triggering, it is determined that a recording end command has been obtained; Generating an executable script based on the access path, the location information, and the target selector includes: A recording pop-up window is generated based on the access path, the location information, and the target selector; Collect the case information entered in the recording pop-up window; The case information is associated with the access path, the location information, and the target selector to generate an executable script.

5. The script recording method according to claim 1, characterized in that, Determining the element corresponding to the triggering event as the target element includes: Locate the trigger position of the event; Based on the mapping table between the trigger location and the elements and positions on the current page, the target element corresponding to the trigger location is determined, wherein the target element is the element corresponding to the trigger event.

6. A script recording apparatus for automated testing, used to implement the script recording method for automated testing as described in any one of claims 1 to 5, characterized in that, The script recording device includes: The recording element determination module is used to listen for trigger events on the current page when a recording start command is received, and determine the element corresponding to the trigger event as the target element when the trigger event meets preset conditions. The recording element parsing module is used to extract the document object model of the target element, and use a recursive algorithm to search upwards in the document object model until the root element tag corresponding to the current page is found, thereby determining the access path and location information corresponding to the target element; The selector determination module is used to extract the attribute information of the access path and determine the target selector corresponding to the access path based on the attribute information. The script generation module is used to generate an executable script based on the access path, the location information, and the target selector when the recording end instruction is received.

7. A computer device, characterized in that, The computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the script recording method as described in any one of claims 1 to 5.

8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the script recording method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Method and device for testing user interface

    CN107102937A

  • Test script recording method, application program test method and related devices

    CN110716853A