Method and device for generating test scripts
By obtaining the user's click coordinates, determining the visible area and control attributes of interface elements, and generating test scripts based on priority and attribute information, it solves the problem of difficult correlation of click actions on complex interfaces and improves the accuracy and efficiency of test scripts.
Patent Information
- Application Number
- CN202010371295.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-06
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2040-05-06
AI Technical Summary
On complex interfaces, it is difficult to accurately determine the coordinates corresponding to user clicks and bind them to interface elements, which limits the efficiency and accuracy of automated test script generation.
By obtaining the user's click coordinates, the visible area of the interface element is determined, each element is traversed, the control attribute information is obtained, the target control is determined based on the priority and attribute information, and a test script is generated based on keywords.
Improved the accuracy of target controls and the efficiency of test script generation, ensuring that click operations are associated with the correct controls.
Smart Images

Figure CN113626301B
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of computer technology, and in particular to a method and device for generating a test script. Background Art
[0002] As technology continues to advance, the interfaces presented by terminals are becoming more diverse and complex. When developing an interface, testing the interface is an essential step, and test scripts are an important basis for testing.
[0003] In the process of implementing this application, the inventor discovered that the user's click action is actually targeted at a coordinate in the page, and there will be many interface elements covering this coordinate point on a complex interface. Therefore, how to find a suitable interface element to bind it is an important step in automatically generating test scripts. Summary of the invention
[0004] The embodiments of the present disclosure provide a method and apparatus for generating a test script.
[0005] In a first aspect, an embodiment of the present disclosure provides a method for generating a test script, the method comprising: in response to obtaining the click coordinates of a user performing a click operation on a current interface, determining the interface elements of the current interface and the visible area of the interface elements; traversing the visible areas of each interface element, determining a target visible area containing the click coordinates and controls associated with the interface elements corresponding to the target visible area; obtaining attribute information of each control associated with the interface element corresponding to the target visible area, and determining the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determining a keyword of the target control based on the attribute information of the target control; and generating a test script corresponding to the click operation based on the keyword of the target control.
[0006] In some embodiments, the attribute information of the control includes resource identification information and / or text information, the resource identification information identifies the resources loaded by the control, and the text information represents the text displayed on the control; and based on the attribute information of each control associated with the interface element corresponding to the target visible area, the target control associated with the click coordinates is determined, including: determining the priority of each control based on the resource identification information and / or text information of the control, and determining the target control associated with the click coordinates based on the priority of each control.
[0007] In some embodiments, the priority of each control is determined based on the resource identification information and / or text information of the control, including: determining the priority of a control whose resource identification information is unique as the first priority; determining the priority of a control whose resource identification information is not unique and whose text information meets a first preset condition as the second priority, wherein the first preset condition includes: the length of the text information exceeds a preset length, the text information is not unique, or the text information contains abnormal characters; determining the priority of a control whose resource identification information is not unique and whose text information meets a second preset condition as the third priority, wherein the second preset condition includes: the length of the text information does not exceed a preset length and there are no abnormal characters; determining the priority of a control whose resource identification information is invalid and whose text information is valid and unique as the fourth priority.
[0008] In some embodiments, the target control associated with the click coordinates is determined based on the priority of each control, including: sorting the controls based on the priority of each control, and determining the controls with a preset number of controls in the front as the target controls associated with the click coordinates.
[0009] In some embodiments, based on the attribute information of the target control, the keyword of the target control is determined, including at least one of: in response to determining that the priority of the target control is the first priority, determining the resource identification information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the second priority, determining the resource identification information in the attribute information of the target control and the index of the resource identification information as the keyword of the target control, wherein the index is used to filter out the target control from multiple controls with the same resource identification information; in response to determining that the priority of the target control is the third priority, determining the text information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the fourth priority, determining the text information in the attribute information of the target control as the keyword of the target control.
[0010] In some embodiments, based on the keyword of the target control, a test script corresponding to the click operation is generated, including: in response to the ratio of the area of the target control to the interface area of the current interface not exceeding a first preset value, associating the click operation to the keyword of the target control in the test script.
[0011] In some embodiments, based on the keyword of the target control, a test script corresponding to the click operation is generated, and the method also includes: in response to the ratio of the area of the target control to the interface area of the current interface exceeding a first preset value but not exceeding a second preset value, associating the click operation to the keyword of the target control in the test script, and adding an annotation to the test script to mark the location where the user clicked.
[0012] In some embodiments, a test script corresponding to a click operation is generated based on a keyword of a target control, and also includes: in response to a ratio of the area of the target control to the interface area of the current interface exceeding a second preset value, variable coordinates are generated based on the click coordinates and the size of the display screen, and the click operation is associated with the variable coordinates in the test script, and a comment is added in the test script to mark the target control associated with the click operation.
[0013] In a second aspect, an embodiment of the present disclosure provides a device for generating a test script, the device comprising: a visible area determination unit, configured to determine the interface elements of the current interface and the visible area of the interface elements in response to obtaining the click coordinates of a user performing a click operation on the current interface; an associated control determination unit, configured to traverse the visible areas of each interface element, determine a target visible area containing the click coordinates and controls associated with the interface elements corresponding to the target visible area; a keyword determination unit, configured to obtain attribute information of each control associated with the interface element corresponding to the target visible area, and determine the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the keyword of the target control based on the attribute information of the target control; a generation unit, configured to generate a test script corresponding to the click operation based on the keyword of the target control.
[0014] In some embodiments, the attribute information of the control includes resource identification information and / or text information, the resource identification information identifies the resources loaded by the control, and the text information represents the text displayed on the control; and a keyword determination unit includes: a target control determination module, configured to determine the priority of each control based on the resource identification information and / or text information of the control, and determine the target control associated with the click coordinates based on the priority of each control.
[0015] In some embodiments, the target control determination module is further configured to: determine the priority of the control whose resource identification information is unique as the first priority; determine the priority of the control whose resource identification information is not unique and whose text information meets the first preset condition as the second priority, wherein the first preset condition includes: the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters; determine the priority of the control whose resource identification information is not unique and whose text information meets the second preset condition as the third priority, wherein the second preset condition includes: the length of the text information does not exceed the preset length and there are no abnormal characters; determine the priority of the control whose resource identification information is invalid and whose text information is valid and unique as the fourth priority.
[0016] In some embodiments, the target control determination module is further configured to: sort the controls based on the priority of each control, and determine the controls with a preset number of controls in the front as the target controls associated with the click coordinates.
[0017] In some embodiments, a keyword determination unit includes: a keyword determination module; and the keyword determination module is configured to be at least one of the following: in response to determining that the priority of the target control is the first priority, determining the resource identification information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the second priority, determining the resource identification information in the attribute information of the target control and the index of the resource identification information as the keyword of the target control, wherein the index is used to filter out the target control from multiple controls with the same resource identification information; in response to determining that the priority of the target control is the third priority, determining the text information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the fourth priority, determining the text information in the attribute information of the target control as the keyword of the target control.
[0018] In some embodiments, the generating unit is further configured to: in response to the ratio of the area of the target control to the interface area of the current interface not exceeding a first preset value, associate the click operation with a keyword of the target control in the test script.
[0019] In some embodiments, the generation unit is further configured to: in response to the area of the target control accounting for a ratio of the interface area of the current interface exceeding a first preset value but not exceeding a second preset value, associate the click operation with a keyword of the target control in the test script, and add a comment in the test script to mark the location where the user clicked.
[0020] In some embodiments, the generation unit is further configured to: in response to the ratio of the area of the target control to the interface area of the current interface exceeding a second preset value, generate variable coordinates based on the click coordinates and the size of the display screen, and associate the click operation to the variable coordinates in the test script, and add a comment in the test script to mark the target control associated with the click operation.
[0021] In a third aspect, an embodiment of the present disclosure provides an electronic device, comprising: one or more processors; a storage device on which one or more programs are stored; when the one or more programs are executed by one or more processors, the one or more processors implement a method for generating a test script as described in any embodiment of the first aspect.
[0022] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the method for generating a test script as described in any embodiment of the first aspect.
[0023] The method and device for generating a test script provided by the embodiments of the present disclosure first determine the interface elements of the current interface and the visible area of the interface elements in response to obtaining the click coordinates of a user performing a click operation on the current interface, then traverse the visible area of the interface elements to determine the target visible area containing the click coordinates and the controls associated with the interface elements corresponding to the target visible area, then obtain the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the keyword of the target control based on the attribute information of the target control, and finally generate a test script corresponding to the click operation based on the keyword of the target control, which can accurately and quickly determine the target control associated with the click coordinates, thereby improving the accuracy of the target control, and can automatically generate a test script according to the keyword of the target control, thereby improving the efficiency of generating a test script. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0025] Figure 1 is an exemplary system architecture diagram in which an embodiment of the present disclosure may be applied;
[0026] Figure 2 is a flowchart of an embodiment of a method for generating a test script according to an embodiment of the present disclosure;
[0027] Figure 3 is a schematic diagram of an application scenario of a method for generating a test script according to an embodiment of the present disclosure;
[0028] Figure 4 is an exemplary flow chart of generating a test script according to an embodiment of the present disclosure;
[0029] Figure 5 is a structural schematic diagram of an embodiment of a device for generating a test script according to an embodiment of the present disclosure;
[0030] Figure 6 It is a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. DETAILED DESCRIPTION
[0031] The present disclosure is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant disclosure, rather than to limit the disclosure. It is also necessary to explain that, for ease of description, only the parts related to the relevant disclosure are shown in the accompanying drawings.
[0032] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0033] Figure 1 An exemplary system architecture 100 is shown to which the method for generating a test script and the apparatus for generating a test script according to the embodiments of the present disclosure can be applied.
[0034] like Figure 1 As shown, the system architecture 100 may include terminal devices 104, 105, a network 106, and servers 101, 102, 103. The network 106 is used to provide a medium for communication links between the terminal devices 104, 105 and the servers 101, 102, 103. The network 106 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0035] Users can interact with servers 101, 102, 103 through terminal devices 104, 105 via network 106 to receive or send information, etc. Various applications can be installed on terminal devices 104, 105, such as data analysis applications, data processing applications, instant messaging tools, social platform software, search applications, shopping applications, etc.
[0036] The terminal devices 104 and 105 can be hardware or software. When the terminal device is hardware, it can be various electronic devices with a display screen and supporting communication with the server, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, etc. When the terminal device is software, it can be installed in the electronic devices listed above. It can be implemented as multiple software or software modules, or as a single software or software module. No specific limitation is made here.
[0037] The terminal devices 104 and 105 can be terminals with interface display, interface element analysis and test script generation functions (such as smart devices with screen and data analysis functions, etc.). The terminal devices 104 and 105 can receive the click operation of the tester, obtain the click coordinates corresponding to the click operation, and then generate the test script corresponding to the click operation locally according to the click coordinates. The terminal devices 104 and 105 can also send the click coordinates to the server, and the server generates the test script corresponding to the click operation according to the click coordinates.
[0038] Servers 101, 102, and 103 may be servers that provide various services, such as a backend server that receives a request sent by a terminal device that establishes a communication connection with the backend server. The backend server may receive and analyze the request sent by the terminal device and generate a processing result.
[0039] It should be noted that the server can be hardware or software. When the server is hardware, it can be various electronic devices that provide various services to the terminal device. When the server is software, it can be implemented as multiple software or software modules that provide various services to the terminal device, or it can be implemented as a single software or software module that provides various services to the terminal device. No specific limitation is made here.
[0040] It should be noted that the method for generating a test script provided in the embodiment of the present disclosure can be executed by the terminal device 104, 105, or by the server 101, 102, 103. Accordingly, the apparatus for generating a test script can be set in the terminal device 104, 105, or in the server 101, 102, 103.
[0041] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0042] Continue to refer Figure 2 , shows a process 200 of an embodiment of a method for generating a test script according to the present disclosure. The method for generating a test script comprises the following steps:
[0043] Step 210, in response to obtaining the click coordinates of a click operation performed by the user on the current interface, determining the interface elements of the current interface and the visible areas of the interface elements.
[0044] In this step, the execution subject on which the method for generating a test script runs can obtain the click coordinates corresponding to the click operation by collecting the click operation performed by the user (such as the tester) on the current interface. In practice, the click coordinates of the click operation performed by the user on the current interface can also be specified. For example, for the click operation to be tested or the function associated with the click operation, the coordinates corresponding to the click operation can be used as the click coordinates of the click operation performed by the user on the current interface.
[0045] After the above-mentioned execution entity obtains the click coordinates, it can parse the current interface and determine the interface elements contained in the current interface. Different interfaces correspond to different interface elements, and the number of interface elements is also different. This application does not make specific limitations on the interface and interface elements.
[0046] Each interface element has attribute information, such as resource identification information, text information, type, and visible area, etc. Among them, the resource identification information represents the resources loaded by the interface element, such as pictures, videos, documents, etc.; the text information represents the text displayed on the interface element, and the visible area refers to the display area of the interface element. The above-mentioned execution subject can determine the visible area corresponding to each interface element by parsing each interface element, and can also determine the resource identification information, text information and type corresponding to each interface element.
[0047] Step 220, traverse the visible areas of each interface element, determine the target visible area containing the click coordinates and the control associated with the interface element corresponding to the target visible area.
[0048] In this step, after determining the visible areas corresponding to the interface elements, the execution subject can sort the visible areas from small to large according to the area of each visible area to obtain the sorting result of the visible areas, and then select the visible area with the smallest area from the sorting result to start judging whether the click coordinates fall into the visible area. When the execution subject determines that a certain visible area contains the click coordinates, the visible area is determined as the target visible area, and then the execution subject determines the interface element corresponding to the target visible area, and determines the control associated with the interface element.
[0049] The control associated with the interface element is a control that can support the display of the interface element and realize the function corresponding to the interface element. Each interface element can be associated with multiple controls, and each control has different functions. Step 230, obtain the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the keyword of the target control based on the attribute information of the target control.
[0050] In this step, the execution subject may obtain the attribute information of each control after determining the control associated with the interface element corresponding to the target visible area, wherein the attribute information of the control may include resource identification information and / or text information, etc. The resource identification information identifies the resource loaded by the control, such as a picture, video, document, etc.; the text information represents the text displayed on the control.
[0051] Optionally, in the process of acquiring the attribute information of each control, the execution subject may delete the control whose attribute information does not include resource identification information and / or text information.
[0052] Optionally, after acquiring the attribute information of each control, the execution subject may determine the control whose attribute information includes resource identification information and / or text information. The execution subject may determine the target control associated with the click coordinates according to the attribute information of each control.
[0053] Specifically, after the execution subject obtains the resource identification information and / or text information of each control, it determines the priority of each control according to the resource identification information and / or text information of each control. As an example, the execution subject can classify these controls according to the attributes of the resource identification information and / or text information of each control, such as the uniqueness or validity of the resource identification information, the length, uniqueness or validity of the text information, etc. For example, different priorities are assigned according to whether the resource identification information is unique or the length of the text, etc. The execution subject determines the control that meets the preset conditions as the target control associated with the click coordinates according to the priority of each control. For example, the execution subject can select the control with the highest priority as the target control.
[0054] After determining the target control, the execution subject determines whether the attribute information can identify the target control based on the attribute information of the target control, for example, whether the resource identification information and / or text information of the target control can uniquely identify the target control. If the attribute information of the target control can identify the target control, the attribute information of the target control can be used as the keyword of the target control. If the attribute information of the target control cannot identify the target control, information that can uniquely identify the target control can be further determined based on the attribute information of the target control, and the information can be used as the keyword of the target control.
[0055] Step 240: Generate a test script corresponding to the click operation based on the keyword of the target control.
[0056] In this step, the execution subject can automatically generate a test script corresponding to the click operation according to the target control and the keyword of the target control after determining the target control and the keyword of the target control associated with the click coordinates. Specifically, after determining the target control associated with the click coordinates and the keyword of the target control, the execution subject further determines whether the target control is a control corresponding to the click operation. If it is determined that the target control is a control corresponding to the click operation, the click operation is associated with the keyword of the target control to generate a test script corresponding to the click operation.
[0057] Continue to refer Figure 3 , Figure 3 FIG. 1 is a schematic diagram of an application scenario of the method for generating a test script according to this embodiment. Figure 3In the application scenario, the terminal 310 presents an interface 320 to the tester. The terminal 310 receives a click operation performed by the tester on a coordinate 330 at the upper right corner of the interface 320, and the terminal 310 obtains the coordinate 330. The terminal 310 begins to parse the interface 320, and determines the interface elements of the interface 320 and the visible areas corresponding to each interface element. The terminal 310 analyzes each visible area, determines the target visible area containing the coordinate 330, determines the interface element corresponding to the target visible area, and further determines the control associated with the interface element. Then the terminal 310 obtains the attribute information of each control associated with the interface element, and determines the target control associated with the coordinate 330 based on the attribute information of each control, and further determines the keyword of the target control based on the attribute information of the target control. Finally, the terminal 310 generates a test script corresponding to the user's click operation based on the obtained target control and the keyword of the target control.
[0058] The method for generating a test script provided by an embodiment of the present disclosure determines the interface elements of the current interface and the visible area of the interface elements in response to obtaining the click coordinates of a user performing a click operation on the current interface, then traverses the visible area of the interface elements to determine the target visible area containing the click coordinates and the controls associated with the interface elements corresponding to the target visible area, then obtains the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the keyword of the target control based on the attribute information of the target control, and finally generates a test script corresponding to the click operation based on the keyword of the target control, which can accurately and quickly determine the target control associated with the click coordinates, thereby improving the accuracy of the target control, and can automatically generate a test script based on the keyword of the target control, thereby improving the efficiency of generating a test script.
[0059] In some optional implementations of this embodiment, the priority of each control associated with the interface element corresponding to the target visible area can be determined in the following manner:
[0060] (1) The priority of the control that determines the uniqueness of resource identification information is the first priority.
[0061] Specifically, the above-mentioned execution entity can obtain the resource identification information of each control, determine whether the resource identification information of each control is the same by comparing the resource identification information of each control, determine a control whose resource identification is different from the resource identification of any other control, and determine the control as the control with unique resource identification information, and determine the priority of the control as the first priority.
[0062] (2) Determine that the priority of the control whose resource identification information is not unique and whose text information meets the first preset condition is the second priority, wherein the first preset condition includes: the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters.
[0063] Specifically, after determining the controls of the first priority, the above-mentioned execution subject can determine the controls of the second priority from the controls whose resource identification information is not unique. After determining the controls whose resource identification information is not unique, the above-mentioned execution subject further determines whether the text information of these controls meets the first preset condition, and the first preset condition may include that the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters, that is, the above-mentioned execution subject can determine whether the text information of each control has the situation that the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters, and determine the priority of the control corresponding to the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters as the second priority.
[0064] (3) Determine that the priority of the control whose resource identification information is not unique and whose text information meets the second preset condition is the third priority, wherein the second preset condition includes: the length of the text information does not exceed the preset length and there are no abnormal characters.
[0065] Specifically, after determining the controls of the first priority and the second priority, the above-mentioned execution subject may further determine the controls of the third priority from the controls whose resource identification information is not unique. After the above-mentioned execution subject determines the controls whose text information meets the first preset condition among the controls whose resource identification information is not unique, it determines whether the text information of the remaining controls meets the second preset condition, and the second preset condition may include that the length of the text information does not exceed the preset length and there are no abnormal characters, that is, the above-mentioned execution subject may determine whether the text information of the remaining controls has the situation that the length of the text information does not exceed the preset length and there are no abnormal characters, and determines the priority of the control corresponding to the text information length not exceeding the preset length and no abnormal characters as the third priority.
[0066] (4) Determine that the priority of the control whose resource identification information is invalid and whose text information is valid and unique is the fourth priority.
[0067] Specifically, the execution subject has determined the controls with the first priority, the second priority, and the third priority, that is, the execution subject has determined the priority of the control whose resource identification information is unique, and has determined the priority of the control whose resource identification information is not unique and whose text information meets the first preset condition or the second preset condition. The execution subject can select the control whose resource identification information is invalid and whose text information is valid and unique from the remaining controls, and determine the priority of the control that meets these conditions as the fourth priority.
[0068] (5) Determine that the controls whose resource identification information and text information are invalid are the fifth priority.
[0069] Specifically, after determining the controls with the first priority, the second priority, the third priority, and the fourth priority, the execution subject determines the remaining controls with invalid resource identification information and text information as the fifth priority.
[0070] In this implementation, the priority of each control is determined based on its resource identification information and text information, and the priority of each control is divided. The target control can be quickly located and selected according to the priority, thereby improving the accuracy of the target control.
[0071] In some optional implementations of the present embodiment, the target control associated with the click coordinates is determined based on the priority of each control associated with the interface element corresponding to the target visible area, including: sorting each control based on the priority of each control associated with the interface element corresponding to the target visible area, and determining the controls with a preset number of controls in the front order as the target controls associated with the click coordinates.
[0072] Specifically, the execution subject determines the priority of each control associated with the interface element corresponding to the target visible area according to the attribute information of each control, wherein the first priority is the highest priority, the second priority is the second, and so on, and the fifth priority is the lowest priority. The execution subject sorts the controls associated with the interface element corresponding to the target visible area according to the priority level of each control, and obtains the sorting result of the controls associated with the interface element corresponding to the target visible area. For example, the sorting result can be a control with a first priority, a control with a second priority, a control with a third priority, a control with a fourth priority, and a control with a fifth priority. The execution subject selects a preset number of controls from the sorting result. As an example, the control with the first priority can be selected according to the sorting result as the target control associated with the click coordinates.
[0073] In this implementation, if the resource identification information can uniquely identify the control, there is no need to further judge the text information. By prioritizing the uniqueness of the resource identification information, the operation of judging the control can be saved. If the resource identification information cannot uniquely identify the control, further judgment of the text information is required, which can ensure the uniqueness of the control and improve the accuracy of the control.
[0074] In some optional implementations of the present embodiment, determining the keyword of the target control based on the attribute information of the target control in the above step 230 includes at least one of the following: in response to determining that the priority of the target control is the first priority, determining the resource identification information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the second priority, determining the resource identification information in the attribute information of the target control and the index of the resource identification information as the keyword of the target control, wherein the index is used to filter out the target control from multiple controls with the same resource identification information; in response to determining that the priority of the target control is the third priority, determining the text information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the fourth priority, determining the text information in the attribute information of the target control as the keyword of the target control.
[0075] Specifically, after the execution subject determines the target control according to the priorities of each control, it determines to which priority control the target control belongs.
[0076] If the target control belongs to the first priority control, it can be determined that the resource identification information of the target control is unique, and the resource identification information of the target control can identify the target control. The resource identification information in the attribute information of the target control is used as the keyword of the target control, and the keyword can be used to identify the target control in the test script.
[0077] If the target control belongs to the second priority control, it can be determined that the resource identification information of the target control is not unique and the text information meets the first preset condition. The target control cannot be identified only by the resource identification information. An index can be set in advance. The index is used to filter out the target control from multiple controls with the same resource identification information. The resource identification information in the attribute information of the target control and the index of the resource identification information are used as keywords of the target control. The keyword can be used to identify the target control in the test script to identify the target control filtered out from multiple controls with the same resource identification information.
[0078] If the target control belongs to the third priority control, it can be determined that the resource identification information of the target control is not unique and the text information meets the second preset condition. In the case that the resource identification information is not unique, the text information can further identify the target control, and the text information in the attribute information of the target control is used as the keyword of the target control. The keyword can be used to identify the target control in the test script.
[0079] If the target control belongs to the fourth priority control, it can be determined that the resource identification information of the target control is invalid, and the text information is valid and unique. In the case that the resource identification information is invalid, the text information can further identify the target control, and the text information in the attribute information of the target control is used as the keyword of the target control. The keyword can be used to identify the target control in the test script.
[0080] If the target control belongs to the fifth priority control, it can be determined that the resource identification information of the target control is invalid, the text information is invalid, and the keyword of the target control does not exist.
[0081] In this implementation, the keyword of the target control is determined based on the priority of the target control, which makes it easier and faster to determine the keyword of the target control and improves the accuracy of the keyword of the target control.
[0082] In some optional implementations of this embodiment, the above step 240, based on the keyword of the target control, generates a test script corresponding to the click operation, which can be performed according to the following process 400:
[0083] Step 410 , in response to the ratio of the area of the target control to the interface area of the current interface not exceeding a first preset value, associating a click operation with a keyword of the target control in the test script.
[0084] In this step, after determining the target control, the execution subject further obtains the area of the target control. The execution subject can obtain the ratio of the area of the target control to the interface area of the current interface based on the area of the target control and the interface area of the current interface, for example, the ratio is 16%, and then judge whether the ratio exceeds the first preset value, which can be a pre-set empirical value, such as 20%. If the execution subject determines through judgment that the ratio of the area of the target control to the interface area of the current interface does not exceed the first preset value, the area of the target control accounts for a small proportion of the current interface, and the proportion of the screened control is low, then the accuracy of the association between the target control and the click coordinate is higher, and it is considered that the found target control is correct, and the click operation is associated with the keyword of the target control in the process of generating the test script.
[0085] Step 420, in response to the ratio of the area of the target control to the interface area of the current interface exceeding the first preset value and not exceeding the second preset value, associate the click operation with the keyword of the target control in the test script, and add a comment to the test script to mark the location where the user clicked.
[0086] In this step, the execution subject obtains the ratio of the area of the target control to the interface area of the current interface, for example, the ratio is 26%, and then determines whether the ratio exceeds the first preset value, which can be a preset empirical value, such as 20%. If the execution subject determines through judgment that the ratio of the area of the target control to the interface area of the current interface exceeds the first preset value, it further determines whether the ratio exceeds the second preset value, which can be a preset empirical value, and the second preset value is greater than the first preset value, such as 40%. If the execution subject determines through judgment that the ratio of the area of the target control to the interface area of the current interface does not exceed the second preset value, the area ratio occupied by the target control in the current interface is large, and the ratio of the control screened out is high, then there is a possibility that there is an error in the association between the target control and the click coordinates, and it is considered that the correct target control may be found, that is, there is a possibility that the target control is wrong. In the process of generating the test script, the click operation is associated with the keyword of the target control, and a comment for marking the position where the user clicks is added to the generated test script to indicate the specific position where the user clicked at that time.
[0087] Step 430, in response to the ratio of the area of the target control to the interface area of the current interface exceeding a second preset value, variable coordinates are generated based on the click coordinates and the size of the display screen, and the click operation is associated with the variable coordinates in the test script, and a comment is added in the test script to mark the target control associated with the click operation.
[0088] In this step, the execution subject obtains the ratio of the area of the target control to the interface area of the current interface, for example, the ratio is 46%, and then determines whether the ratio exceeds the first preset value, which can be a preset empirical value, such as 20%. If the execution subject determines through judgment that the ratio of the area of the target control to the interface area of the current interface exceeds the first preset value, it further determines whether the ratio exceeds the second preset value, which can be a preset empirical value, and the second preset value is greater than the first preset value, such as 40%. If the execution subject determines through judgment that the ratio of the area of the target control to the interface area of the current interface exceeds the second preset value, the area ratio of the target control in the current interface is large, and the ratio of the control screened out is very high, then the target control is likely not the control associated with the click coordinates, and it is considered that the correct target control is not found with a high probability, then a variable coordinate is generated according to the click coordinates and the size of the current display screen, and the variable coordinate can represent the specific position of the target control associated with the click operation. The execution subject associates the click operation with the variable coordinates during the process of generating the test script, and adds a comment in the generated test script for marking the target control associated with the click operation to indicate which control the click operation corresponds to.
[0089] In this implementation, whether the target control is the control associated with the click coordinates is determined by the ratio of the display area of the target control to the interface area of the current interface, which further improves the accuracy of the target control. If the target control does not meet expectations, there is also a corresponding processing strategy, which improves the flexibility of test script generation.
[0090] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device for generating a test script. Figure 2 The method embodiments shown correspond.
[0091] like Figure 5As shown, the picture display device 500 of this embodiment may include: a visible area determination unit 510, configured to determine the interface elements of the current interface and the visible areas of the interface elements in response to obtaining the click coordinates of the user performing a click operation on the current interface; an associated control determination unit 520, configured to traverse the visible areas of each interface element, determine the target visible area containing the click coordinates and the controls associated with the interface elements corresponding to the target visible area; a keyword determination unit 530, configured to obtain the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determine the keyword of the target control based on the attribute information of the target control; a generation unit 540, configured to generate a test script corresponding to the click operation based on the keyword of the target control.
[0092] In some optional implementations of the present embodiment, the attribute information of the control includes resource identification information and / or text information, the resource identification information identifies the resources loaded by the control, and the text information represents the text displayed on the control; and a keyword determination unit includes: a target control determination module, configured to determine the priority of each control based on the resource identification information and / or text information of the control, and determine the target control associated with the click coordinates based on the priority of each control.
[0093] In some optional implementations of the present embodiment, the target control determination module is further configured to: determine the priority of the control whose resource identification information is unique as the first priority; determine the priority of the control whose resource identification information is not unique and whose text information meets the first preset condition as the second priority, wherein the first preset condition includes: the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters; determine the priority of the control whose resource identification information is not unique and whose text information meets the second preset condition as the third priority, wherein the second preset condition includes: the length of the text information does not exceed the preset length and there are no abnormal characters; determine the priority of the control whose resource identification information is invalid and whose text information is valid and unique as the fourth priority.
[0094] In some optional implementations of the present embodiment, the target control determination module is further configured to: sort the controls based on the priority of each control, and determine the controls with a preset number of controls in the front as the target controls associated with the click coordinates.
[0095] In some optional implementations of the present embodiment, the keyword determination unit includes: a keyword determination module; and the keyword determination module is configured to be at least one of the following: in response to determining that the priority of the target control is the first priority, determining the resource identification information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the second priority, determining the resource identification information in the attribute information of the target control and the index of the resource identification information as the keyword of the target control, wherein the index is used to filter out the target control from multiple controls with the same resource identification information; in response to determining that the priority of the target control is the third priority, determining the text information in the attribute information of the target control as the keyword of the target control; in response to determining that the priority of the target control is the fourth priority, determining the text information in the attribute information of the target control as the keyword of the target control.
[0096] In some optional implementations of the present embodiment, the generation unit is further configured to: in response to the ratio of the area of the target control to the interface area of the current interface not exceeding a first preset value, associate the click operation with a keyword of the target control in the test script.
[0097] In some optional implementations of the present embodiment, the generation unit is further configured to: in response to the ratio of the area of the target control to the interface area of the current interface exceeding a first preset value but not exceeding a second preset value, associate the click operation with a keyword of the target control in the test script, and add a comment in the test script to mark the location where the user clicked.
[0098] In some optional implementations of the present embodiment, the generation unit is further configured to: in response to the ratio of the area of the target control to the interface area of the current interface exceeding a second preset value, generate variable coordinates based on the click coordinates and the size of the display screen, and associate the click operation to the variable coordinates in the test script, and add an annotation in the test script to mark the target control associated with the click operation.
[0099] The device provided by the above-mentioned embodiments of the present disclosure, in response to obtaining the click coordinates of a user performing a click operation on the current interface, determines the interface elements of the current interface and the visible area of the interface elements, then traverses the visible area of the interface elements, determines the target visible area containing the click coordinates and the controls associated with the interface elements corresponding to the target visible area, then obtains the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the keyword of the target control based on the attribute information of the target control, and finally generates a test script corresponding to the click operation based on the keyword of the target control, which can accurately and quickly determine the target control associated with the click coordinates, thereby improving the accuracy of the target control, and can automatically generate a test script according to the keyword of the target control, thereby improving the efficiency of generating the test script.
[0100] like Figure 6 As shown, the electronic device 600 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0101] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 600 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 6 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0102] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0103] It should be noted that the computer-readable medium of the embodiment of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the embodiment of the present disclosure, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, device or device. In the embodiment of the present disclosure, the computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0104] The computer-readable medium may be included in the electronic device; or it may exist independently without being installed in the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: determines the interface elements of the current interface and the visible area of the interface elements in response to obtaining the click coordinates of the user performing a click operation on the current interface; traverses the visible areas of each interface element to determine the target visible area containing the click coordinates and the controls associated with the interface elements corresponding to the target visible area; obtains the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the target control associated with the click coordinates based on the attribute information of each control associated with the interface element corresponding to the target visible area, and determines the keywords of the target control based on the attribute information of the target control; generates a test script corresponding to the click operation based on the keywords of the target control.
[0105] Computer program code for performing the operations of the embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" language or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet).
[0106] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0107] The units involved in the embodiments described in the present disclosure may be implemented by software or by hardware. The described units may also be provided in a processor, for example, may be described as: a processor including a visible area determination unit, an associated control determination unit, a keyword determination unit, and a generation unit. Among them, the names of these units do not constitute limitations on the units themselves in certain circumstances, for example, the visible area determination unit may also be described as "a unit for determining the interface elements of the current interface and the visible areas of the interface elements in response to obtaining the click coordinates of a user performing a click operation on the current interface".
[0108] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) to form a technical solution.
Claims
1. A method for generating a test script, include: In response to acquiring click coordinates of a click operation performed by a user on a current interface, determining an interface element of the current interface and a visible area of the interface element; Traversing the visible areas of each of the interface elements, determining a target visible area containing the click coordinates and a control associated with the interface element corresponding to the target visible area; Acquire attribute information of each control associated with the interface element corresponding to the target visible area; wherein the attribute information of the control includes resource identification information and / or text information, the resource identification information identifies the resource loaded by the control, and the text information represents the text displayed on the control; Determine the priority of each control based on the resource identification information and / or the attributes of the text information of the control; the attributes of the resource identification information include the uniqueness or validity of the resource identification information, and the attributes of the text information include the length, uniqueness or validity of the text information; Determine a target control associated with the click coordinates based on the priority of each control; Determining a keyword of the target control based on the attribute information of the target control; Based on the keyword of the target control, a test script corresponding to the click operation is generated.
2. The method according to claim 1, in, Determining the priority of each control based on the resource identification information and / or the attribute of the text information of the control includes: The priority of the control that determines the uniqueness of resource identification information is the first priority; Determine that the priority of the control whose resource identification information is not unique and whose text information meets the first preset condition is the second priority, wherein the first preset condition includes: the length of the text information exceeds the preset length, the text information is not unique, or the text information contains abnormal characters; Determine that the priority of the control whose resource identification information is not unique and whose text information meets the second preset condition is the third priority, wherein the second preset condition includes: the length of the text information does not exceed the preset length and there are no abnormal characters; The priority of the control that determines that the resource identification information is invalid and the text information is valid and unique is the fourth priority.
3. The method according to claim 2, in, Determining a target control associated with the click coordinates based on the priority of each control includes: Based on the priority of each control, the controls are sorted, and controls with a preset number of controls in the front are determined as target controls associated with the click coordinates.
4. The method according to claim 3, in, The determining of the keyword of the target control based on the property information of the target control includes at least one of: In response to determining that the priority of the target control is the first priority, determining the resource identification information in the property information of the target control as a keyword of the target control; In response to determining that the priority of the target control is the second priority, determining the resource identification information and the index of the resource identification information in the property information of the target control as a keyword of the target control, wherein the index is used to filter out the target control from multiple controls with the same resource identification information; In response to determining that the priority of the target control is the third priority, determining text information in the attribute information of the target control as a keyword of the target control; In response to determining that the priority of the target control is the fourth priority, text information in the property information of the target control is determined as a keyword of the target control.
5. The method according to any one of claims 1 to 4, in, The step of generating a test script corresponding to the click operation based on the keyword of the target control includes: In response to the ratio of the area of the target control to the interface area of the current interface not exceeding a first preset value, the click operation is associated with a keyword of the target control in a test script.
6. The method according to claim 5, in, The generating a test script corresponding to the click operation based on the keyword of the target control also includes: In response to the ratio of the area of the target control to the interface area of the current interface exceeding a first preset value but not exceeding a second preset value, the click operation is associated with a keyword of the target control in the test script, and an annotation is added to the test script to mark the location where the user clicked.
7. The method according to claim 6, in, The generating a test script corresponding to the click operation based on the keyword of the target control also includes: In response to the ratio of the area of the target control to the interface area of the current interface exceeding a second preset value, variable coordinates are generated based on the click coordinates and the size of the display screen, and the click operation is associated with the variable coordinates in a test script, and an annotation is added in the test script to mark the target control associated with the click operation.
8. A device for generating a test script, include: a visible area determination unit, configured to determine the interface elements of the current interface and the visible areas of the interface elements in response to acquiring click coordinates of a click operation performed by a user on the current interface; an associated control determination unit, configured to traverse the visible areas of the interface elements, determine a target visible area containing the click coordinates and a control associated with the interface element corresponding to the target visible area; A keyword determination unit is configured to obtain attribute information of each control associated with the interface element corresponding to the target visible area The attribute information of the control includes resource identification information and / or text information, the resource identification information identifies the resource loaded by the control, and the text information represents the text displayed on the control; Determine the priority of each control based on the resource identification information and / or the attributes of the text information of the control; the attributes of the resource identification information include the uniqueness or validity of the resource identification information, and the attributes of the text information include the length, uniqueness or validity of the text information; Determine a target control associated with the click coordinates based on the priority of each control; Determining a keyword of the target control based on the attribute information of the target control; The generating unit is configured to generate a test script corresponding to the click operation based on the keyword of the target control.
9. An electronic device, include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
