Keyword-driven UI element positioning and interaction method and device
By automatically calculating UI element positioning and performing interactive actions based on keyword-driven methods, the problems of multiple element positioning and high maintenance costs in UI automation testing are solved, and testing efficiency and maintainability are improved.
Patent Information
- Application Number
- CN202411828070.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-08
AI Technical Summary
In the existing UI automation test, there are too many element positioning and high cost of maintenance of use cases, which leads to a lot of manpower required to modify after version iteration, which is inefficient.
采用基于关键字驱动的UI元素定位与交互方法,通过编写特定语法的测试用例,自动计算元素定位并进行对应的交互动作,减少对页面元素定位和交互函数的维护。
Automatically calculate element positioning and perform interactive actions during the use case writing stage, reducing the maintenance needs of element positioning and interaction functions, improving the maintainability and efficiency of use cases, and reducing manpower investment.
Smart Images

Figure CN119782152A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a keyword-driven UI element positioning and interaction method and device. Background Art
[0002] With the rapid development of computer technology, testing methods have also developed accordingly. In response to the repeated and redundant testing workload, most companies will use automated testing technology to deal with it, and UI (user interface) automated testing is one of them. The pain points and difficulties of UI automated testing lie in the excessive element positioning and high maintenance cost of use cases. The core of UI automated testing is page element positioning. If the page requirements change or there are changes for other reasons, the page elements located by UI automation will also change, which will cause the use case execution to fail. This kind of situation is very common. At present, there is no mature solution for the maintainability of use cases. In the maintenance of automated use cases after version iteration, a lot of manpower is still needed to modify them. The high cost and low efficiency will bring certain economic losses to the company. Therefore, keyword-driven UI element positioning and automatic interaction algorithms are of great significance.
[0003] Traditional UI automation testing requires first locating button elements, then writing the corresponding button interaction methods, and finally assembling them into use cases. After version iteration, the old UI automation use cases are not compatible with the new version of the interface interaction, and the testers must re-locate the button elements. If the button interaction method is changed, the interaction method needs to be reconstructed. Finally, the use case steps are revised again. The overall process is redundant, the workload is large, the efficiency is extremely low, and continuous personnel investment is required. The specific shortcomings are as follows:
[0004] 1) There are many page element locations. Each button, input box, and option on the page needs to write a corresponding page element location use case;
[0005] 2) There are many interactive functions, and each page element needs to rewrite the interactive functions;
[0006] 3) The maintainability of the use case is low. After version iteration, the elements and methods are not applicable and need to be refactored;
[0007] 4) The process is redundant and the workload is large. Each version iteration requires a lot of manpower to maintain elements, methods, and use cases. Summary of the invention
[0008] In response to the technical problems mentioned above, the purpose of the embodiments of the present application is to propose a keyword-driven UI element positioning and interaction method and device, which automatically calculates element positioning and performs corresponding interactive actions by writing test cases with specific syntax, without the need to maintain page element positioning and response interactive functions.
[0009] The technical solution of the present invention is as follows.
[0010] In a first aspect, a keyword-driven UI element positioning and interaction method includes:
[0011] Obtain a written test case; the test case includes a target action, a parent element where a target element is located, a child element where the target element is located, and a target element to be interacted with;
[0012] Use the keyword syntax matching algorithm to obtain the parent element of the target element in the test case, the child element of the target element, and the characteristic value of the target element, as well as the characteristic value of the target action in the test case;
[0013] Using the positioning algorithm, obtain the parent element XPATH that matches the parent element feature value, and obtain the child element XPATH that matches the child element feature value and the target element feature value;
[0014] Splice the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH;
[0015] Based on the target element XPATH and the feature value of the target action, the corresponding interactive action is executed.
[0016] Preferably, the keyword syntax matching algorithm is specifically an embedded keyword syntax matching algorithm based on Robot Framework.
[0017] Preferably, a positioning algorithm is used to obtain the parent element XPATH that matches the parent element feature value, as follows:
[0018] Each characteristic value of the parent element will correspond to a wildcard XPATH location. The characteristic value is added to the parent element XPATH location through the positioning algorithm to obtain an XPATH location that is uniquely determined and matches the parent element characteristic value.
[0019] Preferably, a positioning algorithm is used to obtain a sub-element XPATH that matches the sub-element feature value and the target element feature value, as follows:
[0020] Each characteristic value of the sub-element will correspond to a wildcard XPATH location. The characteristic value of the target element is added to the XPATH location of the sub-element through the positioning algorithm to obtain an XPATH location that is uniquely determined and matches the characteristic values of the sub-element and the target element.
[0021] Preferably, the test case also includes parameters corresponding to special elements;
[0022] Before obtaining the target element XPATH, the method further includes:
[0023] Get the characteristic value of a special element;
[0024] Get the syntax that matches the characteristic value of a special element and concatenate it with the child element XPATH or parent element XPATH.
[0025] Preferably, the special element includes one or more of: a positioning offset, a parent element unique identifier, a root element, and an exception identifier.
[0026] Preferably, the syntax matching the characteristic value of the special element is obtained and concatenated with the child element XPATH or the parent element XPATH, specifically including:
[0027] If the characteristic value of the positioning offset is obtained, the element subscript index index is hard-coded after the child element XPATH as the characteristic value of the positioning offset;
[0028] If the characteristic value of the unique identifier of the parent element is obtained, the unique characteristic value of the parent element is added to the XPATH of the parent element;
[0029] If the characteristic value of the root element is obtained, the root element XPATH is concatenated before the parent element to limit the position of the parent element;
[0030] If the characteristic value of the exception identifier is obtained, the characteristic value excluding the obtained exception identifier is appended to the child element XPATH.
[0031] Preferably, after obtaining the sub-element XPATH that matches the sub-element characteristic value and the target element characteristic value, the method further includes:
[0032] Get the front-end style framework, and identify the characteristic value of the Class element of the front-end framework according to the addition of the front-end style framework in the child element XPATH.
[0033] Preferably, based on the target element XPATH and the characteristic value of the target action, the corresponding interactive action is executed, specifically including:
[0034] In the Selenium Library in Robot Framework, the interaction keywords corresponding to the target action feature values are obtained, and based on the target element XPATH, the corresponding interaction keywords are executed to make the corresponding interaction actions.
[0035] On the other hand, a keyword-driven UI element positioning and interaction device includes:
[0036] A test case acquisition module is used to acquire the written test case; the test case includes a target action, a parent element where the target element is located, a child element where the target element is located, and a target element to be interacted with;
[0037] A feature value acquisition module is used to use a keyword syntax matching algorithm to obtain the parent element of the target element in the test case, the child element of the target element, and the feature value of the target element, as well as the feature value of the target action in the test case;
[0038] An XPATH positioning module is used to use a positioning algorithm to obtain a parent element XPATH that matches a parent element feature value, and to obtain a child element XPATH that matches a child element feature value and a target element feature value;
[0039] The target element XPATH acquisition module is used to splice the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH;
[0040] The interaction module is used to execute corresponding interaction actions based on the target element XPATH and the characteristic value of the target action.
[0041] Compared with the prior art, the present invention has the following beneficial effects:
[0042] (1) During the use case writing stage, the present invention automatically calculates element positioning and performs corresponding interactive actions by writing use case steps with specific syntax, without the need to maintain page element positioning and responsive interactive functions; after version iteration, the element positioning can be adaptively adjusted, and even if the page elements change, there is no need to adjust the element positioning, and only the use case steps need to be maintained, without the need to invest manpower to make further adjustments;
[0043] (2) The test case of the present invention includes special elements, and the introduction of special elements can increase the reusability and accuracy of positioning. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 A flowchart of a keyword-driven UI element positioning and interaction method according to an embodiment of the invention;
[0046] Figure 2 A schematic diagram of the structure of a keyword-driven UI element positioning and interaction method according to an embodiment of the invention;
[0047] Figure 3 It is a structural diagram of the parent element XPATH positioning process of an embodiment of the invention;
[0048] Figure 4 It is a structural schematic diagram of the sub-element XPATH positioning process of an embodiment of the invention;
[0049] Figure 5 This is a structural diagram of positioning by identifying the Class element features of the front-end framework in an embodiment of the invention;
[0050] Figure 6 It is a structural schematic diagram of a keyword-driven UI element positioning and interaction device according to an embodiment of the invention. DETAILED DESCRIPTION
[0051] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention; it is obvious that the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments, and all other embodiments obtained by ordinary technicians in this field based on the embodiments of the present invention without making creative work are within the scope of protection of the present invention.
[0052] In the description of the present invention, it should be noted that the terms "comprises", "includes" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0053] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, step identifiers S101, S102, S103, etc. are only used for convenient expression and do not represent the execution order. The corresponding execution order can be adjusted as needed.
[0054] See also Figure 1 and Figure 2 As shown, the present invention provides a keyword-driven UI element positioning and interaction method, which includes the following steps.
[0055] S101, obtaining a written test case; the test case includes a target action, a parent element where a target element is located, a child element where the target element is located, and a target element to be interacted with.
[0056] Specifically, the test case is written using a standardized natural language template. An example of a fixed syntax is as follows:
[0057] "${l_element_name}"${l_element_type} in K_${l_action}"${l_type}"
[0058] Among them, ${l_action} is the target action, such as single click, double click, input, suspension, etc.
[0059] ${l_type} is the parent element of the target element, such as a pop-up window, prompt window, list, etc.
[0060] ${l_elemenet_name} is the target element to be interacted, such as user name, password, etc.
[0061] ${l_element_type} is the child element of the target element, such as a button, input box, etc.
[0062] For example, a test case is represented as "K_input "name" input box in "add pop-up window", then "input" is the target action; "pop-up window" is the parent element of the target element; "name" is the target element to be interacted; and "input box" is the child element of the target element.
[0063] Furthermore, the test case also includes special elements.
[0064] Special elements are passed in the form of parameters, including the positioning offset ${l_index}, the parent element unique identifier ${l_title}, the root element ${l_base_xpath}, and the exception identifier ${l_ex_lable}. The positioning offset defaults to 1, and the parent element unique identifier, root element, and exception identifier are empty by default.
[0065] Specifically, ${l_index} is the positioning offset, which is used to locate the target element position, and the default value is 1. For example: a single Label has multiple input boxes, but none of the input boxes have special marks, then the offset can be used to specify the input box position.
[0066] The implementation code for setting the positioning offset is as follows:
[0067] ${l_element_xpath}Set Variable${l_element_xpath}\[${l_index}]
[0068] Among them, l_element_xpath is the original XPATH location (XPATH location calculated based on fixed syntax). By adding "[number]" on the right, the effect of specifying the element offset distance can be achieved.
[0069] Specifically, ${l_title} is the unique identifier of the parent element. For example, if there are a "Details" pop-up window and an "Add" pop-up window, the parent element needs to be specified as the "Add" pop-up window, and the Title field "Add" of the pop-up window can be used as the unique identifier.
[0070] Pop-up window - Specify the XPATH of Title as follows:
[0071] / / div[contains(@class,'el-dialog__wrapper')][not(contains(@style,'display:
[0072] none'))] / div[contains(@aria-label,'########')]
[0073] Sliding Window - Specify the XPATH of Title as follows:
[0074] / / div[@role='dialog'][contains(@class,'el-drawer')][not(contains(@style,'display:none'))][contains(@aria-label,'########')]
[0075] Prompt dialog box - Specify the XPATH of Title as follows:
[0076] / / div[contains(@aria-label,'########')][not(contains(@style,'display:none'))]
[0077] During the XPATH calculation process, ${l_title} will be replaced with the "########" field in the above three examples to achieve reusability and accuracy of positioning.
[0078] Specifically, ${l_base_xpath} is the root element, which is suitable for element positioning in complex interfaces. For example, if you need to locate a list in a detail pop-up window within a list, you can set the detail pop-up window as the root element and the list in the pop-up window as the parent element.
[0079] The implementation code for splicing the root element and the parent element is as follows:
[0080] ${l_element_xpath}Set Variable${l_base_xpath}${l_element_xpath}
[0081] Specifically, ${l_ex_lable} is an exception mark. For example, if there are two input boxes, namely "Port" and "Access Port", and if you locate by the "Port" field, you will locate two input boxes. At this time, you can set "Access Port" as an exception mark.
[0082] Replace the category characters that need to be excluded (********), the default is -1, the implementation code is as follows:
[0083] ${l_element_xpath}
[0084] ...K_Replace the specified characters in the string
[0085] ...original_string=${l_element_xpath}
[0086] ...target_string=${l_ex_label}
[0087] ...regular_string=********
[0088] Among them, "********" is the replacement text identifier in XPATH. If there are multiple XPATH statements that need to replace text, you can modify the replacement identifier yourself. During the XPATH calculation process, "********" in XPATH will be replaced with the ${l_ex_label} field.
[0089] S102, using a keyword syntax matching algorithm, obtain the parent element of the target element in the test case, the child element of the target element, and the characteristic value of the target element, and obtain the characteristic value of the target action in the test case.
[0090] Specifically, through the embedded keyword syntax matching of Robot Framework, the feature values of the parent element, child element and target element in the standardized template use case steps are calculated, and the feature value of the target action in the test case is obtained.
[0091] Test case for Example 1: K_enters the "Name" input box in the "Add pop-up window".
[0092] The parent element characteristic value "pop-up window" and the child element characteristic value "input box" can be extracted;
[0093] Example 2: K_Click the "OK" button in the "Personal Settings Sliding Window".
[0094] The parent element feature value "slide" and the child element feature value "button" can be extracted.
[0095] The embedded keyword syntax is responsible for passing the text of the parent element, child element, etc. in the test case into the algorithm. The algorithm will perform fuzzy matching based on the passed text to match the feature values in the text of the parent element, child element, etc.
[0096] S103, using a positioning algorithm, obtaining a parent element XPATH that matches the parent element feature value, and obtaining a child element XPATH that matches the child element feature value and the target element feature value.
[0097] S104, splicing the child element XPATH to the right side of the parent element XPATH to obtain the target element XPATH.
[0098] The specific implementation of S103 and S104 is as follows.
[0099] After extracting the feature value, the XPATH location of the target element is calculated through the UI element adaptive positioning algorithm.
[0100] Specifically, each characteristic value of the parent element will correspond to a wildcard XPATH location, see Figure 3 As shown, by adding the characteristic value to the parent element XPATH location through the location algorithm, an XPATH location that is uniquely determined and matches the parent element characteristic value is obtained.
[0101] The XPATH of the pop-up window is as follows:
[0102] / / div[contains(@class,'el-dialog__wrapper')][not(contains(@style,'display:none'))]
[0103] The XPATH of the sliding window is as follows:
[0104] / / div[@role='dialog'][contains(@class,'el-drawer')][not(contains(@style,'display:none'))]
[0105] The XPATH of the prompt dialog box is as follows:
[0106] / / div[contains(@aria-label,'prompt')or contains(@aria-label,'ok')][not(contains(@style,'display:none'))][not(contains(parent::* / @style,'display:none'))]
[0107] Each type of XPATH has a specified common XPATH statement. For example, if the parent element feature value of the test case is "pop-up window", the XPATH statement of the pop-up window will be directly spliced on the left side of the XPATH.
[0108] Specifically, the feature value of the sub-element is strongly coupled to the feature value of the target element, so each feature value of the sub-element will also correspond to a wildcard XPATH location, see Figure 4 As shown, by adding the characteristic value of the target element to the XPATH location of the sub-element through the location algorithm, an XPATH location that is uniquely determined and matches the characteristic values of the sub-element and the target element is obtained.
[0109] The child element XPATH of the pop-up window-name input box is as follows:
[0110] / following::input[contains(@class,'el-input')]
[0111] The XPATH of the child element of pop-up switch is as follows:
[0112] / following::span[contains(@class,'el-switch')]
[0113] List search bar - The child element XPATH of the search input box is as follows:
[0114] / / div[contains(@class,'tabletop_cz')or contains(@class,'tablesearchfilter')]
[0115] / / input[contains(@class,'el-input__inner')][(contains(@placeholder,'########')
[0116] and not(contains(@placeholder,'********')))or(contains(following::text(),'########')andnot(contains(following::text(),'********')))]
[0117] List Action Bar - Specify the child element XPATH of the row button as follows:
[0118] / following::div[@class='table-maneuvering-areatable_operate'][1] / / span[contains(text(),'########')]
[0119] Each sub-element type has a specified general XPATH statement. For example, if the sub-element feature value of the use case is "input box", the XPATH statement of the input box will be directly spliced to the right side of the XPATH. These XPATHs are fixed and general sub-element XPATHs. As long as it is a sub-element that hits the feature value, the corresponding sub-element XPATH will be spliced to the right side of the parent XPATH.
[0120] Furthermore, after calculating the XPATH locations of the parent element and the child element, special processing is performed according to the special feature values passed in as parameters, as follows:
[0121] If the input positioning offset is 2, the element subscript index index is hard-coded as 2 after the child element XPATH, marking it as the second element after the target element;
[0122] If the unique identifier of the parent element is passed to "Add", the feature value "Add" is added to the XPATH of the parent element;
[0123] If the specified root element is "Details Pop-up Window", the root element XPATH is concatenated before the parent element to limit the parent element position;
[0124] If the exception identification feature "access port" is specified, the "access port" is appended to the child element XPATH without including it.
[0125] The parent element and child element described in this algorithm are in a relative positioning relationship. After calculating the parent element and child element XPATH, relative positioning splicing is performed in the format of "parent element / child element" to identify the uniqueness of the target element positioning.
[0126] For further information, see Figure 5 As shown in the figure, the general XPATH positioning of the parent element and the child element is also performed by identifying the Class element characteristics of the front-end framework. The specific positioning scheme is exemplified as follows.
[0127] Example 1: To locate the button element, if the front-end style framework is AntDesign, you can directly identify the button tag whose Class attribute contains "ant-btn".
[0128] Sub-element XPATH code example: / following::button[contains(@class,'ant-btn')]
[0129] / following::button[contains(@class,'ant-btn')or contains(@class,'n-button')or contains(@class,'el-button')]
[0130] Example 2: To locate the input box, if the front-end style framework is NaiveUI, you can directly identify the input tag whose Class attribute contains "n-input".
[0131] Sub-element XPATH code example: / following::input[contains(@class,'n-input')]
[0132] Example 3: To locate the drop-down item, if the front-end style framework is Element, you can directly identify the input tag whose Class attribute contains "el-select".
[0133] Sub-element XPATH code example: / following::input[contains(@class,'el-input')]
[0134] As long as the front-end and back-end are separated, and the front-end style framework is kept unified or multiple front-end style frameworks are used, the identification calculation can be performed directly according to the corresponding Class feature value. And XPATH can be extended and optimized according to different design frameworks, as follows:
[0135] AntDesign framework identifier: ant-*;
[0136] Frame ID: n-*;
[0137] Element framework identifier: el-*;
[0138] Regardless of whether the front-end framework is implemented in Vue language or React, the front-end style is unified, and the general XPATH positioning does not require additional modifications.
[0139] It should be noted that the universal XPATH positioning of parent elements and child elements is extensible. When the positioning of other characteristic elements needs to be added, the algorithm matching parameters can be directly expanded horizontally.
[0140] S105: Execute a corresponding interactive action based on the target element XPATH and the characteristic value of the target action.
[0141] Specifically, as described above, the target actions in the standardized template use case steps are calculated through the embedded syntax matching algorithm of the Robot Framework.
[0142] For example, in the test case: K_ inputs the "Name" input box in the "Add pop-up window", and the target action can be extracted as "Input".
[0143] The embedded keyword syntax is responsible for passing the "action" text into the algorithm. The algorithm will simulate matching based on the text passed in, match the feature values in the "action" text, and execute the specified action. A dictionary of action feature values and interaction methods will be encapsulated inside the algorithm. By traversing and matching the action feature values, the corresponding interaction keywords are obtained, and finally the interaction keywords corresponding to the action feature values are executed.
[0144] After calculating the target action, the corresponding interactive action is made by encapsulating the interactive keywords in the Selenium Library in the Robot Framework.
[0145] Example 1: K_ enters the "Name" input box in the "Add pop-up window" and implements input interaction through the Input Text keyword of SeleniumLibrary in RobotFramework;
[0146] Example 2: K_Clicks the "OK" button in the "Personal Settings Slider" and implements single-click interaction through the Click Element of SeleniumLibrary in RobotFramework.
[0147] It should be noted that the interactive action in the present invention is scalable. When the interactive action needs to be expanded, the algorithm matching parameters can be directly expanded horizontally without reconstructing the algorithm code.
[0148] For example, if you need to add an interactive action of "slide to", you can directly add the corresponding feature value and interactive keyword in the interactive dictionary: "slide to = Scroll Element Into View". In subsequent use, you can automatically execute the Scroll Element Into View keyword by directly writing the action field of "slide" in the use case.
[0149] See also Figure 6 As shown, this embodiment also discloses a keyword-driven UI element positioning and interaction device, including:
[0150] The test case acquisition module 601 is used to acquire the written test case; the test case includes the target action, the parent element where the target element is located, the child element where the target element is located, and the target element to be interacted;
[0151] The feature value acquisition module 602 is used to use the keyword syntax matching algorithm to obtain the feature values of the parent element of the target element, the child element of the target element and the target element in the test case, and to obtain the feature value of the target action in the test case;
[0152] An XPATH positioning module 603 is used to use a positioning algorithm to obtain a parent element XPATH that matches a parent element feature value, and to obtain a child element XPATH that matches a child element feature value and a target element feature value;
[0153] The target element XPATH acquisition module 604 is used to splice the child element XPATH to the right side of the parent element XPATH to obtain the target element XPATH;
[0154] The interaction module 605 is used to execute the corresponding interaction action based on the target element XPATH and the characteristic value of the target action.
[0155] Furthermore, the test case also includes parameters corresponding to special elements;
[0156] Before obtaining the target element XPATH, the method further includes:
[0157] Get the characteristic value of a special element;
[0158] Get the syntax that matches the characteristic value of a special element and concatenate it with the child element XPATH or parent element XPATH.
[0159] The special elements include: one or more of: positioning offset, parent element unique identifier, root element and exception identifier.
[0160] The specific implementation of each module of the keyword-driven UI element positioning device is the same as the keyword-driven UI element positioning and interaction method, which will not be repeated in this embodiment.
[0161] Furthermore, the embodiment also provides a schematic diagram of the structure of a computer device. The computer device includes a processor, a memory and a communication interface. The processor, the memory and the communication interface are interconnected via a bus. The memory stores a computer program, and the computer program is configured to be executed by the processor.
[0162] The computer program includes instructions for performing the following steps:
[0163] Obtain a written test case; the test case includes a target action, a parent element where a target element is located, a child element where the target element is located, and a target element to be interacted with;
[0164] Use the keyword syntax matching algorithm to obtain the parent element of the target element in the test case, the child element of the target element, and the characteristic value of the target element, as well as the characteristic value of the target action in the test case;
[0165] Using the positioning algorithm, obtain the parent element XPATH that matches the parent element feature value, and obtain the child element XPATH that matches the child element feature value and the target element feature value;
[0166] Splice the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH;
[0167] Based on the target element XPATH and the feature value of the target action, the corresponding interactive action is executed.
[0168] In addition, the embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program can be operated to cause a computer to execute some or all steps of any method recorded in the keyword-driven UI element positioning and interaction method embodiment. The computer program product can be a software installation package, and the computer includes a computer device or a server.
[0169] The modules involved in the embodiments described in this application may be implemented by software or hardware, and the modules described may also be set in a processor.
[0170] As another aspect, the present application also provides a computer-readable medium, which may be included in the computer device described in the above embodiment; or it may exist independently and not be assembled into the computer device. The above computer-readable medium carries one or more computer programs, and when the above one or more computer programs are executed by the computer device, the computer device: obtains the written test case; the test case includes the target action, the parent element where the target element is located, the child element where the target element is located, and the target element to be interacted; uses the keyword syntax matching algorithm to obtain the parent element where the target element is located, the child element where the target element is located, and the characteristic value of the target element in the test case, and obtains the characteristic value of the target action in the test case; uses the positioning algorithm to obtain the parent element XPATH that matches the parent element characteristic value, and obtains the child element XPATH that matches the child element characteristic value and the target element characteristic value; splices the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH; based on the characteristic value of the target element XPATH and the target action, executes the corresponding interactive action.
[0171] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A keyword-driven UI element positioning and interaction method, characterized in that: include: Get the written test cases; The test case includes the target action, the parent element where the target element is located, the child element where the target element is located, and the target element to be interacted with; Use the keyword syntax matching algorithm to obtain the parent element of the target element in the test case, the child element of the target element, and the characteristic value of the target element, as well as the characteristic value of the target action in the test case; Using the positioning algorithm, obtain the parent element XPATH that matches the parent element feature value, and obtain the child element XPATH that matches the child element feature value and the target element feature value; Splice the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH; Based on the target element XPATH and the feature value of the target action, the corresponding interactive action is executed.
2. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: The keyword syntax matching algorithm is specifically an embedded keyword syntax matching algorithm based on Robot Framework.
3. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: Use the positioning algorithm to obtain the parent element XPATH that matches the parent element feature value, as follows: Each characteristic value of the parent element will correspond to a wildcard XPATH location. The characteristic value is added to the parent element XPATH location through the positioning algorithm to obtain an XPATH location that is uniquely determined and matches the parent element characteristic value.
4. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: Use the positioning algorithm to obtain the sub-element XPATH that matches the sub-element feature value and the target element feature value, as follows: Each characteristic value of the sub-element will correspond to a wildcard XPATH location. The characteristic value of the target element is added to the XPATH location of the sub-element through the positioning algorithm to obtain an XPATH location that is uniquely determined and matches the characteristic values of the sub-element and the target element.
5. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: The test case also includes parameters corresponding to special elements; Before obtaining the target element XPATH, the method further includes: Get the characteristic value of a special element; Get the syntax that matches the characteristic value of a special element and concatenate it with the child element XPATH or parent element XPATH.
6. The keyword-driven UI element positioning and interaction method according to claim 5, characterized in that: The special elements include: one or more of: positioning offset, parent element unique identifier, root element and exception identifier.
7. The keyword-driven UI element positioning and interaction method according to claim 6, characterized in that: Get the syntax that matches the characteristic value of a special element and concatenate it with the child element XPATH or the parent element XPATH, including: If the characteristic value of the positioning offset is obtained, the element subscript index index is hard-coded after the child element XPATH as the characteristic value of the positioning offset; If the characteristic value of the unique identifier of the parent element is obtained, the unique characteristic value of the parent element is added to the XPATH of the parent element; If the characteristic value of the root element is obtained, the root element XPATH is concatenated before the parent element to limit the position of the parent element; If the characteristic value of the exception identifier is obtained, the characteristic value excluding the obtained exception identifier is appended to the child element XPATH.
8. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: After obtaining the sub-element XPATH that matches the sub-element feature value and the target element feature value, it also includes: Get the front-end style framework, and identify the characteristic value of the Class element of the front-end framework according to the addition of the front-end style framework in the child element XPATH.
9. The keyword-driven UI element positioning and interaction method according to claim 1, characterized in that: Based on the target element XPATH and the feature value of the target action, the corresponding interactive action is executed, including: In the Selenium Library in Robot Framework, the interaction keywords corresponding to the target action feature values are obtained, and based on the target element XPATH, the corresponding interaction keywords are executed to make the corresponding interaction actions.
10. A keyword-driven UI element positioning and interaction device, characterized in that: include: Test case acquisition module, used to obtain the written test cases; The test case includes the target action, the parent element where the target element is located, the child element where the target element is located, and the target element to be interacted with; A feature value acquisition module is used to use a keyword syntax matching algorithm to obtain the parent element of the target element in the test case, the child element of the target element, and the feature value of the target element, as well as the feature value of the target action in the test case; An XPATH positioning module is used to use a positioning algorithm to obtain a parent element XPATH that matches a parent element feature value, and to obtain a child element XPATH that matches a child element feature value and a target element feature value; The target element XPATH acquisition module is used to splice the child element XPATH to the right of the parent element XPATH to obtain the target element XPATH; The interaction module is used to execute corresponding interaction actions based on the target element XPATH and the characteristic value of the target action.