CN117472744A - Page element positioning method, electronic device and storage medium - Google Patents

Page element positioning method, electronic device and storage medium Download PDF

Info

Publication number
CN117472744A
CN117472744A CN202311396223.XA CN202311396223A CN117472744A CN 117472744 A CN117472744 A CN 117472744A CN 202311396223 A CN202311396223 A CN 202311396223A CN 117472744 A CN117472744 A CN 117472744A
Authority
CN
China
Prior art keywords
test
page
target
keywords
determining
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311396223.XA
Other languages
Chinese (zh)
Inventor
陈均辉
黄博
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Merchants Bank Co Ltd
Original Assignee
China Merchants Bank Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Merchants Bank Co Ltd filed Critical China Merchants Bank Co Ltd
Priority to CN202311396223.XA priority Critical patent/CN117472744A/en
Publication of CN117472744A publication Critical patent/CN117472744A/en
Pending legal-status Critical Current

Links

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The application discloses a page element positioning method, electronic equipment and a storage medium, which relate to the field of page element positioning, and in the application, htm l analysis data of a target page are determined first; determining a target text from the htm l analysis data based on the keywords of the test elements in the test step of the target page; and finally, determining the position information of the test element on the target page based on the structural hierarchy of the target text in the htm l analysis data. Namely, in the test step of the method, the test elements are described through the keywords, the keywords are visual natural language, the method has good readability, and maintenance barriers caused by differences of coding styles among different testers can be weakened. And the position of the test element in the page is determined directly from the htm l analysis data through the keywords, so that the labor cost of manual searching is reduced, and the testing efficiency is improved.

Description

Page element positioning method, electronic device and storage medium
Technical Field
The application relates to the technical field of automated testing, in particular to a page element positioning method, electronic equipment and a storage medium.
Background
At present, in the automatic test of a Web terminal interface, a common test method is to write a corresponding automatic script for testing based on python-selenium (a Web automatic test tool). When the interface test script is compiled, one of the steps is to locate the interface elements, and the element location generally needs to be searched one by personnel based on a certain test technology, but the interface elements are more and frequently changed, the complexity of the interface elements also increases the location difficulty to a certain extent, so that manual searching is time-consuming. And the coding technical capability and coding style of different testers are different, and the readability and easy maintenance of the script also have certain difference. If there is a change or job intersection, it is inevitably necessary to read and modify each other's codes, and the difference between the writing styles of different testers will increase the maintenance cost of the test script in the later stages. It can be seen that the implementation cost of the automation script in the conventional automation test scheme is high.
Disclosure of Invention
The main purpose of the application is to provide a page element positioning method, electronic equipment and a storage medium, and aims to solve the technical problem of high implementation cost of an automatic script in a conventional automatic test scheme.
In order to achieve the above object, the present application provides a page element positioning method, including:
determining html analysis data of a target page;
determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page;
and determining the position information of the test element on the target page based on the structure level of the target text in the html analysis data.
Optionally, before the step of determining the target text from the html parsing data based on the keywords of the target element in the testing step, the method includes:
outputting selectable test contents, wherein the selectable test contents comprise keywords of test elements and test actions, and the types of the test actions comprise single actions and combined actions;
responsive to user operation, determining selected selectable test content and/or receiving custom test content;
generating a test step based on the selected selectable test content and/or the received custom test content.
Optionally, after the step of generating a test step based on the selected selectable test content and/or the received custom test content, the method includes:
If a plurality of selectable texts are determined based on keywords of the test elements in the test step in the process of debugging and executing the test step, respectively determining the positions of the test elements in the target page based on the selectable texts to obtain the selectable positions;
determining a target position in each optional position, wherein the target position can finish the test action in the test step;
and associating the identification of the optional text corresponding to the target position with the keyword to complete the debugging of the testing step.
Optionally, the keyword is associated with an identifier, and the step of determining the target text from the html parsing data based on the keyword of the test element in the test step of the target page includes:
matching texts which are the same as the keywords in the html analysis data based on the keywords of the test elements to obtain matching texts;
and selecting target text from the matched texts according to the identification of the keyword association.
Optionally, the step of determining the target position in each of the selectable positions at which the test action in the testing step can be completed includes:
optionally taking one optional position from the optional positions, and executing the test action of the test step based on the optional position;
If the test action is executed, the optional position is taken as a target position;
if the test action is not executed, a new optional position is selected, and the step of executing the test action of executing the test step based on the optional position is returned based on the new optional position until each optional position is traversed.
Optionally, after the step of traversing each of the selectable positions, the method includes:
if the target position capable of completing the test action in the test step is not selected after the optional positions are traversed, outputting prompt information of failure in execution of the test step;
and after receiving a new user operation, returning to execute the step of responding to the user operation and determining the selected selectable test content and/or receiving the custom test content based on the new user operation.
Optionally, the testing step includes a loading waiting time period and a testing action, after the step of determining the location information of the test element on the target page based on the structure level of the target text in the html parsing data, the method includes:
after waiting for the loading waiting time period, executing the test action on the test element based on the position information;
And if the test action fails to be executed, after waiting the loading waiting time again, returning to execute the step of executing the test action on the test element based on the position information until the test action is executed successfully or the total waiting time reaches the preset time.
Optionally, the keyword of the test element is a name, a label or a prompt of the test element, where, in the case that the test element is a non-text element, the keyword of the test element is a text description of an adjacent element of the test element.
In addition, to achieve the above object, the present application further provides an electronic device, including: the page element positioning device comprises a memory, a processor and a page element positioning program which is stored in the memory and can run on the processor, wherein the page element positioning program realizes the steps of the page element positioning method when being executed by the processor.
In addition, in order to achieve the above object, the present application further provides a storage medium, on which a page element positioning program is stored, which when executed by a processor, implements the steps of the page element positioning method as described above.
The embodiment of the application provides a page element positioning method, electronic equipment and a storage medium. In the embodiment of the application, html analysis data of a target page is determined first; determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page; and finally, determining the position information of the test element on the target page based on the structure level of the target text in the html analysis data. In other words, in the test step of the embodiment, the test elements are described through the keywords, compared with the positions of directly describing the test elements in the traditional automatic test, the keywords are visual natural languages, the method has good readability, maintenance barriers caused by differences of coding styles among different testers can be weakened, and maintenance cost is reduced. Furthermore, the position of the test element in the page is directly determined from the html analysis data through the keywords, and the position of the test element is determined without manual searching, so that the labor cost is reduced, and the testing efficiency is improved. In addition, the implementation cost of the automatic test script in the web automation test can be greatly reduced.
Drawings
FIG. 1 is a schematic diagram of an electronic device in a hardware operating environment according to an embodiment of the present application;
FIG. 2 is a flowchart of a first embodiment of a method for positioning page elements according to the present application;
FIG. 3 is a table of contents of a portion of the test steps in the page element positioning method of the present application;
FIG. 4 is a schematic layout diagram of a target page in the page element positioning method of the present application;
FIG. 5 is a schematic layout diagram of another target page in the page element positioning method of the present application;
FIG. 6 is a flowchart of a second embodiment of a method for positioning page elements according to the present application;
fig. 7 is a flowchart of a third embodiment of a method for positioning page elements in the present application.
The realization, functional characteristics and advantages of the present application will be further described with reference to the embodiments, referring to the attached drawings.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
As shown in fig. 1, fig. 1 is a schematic structural diagram of an electronic device of a hardware running environment according to an embodiment of the present application.
The electronic device in the embodiment of the application may be a server, or may be an electronic terminal device such as a smart phone, a PC, a tablet computer, a portable computer, and the like.
As shown in fig. 1, the electronic device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
Optionally, the electronic device may further include a camera, an RF (Radio Frequency) circuit, a sensor, an audio circuit, a WiFi module, and the like. The terminal may also be configured with other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., which are not described in detail herein. Those skilled in the art will appreciate that the electronic device structure shown in fig. 1 is not limiting of the electronic device and may include more or fewer components than shown, or may combine certain components, or may be arranged in different components.
Those skilled in the art will appreciate that the electronic device structure shown in fig. 1 is not limiting of the electronic device and may include more or fewer components than shown, or may combine certain components, or may be arranged in different components.
Further, as shown in fig. 1, an operating system, a network communication module, a user interface module, and a page element positioning program may be included in the memory 1005 as one type of computer storage medium.
In the electronic device shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server and performing data communication with the background server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call a page element locator program stored in the memory 1005 and perform the following operations:
determining html analysis data of a target page;
determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page;
and determining the position information of the test element on the target page based on the structure level of the target text in the html analysis data.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
Before the step of determining the target text from the html parsing data based on the keywords of the target element in the testing step, the method includes:
outputting selectable test contents, wherein the selectable test contents comprise keywords of test elements and test actions, and the types of the test actions comprise single actions and combined actions;
responsive to user operation, determining selected selectable test content and/or receiving custom test content;
generating a test step based on the selected selectable test content and/or the received custom test content.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
after the step of generating a test step based on the selected selectable test content and/or the received custom test content, the method comprises:
if a plurality of selectable texts are determined based on keywords of the test elements in the test step in the process of debugging and executing the test step, respectively determining the positions of the test elements in the target page based on the selectable texts to obtain the selectable positions;
Determining a target position in each optional position, wherein the target position can finish the test action in the test step;
and associating the identification of the optional text corresponding to the target position with the keyword to complete the debugging of the testing step.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
the keywords are associated with identifications, and the step of determining the target text from the html analysis data based on the keywords of the test elements in the test step of the target page comprises the following steps:
matching texts which are the same as the keywords in the html analysis data based on the keywords of the test elements to obtain matching texts;
and selecting target text from the matched texts according to the identification of the keyword association.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
the step of determining a target location in each of the selectable locations at which the test action of the step of testing may be completed includes:
optionally taking one optional position from the optional positions, and executing the test action of the test step based on the optional position;
If the test action is executed, the optional position is taken as a target position;
if the test action is not executed, a new optional position is selected, and the step of executing the test action of executing the test step based on the optional position is returned based on the new optional position until each optional position is traversed.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
after the step of traversing each of the selectable positions, the method includes:
if the target position capable of completing the test action in the test step is not selected after the optional positions are traversed, outputting prompt information of failure in execution of the test step;
and after receiving a new user operation, returning to execute the step of responding to the user operation and determining the selected selectable test content and/or receiving the custom test content based on the new user operation.
In a possible implementation, the processor 1001 may call the page element locator program stored in the memory 1005, and further perform the following operations:
the testing step includes loading waiting time length and testing action, after the step of determining the position information of the test element in the target page based on the structure level of the target text in the html parsing data, the method includes:
After waiting for the loading waiting time period, executing the test action on the test element based on the position information;
and if the test action fails to be executed, after waiting the loading waiting time again, returning to execute the step of executing the test action on the test element based on the position information until the test action is executed successfully or the total waiting time reaches the preset time.
In a possible implementation manner, the keyword of the test element is a name, a label or a prompt of the test element, where, in the case that the test element is a non-text element, the keyword of the test element is a text description of an adjacent element of the test element.
Referring to fig. 2, a first embodiment of a page element positioning method of the present application includes:
step S10, determining html analysis data of a target page;
it should be noted that, in practical application, the main flow of the web automatic test includes writing an automatic test script by related technicians, the automatic test script includes corresponding automatic test cases, and the script completes the test work on the corresponding test pages based on each test step in the cases. For any one test step, test elements and test actions can be included, wherein the test actions can be clicking, pulling down, uploading and other operation actions, and the like, can be obtained by packaging some native operation actions of selenium such as clicking, inputting, page waiting and the like, and can be described by using specific character strings such as click, input and the like in actual use. For some specific test actions, the test step further includes a parameter value, for example, the specific test action may be an input action, and the corresponding test element is a text input box, and when the input action is executed, the parameter value in the test step is input into the text input box. It will be appreciated that the corresponding test action performed on the test element requires determining the location information of the test element on the page, i.e. the location of the page element. In a conventional automated test scheme, element information is usually obtained by manually searching by a tester, and writing the found position information into a test step to represent a corresponding test element. Therefore, in the traditional automatic test method, on one hand, the manual searching of the element position information increases the labor cost and affects the automatic test progress, on the other hand, the position information is directly used for expressing the test element, the position information is difficult to embody the function readability of the test aimed at by the test step, and if the layout of the page element changes, the position information also fails, so that the maintenance cost of the subsequent script is increased. In view of the above, the embodiments of the present application will provide a page element positioning method, in which the test element is described in the test steps by the keywords of the test element, for example, refer to fig. 3, which is a table of contents of a part of the test steps in the present application, which will include the keywords (i.e. the keywords are used to describe the test element) and the test actions for any one test step, and in some cases, the test steps will further include the inclusion (i.e. the parameter values). And the position of the test element in the page is determined by automatic keyword matching, on the one hand, the position of the test element in the page is determined by automatic keyword matching, so that the labor cost can be reduced, and the writing efficiency of the test step is improved. On the other hand, the test elements are described by the keywords, and the keywords are usually visual natural language, so that the method has good readability, thereby weakening maintenance barriers caused by differences of coding styles among different testers, and facilitating script maintenance work under the condition of modification or work handover, and reducing maintenance cost.
For example, the target page is a page to be tested, and in order to determine the position of the test element on the page in the testing process, in this embodiment, the html (HyperText Markup Language ) content of the target page is parsed to obtain html parsed data. For example, the html can be resolved by using a third party library beautfulso to obtain html resolved data, where the obtained html resolved data includes location information of each element on the target page. In addition, for obtaining the html of the target page, the target page can be opened through the selenium.webdriver to obtain the html character string of the target page, namely the html content.
Step S20, determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page;
it should be noted that, in this embodiment, the test elements in the test step of the target page are described by keywords, so that when the corresponding test action needs to be executed on the test elements in the actual test process, the position information of the test elements in the target page needs to be determined.
Illustratively, the target text is determined from the html parsing data according to the keywords of the test element in the test step. For example, text identical to the keyword is matched from the html parsing data, the matched text is taken as a target text, the matching process can be realized through regular matching, and a regular expression used by the regular matching can be some common xpath path templates constructed based on xpath (Xml Path Language, extensible markup language path language) grammar.
And step S30, determining the position information of the test element on the target page based on the structural hierarchy of the target text in the html analysis data.
For example, the position information of the test element in the target page is determined according to the structure level of the target text in the html analysis data. It should be noted that, the determined location information is xpath of the test element, and the location of the test element on the target page is identified through xpath. For example, in practical applications, the keywords are: other login modes are determined that the obtained xpath is [ '(//[ containers (text (), "other login modes") ] ] [1]', '(//[ containers (text (), "other login modes") ]) [1]/parent [' (//[ containers (text (), "other login modes") ]) 1/player: (button ',' (//button [ @ type= "button" and@lay-subset "=" and@lay-filter= "packet-subset-btn" and@containers= "layui-btna-subset-btn" and data-lang= "@ label" ] "). The key words are verification codes, and the obtained xpath is determined to be [ '(//[ containers (text (), "verification codes") ] [1]', '(//[ containers (text (), "verification codes") ] ] [1]/parent [' (//[ containers (text (), "verification codes") ]) 1/player:: (button ',' (//button [ @ type= "button" and@lay-subset = "" and@lay-filter = "passage-subscriber-btn" and@containers = "layui-btnacnt-btn" and data-lan "]) [ containers () ]). The key word is that inputting 11-bit mobile phone number, determining that xpath is [ '(/// @ placeholder= "inputting 11-bit mobile phone number" ]) [1]' ]. Specific location information will not be described in detail herein.
In this embodiment, html parsing data of a target page is determined first; determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page; and finally, determining the position information of the test element on the target page based on the structure level of the target text in the html analysis data. In other words, in the test step of the embodiment, the test elements are described through the keywords, compared with the positions of directly describing the test elements in the traditional automatic test, the keywords are visual natural languages, the method has good readability, maintenance barriers caused by differences of coding styles among different testers can be weakened, and maintenance cost is reduced. Furthermore, the position of the test element in the page is directly determined from the html analysis data through the keywords, and the position of the test element is determined without manual searching, so that the labor cost is reduced, and the testing efficiency is improved. In addition, the implementation cost of the automatic test script in the web automation test can be greatly reduced.
In a possible implementation manner, the testing step includes a loading waiting time period and a testing action, and after the step of determining the location information of the test element on the target page based on the structure level of the target text in the html parsing data, the method includes:
Step S310, after waiting for the loading waiting time, executing the test action on the test element based on the position information;
step S320, if the test action fails to be executed, after waiting for the loading waiting duration again, returning to execute the step of executing the test action on the test element based on the location information until the test action is executed successfully, or until the total waiting duration reaches a preset duration.
For example, after determining the position information of the test element in the test step, taking into consideration that a certain time is required for actually loading the page, after waiting for a certain loading time period, executing a corresponding test action on the test element according to the position information. So as to avoid the problem of test failure caused by test action being executed under the condition that the page is not loaded. In practical applications, since the performance of the test device is different, the time required for loading the page is also different, so the loading waiting time can be set by a technician. In addition, if the execution of the test action is still an execution failure after waiting for the loading waiting time, there is a cause of execution failure due to the fact that the page is not loaded, so that the step of executing the test action on the test element based on the position information can be returned to be executed after waiting for the loading waiting time again. Until the test action is successfully executed or the total waiting time reaches the preset time. The total waiting time is obtained by multiplying the waiting times and the loading waiting time, and if the total waiting time reaches the preset time, the test execution failure is not possibly caused by that the page is not loaded, so that prompt information can be output to the outside to inform relevant testers to review.
In a possible implementation manner, the keyword of the test element is a name, a label or a prompt of the test element, where, in the case that the test element is a non-text element, the keyword of the test element is a text description of an adjacent element of the test element.
It can be understood that in this embodiment, the test element is described by using the keyword in the test step, and for the tester, the keyword is an intuitive natural language, and under the scenario of script writing, only the test element is described by using the keyword for the tester, so that the difficulty of script writing can be reduced, and the writing efficiency can be improved. In the reading scene, the keywords can intuitively show the test object aimed at by the test step. In order to characterize the characteristics of the test element, the keywords may be names, labels, prompt words, etc. of the test element, for example, the keywords may be "other login modes", "input 11-bit mobile phone numbers", and "obtain verification codes", etc., and for some non-text elements such as tables and charts, text descriptions of adjacent elements may be used, for example, text descriptions of adjacent elements of tables are selected "as shown in the above table", etc. Referring to fig. 4, a layout diagram of a target page in the present application is shown, where the names of each test element in the target page may include "other login mode", "input 11-bit mobile phone number", "obtain verification code", and "please input verification", so that the corresponding keywords may be set to "other login mode", "input 11-bit mobile phone number", "obtain verification code", and "please input verification", etc. Referring to fig. 5, a layout diagram of another target page in the present application is shown, where the names of each test element in the target page may include "do not need to be preserved, do not need to be preserved", "examine and approve path" and "save draft", so that the corresponding keywords may be set to "do not need to be preserved, do not need to be preserved", "examine and approve path" and "save draft", etc.
Referring to fig. 6, based on the first embodiment of the page element positioning method of the present application, a second embodiment of the page element positioning method of the present application is proposed, and in this embodiment, the same parts as those implemented above may refer to the above, and the details are not repeated here. Before the step of determining the target text from the html parsing data based on the keywords of the target element in the testing step, the method includes:
step S110, outputting selectable test contents, wherein the selectable test contents comprise keywords of test elements and test actions, and the types of the test actions comprise single actions and combined actions;
step S120, responding to user operation, determining selected optional test content and/or receiving custom test content;
step S130, generating a testing step based on the selected selectable testing content and/or the received custom testing content.
It should be noted that, in the writing stage of the test step in the script, the embodiment outputs preset optional test content for the user to select, so as to speed up the writing of the test step.
For example, the selectable test content output to the user through the interactive interface may include a test element and a test action, where the test action may include a single action and a combined action, and the combined action is a result of packaging a plurality of single actions, thereby simplifying the writing process. For example, for various drop-down boxes or calendar elements, clicking and selecting the elements is needed during testing, but before the action is completed, some pre-actions such as a drop-down action or a slide-up action are needed to be completed, and in order to simplify the writing step, the drop-down action or the slide-up action can be packaged together with the clicking and selecting action to obtain a combined action, and the corresponding combined action can also be directly described as the clicking and selecting action. Based on the test requirements, the testers (i.e. users) can select keywords and test actions of the test elements in the output selectable test contents, namely user operation. And then, in response to the user operation, determining the selected selectable test content (namely, the keywords and the test actions of the test elements selected by the user), wherein for the test content, a tester can also input the test content in a self-defined manner on the interactive interface. For example, in practical application, the writing template of the test step can also be output, including a keyword input area and a test action input area of the test element, and also including a parameter value selection input area. The selectable test content which can be selectively output by the tester is filled in each input area, and keywords, test actions and parameter values can be customized, namely, the customized test content is input into each input area, and the selectable test content and the customized test content can be combined for use, for example, the keywords of the test elements are customized and input by a user, and the test steps can be determined according to the selection of the user. After determining the selected optional test content and/or receiving the custom test content, for any one test step, the test element may be generated in association with the keyword-test action-parameter value (optional) form.
In a possible embodiment, after the step of generating a test step based on the selected selectable test content and/or the received custom test content, the method includes:
step S140, if a plurality of selectable texts are determined based on the keywords of the test element in the test step during the debugging and executing the test step, determining the position of the test element in the target page based on each selectable text, so as to obtain each selectable position;
step S150, determining a target position in each optional position, wherein the target position can finish the test action in the test step;
step S160, the identification of the optional text corresponding to the target position is associated with the keyword, so that the debugging of the testing step is completed.
It should be noted that, in practical applications, there may be a problem that the test steps written by the tester are difficult to be performed. For example, multiple target texts may be determined from html parsing data according to keywords, thereby interfering with the testing process. Debugging is required for the test steps for which writing is completed.
For example, the test step may be executed based on the target page debug, and the specific execution process is the same as that of the above embodiment, and will not be described herein. It is noted that if the keywords of the test element in the test step are based on, a plurality of optional texts may be determined from the html parsing data, for example, a plurality of texts (i.e., a plurality of optional texts) identical to the keywords may be matched from the html parsing data. The positions of the test element sub-in the target page are respectively determined based on the optional texts, so that a plurality of optional positions are obtained. And then respectively attempting to execute corresponding test actions based on the optional positions to determine whether the test actions can be completed. And finally, taking the position which can finish the test action in the test step in each optional position as a target position. It will be appreciated that when multiple locations are obtained based on matching keywords to multiple texts, the exact location of the test element, i.e., the target location, may be determined by way of the above-described trial execution. And associating the identification of the optional text corresponding to the target position with the keyword, thereby completing the debugging of the testing step. Wherein the identifier associated with the keyword may be a sequence number for determining the target location in case there are a plurality of matching results.
In a possible implementation manner, the keywords are associated with identifications, and the step of determining the target text from the html parsing data based on the keywords of the test elements in the test step of the target page includes:
step S210, matching texts which are the same as the keywords in the html analysis data based on the keywords of the test elements to obtain matching texts;
and step S220, selecting target texts from the matched texts according to the identification of the keyword association.
In this embodiment, the keyword is associated with an identifier, and in this case, the representation is based on that the keyword will match to a plurality of texts identical thereto.
The text which is the same as the keyword is matched from the html analysis data based on the keyword of the test element, and each matched text is obtained. And selecting a target text from the matched texts according to the identification associated with the keywords. For example, the identifier may be a text number, for example, if the html parsing data includes a text a and a text B, which are the same as the keyword, and according to the matching sequence, the identifier corresponding to the text a is the number 1 and the identifier corresponding to the text B is the number 2, and if the test action is completed based on the position determined by the text B, the identifier associated with the keyword is the number 2. It can be understood that in the actual test stage and the debug test stage, the matching modes are the same, so in the actual test stage, if the keywords are associated with the identifiers, the keywords and the associated identifiers can be accurately matched with the target text, and the position of the test element on the target page can be determined based on the target text.
Referring to fig. 7, based on the first embodiment and the second embodiment of the page element positioning method of the present application, a third embodiment of the page element positioning method of the present application is provided, and in this embodiment, the same parts as those implemented above may refer to the above, and details are not repeated here. The step of determining a target location in each of the selectable locations at which the test action of the step of testing may be completed includes:
step S151, optionally selecting an optional position from the optional positions, and executing the test action of the test step based on the optional position;
step S152, if the test action is completed, the optional position is taken as a target position;
step S153, if the test is not performed, selecting a new optional position, and returning to the step of performing the test based on the optional position until each of the optional positions is traversed.
For example, when determining the target position from the selectable positions, a selectable position may be optionally selected from the selectable positions, and a test action may be performed based on the selectable position, and if the test action may be performed, the selectable position may be taken as the target position. Otherwise, if the test action is not performed, the optional position can be selected again, and the step of performing the test action based on the optional position is returned based on the new optional position until each optional position is traversed.
In a possible embodiment, after the step of traversing each of the selectable positions, the method includes:
step S154, if the target position capable of completing the test action in the test step is not selected after each optional position is traversed, outputting prompt information of failure in execution of the test step;
step S155, after receiving a new user operation, the step of determining the selected selectable test content and/or receiving the custom test content is performed based on the new user operation.
For example, in practical applications, it may happen that after traversing all the optional positions, the target position that can complete the test action in the test step is still not selected. And outputting prompt information of failure in execution of the test step, wherein the prompt information can comprise text matched from html analysis data based on keywords, so that the test personnel can conveniently remove the reason that the test action cannot be completed. The prompt message may prompt the relevant tester that the test procedure needs to be modified. For example, the tester may modify the keywords, test actions or parameter values in the test steps, etc., i.e. a new user operation. And returning to execute the step of responding to the user operation to determine the selected optional test content and/or receive the custom test content based on the new user operation, namely generating a new test step according to the new user operation, and debugging the new test step. In addition, it should be noted that, if the positioning of the test element cannot be accurately completed because the keyword of the test element in the test step, the test element may be described by using the ID (Identity document, identity) or xpath path of the test element instead of the keyword.
The page element positioning device provided by the application adopts the page element positioning method in the embodiment, and aims at solving the technical problem that the traditional pressure measurement mode is difficult to adapt to the test requirements of different scenes. Compared with the prior art, the beneficial effects of the page element positioning device provided by the embodiment of the present application are the same as those of the page element positioning method provided by the above embodiment, and other technical features of the page element positioning device are the same as those disclosed by the method of the above embodiment, which are not described in detail herein.
In addition, to achieve the above object, the present application further provides an electronic device, including: the page element positioning device comprises a memory, a processor and a page element positioning program which is stored in the memory and can run on the processor, wherein the page element positioning program realizes the steps of the page element positioning method when being executed by the processor.
The specific implementation manner of the electronic device is basically the same as the above embodiments of the page element positioning method, and will not be repeated here.
In addition, in order to achieve the above object, the present application further provides a storage medium, on which a page element positioning program is stored, which when executed by a processor, implements the steps of the page element positioning method as described above.
The specific implementation manner of the storage medium is basically the same as that of each embodiment of the page element positioning method, and is not repeated here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for describing, and do not represent advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) as described above, including several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method described in the embodiments of the present application.
The foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the claims, and all equivalent structures or equivalent processes using the descriptions and drawings of the present application, or direct or indirect application in other related technical fields are included in the scope of the claims of the present application.

Claims (10)

1. The page element positioning method is characterized by comprising the following steps:
determining htm l analysis data of a target page;
determining a target text from the html analysis data based on the keywords of the test elements in the test step of the target page;
and determining the position information of the test element on the target page based on the structure level of the target text in the html analysis data.
2. The page element locating method according to claim 1, wherein before the step of determining target text from the html parsing data based on the keywords of the target element in the testing step, the method comprises:
outputting selectable test contents, wherein the selectable test contents comprise keywords of test elements and test actions, and the types of the test actions comprise single actions and combined actions;
Responsive to user operation, determining selected selectable test content and/or receiving custom test content;
generating a test step based on the selected selectable test content and/or the received custom test content.
3. The page element positioning method according to claim 2, wherein after the step of generating a test step based on the selected selectable test content and/or the received custom test content, the method comprises:
if a plurality of selectable texts are determined based on keywords of the test elements in the test step in the process of debugging and executing the test step, respectively determining the positions of the test elements in the target page based on the selectable texts to obtain the selectable positions;
determining a target position in each optional position, wherein the target position can finish the test action in the test step;
and associating the identification of the optional text corresponding to the target position with the keyword to complete the debugging of the testing step.
4. The method for locating page elements according to claim 3, wherein the keywords are associated with identifications, and the step of determining the target text from the html parsing data based on the keywords of the test element in the step of testing the target page comprises:
Matching texts which are the same as the keywords in the html analysis data based on the keywords of the test elements to obtain matching texts;
and selecting target text from the matched texts according to the identification of the keyword association.
5. A method of positioning page elements as recited in claim 3 wherein said step of determining a target location in each of said selectable locations at which a test action in said step of testing can be completed comprises:
optionally taking one optional position from the optional positions, and executing the test action of the test step based on the optional position;
if the test action is executed, the optional position is taken as a target position;
if the test action is not executed, a new optional position is selected, and the step of executing the test action of executing the test step based on the optional position is returned based on the new optional position until each optional position is traversed.
6. The page element locating method of claim 5, wherein after said step of traversing each of said selectable positions, said method comprises:
if the target position capable of completing the test action in the test step is not selected after the optional positions are traversed, outputting prompt information of failure in execution of the test step;
And after receiving a new user operation, returning to execute the step of responding to the user operation and determining the selected selectable test content and/or receiving the custom test content based on the new user operation.
7. The page element positioning method according to claim 1, wherein the testing step includes a load wait time period and a testing action, and after the step of determining location information of the test element on the target page based on a structure level of the target text in the html parsing data, the method includes:
after waiting for the loading waiting time period, executing the test action on the test element based on the position information;
and if the test action fails to be executed, after waiting the loading waiting time again, returning to execute the step of executing the test action on the test element based on the position information until the test action is executed successfully or the total waiting time reaches the preset time.
8. The page element positioning method according to any one of claims 1 to 7, wherein the keyword of the test element is a name, a tag or a prompt of the test element, and wherein in the case that the test element is a non-text element, the keyword of the test element is a text description of an adjacent element of the test element.
9. An electronic device, the electronic device comprising: memory, a processor and a page element locating program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the page element locating method of any one of claims 1 to 8.
10. A storage medium, characterized in that the storage medium is a computer-readable storage medium, on which a page element positioning program is stored, which when executed by a processor implements the steps of the page element positioning method according to any one of claims 1 to 8.
CN202311396223.XA 2023-10-25 2023-10-25 Page element positioning method, electronic device and storage medium Pending CN117472744A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311396223.XA CN117472744A (en) 2023-10-25 2023-10-25 Page element positioning method, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311396223.XA CN117472744A (en) 2023-10-25 2023-10-25 Page element positioning method, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN117472744A true CN117472744A (en) 2024-01-30

Family

ID=89637158

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311396223.XA Pending CN117472744A (en) 2023-10-25 2023-10-25 Page element positioning method, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN117472744A (en)

Similar Documents

Publication Publication Date Title
Fantechi et al. Applications of linguistic techniques for use case analysis
CN109710508B (en) Test method, test device, test apparatus, and computer-readable storage medium
US7398469B2 (en) Automated test system for testing an application running in a windows-based environment and related methods
CN111142988B (en) Page test method and device, storage medium and electronic equipment
CN109308254B (en) Test method, test device and test equipment
CN110704304B (en) Application program testing method and device, storage medium and server
CN110688307B (en) JavaScript code detection method, device, equipment and storage medium
CN110825618B (en) Method and related device for generating test case
CN110825619A (en) Automatic generation method and device of interface test case and storage medium
CN110928763A (en) Test method, test device, storage medium and computer equipment
US8745521B2 (en) System and method for annotating graphical user interface
CN112597052A (en) Interface testing method and device and computer readable storage medium
CN111667231B (en) Automatic tax return method, device, system, computer equipment and storage medium
US20140082582A1 (en) Resource Tracker
US6763360B2 (en) Automated language and interface independent software testing tool
US8656267B2 (en) Method of approximate document generation
CN110688315A (en) Interface code detection report generation method, electronic device, and storage medium
CN111078529A (en) Client write-in module testing method and device and electronic equipment
CN117472744A (en) Page element positioning method, electronic device and storage medium
CN115964269A (en) Test processing method and device, electronic equipment and storage medium
CN114528218A (en) Test program generation method, test program generation device, storage medium, and electronic device
CN112667502A (en) Page testing method, device and medium
CN112380133A (en) Method and device for simulating instruction set simulator by using function library
CN115470127B (en) Page compatibility processing method, device, computer equipment and storage medium
CN117171052B (en) Script testing method, device, equipment and medium based on XML language

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination