CN115344494A - Element positioning method and device of test case, computer equipment and medium - Google Patents
Element positioning method and device of test case, computer equipment and medium Download PDFInfo
- Publication number
- CN115344494A CN115344494A CN202211005007.3A CN202211005007A CN115344494A CN 115344494 A CN115344494 A CN 115344494A CN 202211005007 A CN202211005007 A CN 202211005007A CN 115344494 A CN115344494 A CN 115344494A
- Authority
- CN
- China
- Prior art keywords
- page
- path
- elements
- sub
- page element
- 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
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3684—Test management for test design, e.g. generating new test cases
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/3668—Software testing
- G06F11/3672—Test management
- G06F11/3688—Test management for test execution, e.g. scheduling of test suites
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Debugging And Monitoring (AREA)
Abstract
The application is applicable to the technical field of automatic testing, and particularly relates to an element positioning method and device of a test case, computer equipment and a medium. The method includes the steps of generating a page element path for a test case according to a preset element path generation rule, splitting the page element path into two sub-paths when at least two page elements are selected when the page element path is detected to be triggered, detecting the area of the page elements obtained through query of a first sub-path, determining the page elements with the area not being zero as suspected elements, obtaining the page elements with the area not being zero as target elements through query of a second sub-path in a page range corresponding to the suspected elements, and determining the target elements as elements positioned by the page element path if the positions of all the page elements selected by the page element path in the page and the positions of the target elements in the page have the same positions, so that the positioning of the target elements is accurately realized, and the execution passing rate of the test case is improved.
Description
Technical Field
The application is applicable to the technical field of automatic testing, and particularly relates to an element positioning method and device of a test case, computer equipment and a medium.
Background
At present, when recording an automated test case on a User Interface (UI), a page element to be operated in a test step needs to be selected and an "element path" thereof needs to be recorded. This step can be automatically generated when an automated testing framework is used, the generated element path is generally an XPath absolute path, that is, the element path includes all levels from the root element html to the target page element, and if there are multiple elements of the same type in each level, the order of the elements in the level will be recorded, but the level and the order will also be changed when the page function is changed. Because some elements in the page are dynamically generated according to user operations, for example, a selector is displayed in a popup window, such elements are generally referred to as "dynamic elements" hereinafter, an absolute path of the dynamic element is usually inconsistent with a recording sequence at a certain level, if the influence of path change on case execution success rate is to be avoided, an ID selector is generally required to be added in a front-end service code to realize the positioning of the element, but this method has certain intrusiveness on the service code and also increases debugging cost of case recording, and another method is to preferentially use a class selector to realize the positioning of the dynamic element when identifying the content which may be the dynamic element, but a plurality of page elements may be selected by using the class selector, and finally, the correct element cannot be selected during execution, and a test case needs to be re-recorded. In order to reduce the maintenance cost of the test script, a tester generally needs to have certain automated test experience or front-end knowledge to manually identify whether the element path is reliable. Therefore, how to eliminate the irrelevant elements and realize the accurate positioning of the elements becomes a problem to be solved urgently.
Disclosure of Invention
In view of this, embodiments of the present application provide a method, an apparatus, a computer device, and a medium for locating elements of a test case, so as to solve a problem how to eliminate irrelevant elements and achieve accurate location of the elements.
In a first aspect, an embodiment of the present application provides an element location method for a test case, where the element location method includes:
generating a page element path for the test case according to a preset element path generation rule, and detecting whether at least two page elements are selected when the page element path is triggered;
if at least two page elements are selected when the page element path is detected to be triggered, splitting the page element path into a first sub-path and a second sub-path, wherein the first sub-path at least selects the page elements in the outermost page of all the page elements when triggered, and the second sub-path selects all the page elements except the page elements selected when the first sub-path is triggered;
detecting the area of a page element obtained by using the first sub-path query, determining the page element with the area not being zero as a suspected element, and obtaining the page element with the area not being zero as a target element by using the second sub-path query in a page range corresponding to the suspected element;
and comparing the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page, and if the comparison result shows that the same positions exist, determining that the target elements are the elements positioned by the page element path.
In an embodiment, generating a page element path for the test case according to a preset element path generation rule includes:
detecting element characteristics of page elements contained in the test case;
if the element characteristic is detected to be a first characteristic, generating a page element path corresponding to the page element by using an ID selector;
and if the element characteristic is detected to be a second characteristic, generating a page element path corresponding to the page element by using a class selector.
In an embodiment, after detecting element features of page elements included in the test case, the method further includes:
if the element features are detected to be text node features and the corresponding element contents are not empty, recording the contents of the corresponding page elements, and generating a text selector for inquiring the text contents according to the contents of the element features;
generating a page element path corresponding to the page element using the text selector.
In one embodiment, comparing the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page respectively comprises:
comparing the positions of all the page elements selected by the page element path with the target element in sequence by using a method for comparing document positions;
and determining a position comparison result, wherein the position comparison result comprises the same position, a front-back relation and an inclusion relation.
In one embodiment, detecting that the area of the page element is obtained by using the first sub-path query, and determining that the page element with the area not equal to zero is a suspected element includes:
acquiring the length, width or height of a page element in a page by using the first sub-path query;
and detecting whether an item with the length, the width or the height of zero exists, if so, determining that the area of the corresponding page element is zero, otherwise, determining that the corresponding page element is a suspected element.
In one embodiment, splitting the page element path into a first sub-path and a second sub-path comprises:
extracting the levels of the pages where all the page elements corresponding to the page element paths are located, and determining the levels as the outermost page elements;
and intercepting paths corresponding to the page elements with the outermost layer as first sub-paths from the page element paths, and intercepting paths corresponding to the remaining page elements from the page element paths as second sub-paths.
In a second aspect, an embodiment of the present application provides an element location apparatus for a test case, where the element location apparatus includes:
the path detection module is used for generating a page element path for the test case according to a preset element path generation rule and detecting whether at least two page elements are selected when the page element path is triggered;
the path splitting module is configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered, at least the page element in an outermost page of all the page elements is selected when the first sub-path is triggered, and all the page elements except the page element selected when the first sub-path is triggered are selected when the second sub-path is triggered;
a target element determining module, configured to detect an area of a page element obtained through query using the first sub-path, determine that the page element with the area that is not zero is a suspected element, and obtain the page element with the area that is not zero as a target element through query using the second sub-path in a page range corresponding to the suspected element;
and the positioning determining module is used for comparing the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page respectively, and determining the target elements as the elements positioned by the page element path if the comparison result shows that the same positions exist.
In one embodiment, the path detection module comprises:
the element characteristic detection unit is used for detecting the element characteristics of the page elements contained in the test case;
a first path generating unit configured to generate a page element path corresponding to a page element using an ID selector if it is detected that the element feature is a first feature;
and the second path generating unit is used for generating the page element path corresponding to the page element by using the class selector if the element characteristic is detected to be the second characteristic.
In one embodiment, the path detection module further comprises:
the text element detection unit is used for recording the content of the corresponding page element and generating a text selector for inquiring the text content according to the content of the element feature if the element feature is detected to be a text node feature and the content of the corresponding element is not empty after the element feature of the page element contained in the test case is detected;
a third path generating unit for generating a page element path corresponding to the page element using the text selector.
In one embodiment, the location determination module comprises:
the position comparison unit is used for sequentially comparing the positions of all the page elements selected by the page element path with the target element by using a document position comparison method;
and the comparison result determining unit is used for determining a position comparison result, and the position comparison result comprises the same position, a front-back relationship and an inclusion relationship.
In one embodiment, the target element determination module comprises:
the side length obtaining unit is used for obtaining the length, the width or the height of the page element in the page by using the first sub-path query;
and the suspected element determining unit is used for detecting whether an item with the length, the width or the height of zero exists, if the item with the length, the width or the height of zero exists, the area of the corresponding page element is determined to be zero, and if the item with the length, the width or the height of zero exists, the corresponding page element is determined to be the suspected element.
In one embodiment, the path splitting module includes:
the splitting point determining unit is used for extracting the page levels of all the page elements corresponding to the page element path and determining the page elements with the outermost level;
and the path splitting unit is used for intercepting paths corresponding to the page elements with the outermost layer as first sub-paths from the page element paths, and intercepting paths corresponding to the remaining page elements from the page element paths as second sub-paths.
In a third aspect, an embodiment of the present application provides a computer device, where the computer device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor, when executing the computer program, implements the element location method according to the first aspect.
In a fourth aspect, the present application provides a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the computer program implements the element location method according to the first aspect.
Compared with the prior art, the embodiment of the application has the advantages that: according to the method, a page element path is generated for a test case according to a preset element path generation rule, whether at least two page elements are selected when the page element path is triggered is detected, if the at least two page elements are selected when the page element path is detected to be triggered, the page element path is divided into a first sub-path and a second sub-path, the page elements in the outermost page are at least selected when the first sub-path is triggered, all the page elements except the page elements selected when the first sub-path is triggered are selected when the second sub-path is triggered, the area of the page elements obtained by using the first sub-path for inquiry is detected, the page elements with the area not equal to zero are determined to be suspected elements, the page elements with the area not equal to zero are obtained by using the second sub-path for inquiry in a page range corresponding to the suspected elements, the positions of all the page elements selected by using the page element path in the page are respectively compared with the positions of the target elements in the page, and if the comparison result is that the same position exists, the target elements are determined to be the elements positioned by the page element path, so that the test case positioning is accurately realized, and the test case execution rate is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic diagram of an application environment of a method for locating elements of a test case according to an embodiment of the present application;
fig. 2 is a schematic flowchart of an element positioning method for a test case according to a second embodiment of the present application;
fig. 3 is a schematic flowchart of an element location method for a test case according to a third embodiment of the present application;
fig. 4 is a schematic structural diagram of an element locating apparatus for a test case according to a fourth embodiment of the present application;
fig. 5 is a schematic structural diagram of a computer device according to a fifth embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
The embodiment of the application can acquire and process related data based on an artificial intelligence technology. Among them, artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence base technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
It should be understood that, the sequence numbers of the steps in the following embodiments do not mean the execution sequence, and the execution sequence of each process should be determined by the function and the inherent logic of the process, and should not constitute any limitation to the implementation process of the embodiments of the present application.
In order to explain the technical means of the present application, the following description will be given by way of specific examples.
The element positioning method for the test case provided by the embodiment of the application can be applied to an application environment as shown in fig. 1, wherein a client communicates with a server. The client includes, but is not limited to, a palm top computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud computing device, a Personal Digital Assistant (PDA), and other computing devices. The server can be implemented by an independent server or a server cluster composed of a plurality of servers.
Referring to fig. 2, a flowchart of an element location method for a test case provided in the second embodiment of the present application is shown, where the element location method for a test case is applied to the server in fig. 1, and a computer device corresponding to the server is connected to a corresponding database to obtain a corresponding test case in the database. The computer equipment can also be connected with a corresponding client, the client is operated by a user, and the user can provide a corresponding test case to the server through the client. As shown in fig. 2, the method for locating elements of a test case may include the following steps:
step S201, generating a page element path for the test case according to a preset element path generation rule, and detecting whether at least two page elements are selected when the page element path is triggered.
In this application, the element path generation rule may be set according to an actual application requirement, where the actual application requirement may refer to a case that a requirement for a test case in an application scenario is that no dynamic element is included, it may be determined that a path is not required to be generated by using a specific element path generation rule, for example, the specific element path generation rule may refer to a rule corresponding to an ID selector and a class selector, that is, a conventional path generation rule is used.
The element path generation rule is used when the test case is recorded, and the generation rule is determined according to the selection of a user, so that the selected element path generation rule is used for generating the page element path for the test case.
In this application, the preset element path generation rule may include an ID selector, a class selector, a text selector, and the like, and specifically, if the page element path includes an ID, the ID selector is preferentially used to generate the page element path; in order to avoid operations such as adding an ID (identity) in a service code, and the like, when the characteristics of some dynamic elements contained in a page element path are identified during recording, a class selector can be preferentially used for generating the page element path; when the page element is identified as a text node and the corresponding content is not empty, the text content of the node can be recorded, a query text selector is generated, and a page element path is generated by using the text selector.
Optionally, generating a page element path for the test case according to a preset element path generation rule includes:
detecting element characteristics of page elements contained in the test case;
if the element characteristic is detected to be the first characteristic, generating a page element path corresponding to the page element by using an ID selector;
and if the element characteristic is detected to be the second characteristic, generating a page element path corresponding to the page element by using the class selector.
The element feature may refer to a feature such as an attribute and a category of the page element, for example, if the page element includes a dynamic attribute, it may be determined that the page element is a dynamic page element. The first characteristic is distinguished from the second characteristic, the first characteristic can refer to an ID attribute in a page element, the second characteristic can refer to a dynamic attribute in the page element, and when the page element contains the ID attribute, namely the element characteristic contains the first characteristic, an ID selector is used for generating a page element path corresponding to the page element; and when the page element contains the dynamic attribute, namely the element characteristic contains the second characteristic, generating a page element path corresponding to the page element by using a class selector.
It should be understood that a plurality of page elements may exist in one page at the same time, and accordingly, a plurality of page elements may also exist in a test case at the same time, and different selectors may be used for different page elements to generate a page path, thereby helping to distinguish the different page elements and achieving accurate and efficient positioning of the page elements.
Optionally, after detecting the element features of the page elements included in the test case, the method further includes:
if the element characteristics are detected to be text node characteristics and the corresponding element contents are not empty, recording the contents of the corresponding page elements, and generating a text selector for inquiring the text contents according to the contents of the element characteristics;
a page element path corresponding to the page element is generated using the text selector.
The text node feature may mean that the corresponding page element is a text element, for example, a text box in the page is a text element, and the content in the text box is the content of the corresponding element.
Since there may be redundant text boxes in operation, but the text boxes are not filled with content, and the presentation of the page is not affected when there is no content in the text boxes, but the page is still detected because, in order to avoid processing the useless text boxes, it is necessary to define the element content of the page element whose element feature is corresponding to the text node feature, that is, the element content is not empty.
Extracting element content corresponding to the page element, and generating a text selector according to the element content, wherein the purpose of the text selector is to generate a page element path corresponding to the page element, and essentially, the text selector is an expression containing the corresponding element content, as follows:
page.locator("text=Log in").click()
page.locator("text='Log in'").click()
wherein text = Log in and text = 'Log in' difference: log in is not primed (single or double quotes): fuzzy matching and insensitive to case; 'Log in' has quote: exact match and case sensitive.
Step S202, if at least two page elements are selected when the page element path is triggered, splitting the page element path into a first sub-path and a second sub-path.
In the application, when the first sub-path is triggered, at least the page elements in the outermost page of all the page elements are selected, and when the second sub-path is triggered, all the page elements except the page element selected when the first sub-path is triggered are selected.
After the page element path is executed, the page element path is located to more than two page elements, that is, under the condition that one page element path corresponds to multiple page elements, in order to accurately locate the target element, the page element path needs to be split, the splitting may refer to splitting the page element path into two segments, and the first segment may select the outermost page element, which may be referred to as a "parent element selector"; the second segment is where the remaining page elements can be selected, which may be referred to as a "child element selector".
In the case where the number of page elements in the outermost layer is plural, the number of parent element selectors also exists, but in general, the number of page elements in the outermost layer is 1, and one or more page elements exist in the remaining page elements.
Optionally, splitting the page element path into a first sub-path and a second sub-path includes:
extracting the levels of the pages where all the page elements corresponding to the page element paths are located, and determining the levels as the outermost page elements;
and intercepting paths corresponding to the page elements with the outermost layer as a first sub-path from the page element paths, and intercepting paths corresponding to the remaining page elements from the page element paths as second sub-paths.
The method comprises the steps of extracting the hierarchy attribute of the page element, further knowing the hierarchy feature of each page element, and comparing the hierarchy features of all the page elements, thereby determining the page element with the outermost layer as the hierarchy.
After the page element with the outermost layer as the hierarchy is obtained, a path corresponding to the page element is intercepted from the page element path aiming at the page element, namely the first sub-path, and the rest page elements can obtain the corresponding path from the page element path, namely the second sub-path.
Step S203, detecting the area of the page element obtained by using the first sub-path query, determining the page element with the area not equal to zero as a suspected element, and obtaining the page element with the area not equal to zero as a target element by using the second sub-path query within the page range corresponding to the suspected element.
In the method, the page elements which can be inquired by the parent element selector are traversed, whether the corresponding page elements are visible page elements or not is judged, if the corresponding page elements are visible page elements, the visible page elements are used as inquiry ranges, the corresponding page elements are inquired by the child element selector, and if the corresponding page elements are invisible page elements, the corresponding page elements are not considered to be the current direction needing to be searched.
The visible page element is that the area displayed in the page by the corresponding page element is not zero, and it can also be understood that the length, width and height of the visible page element are not 0.
For a visible page element, among a plurality of page elements, a suspected element belonging to a suspected target element may eventually include the target element, and thus, after the suspected element is obtained, the corresponding target element may be found in an enclosing range or an enclosing area in the page corresponding to the suspected element.
And under the condition that the range of the suspected elements in the page is used as a condition, the page element obtained by using the second sub-path, namely the sub-element selector for query is the target element, and the target element at the moment may be a target to be finally positioned or not. There may be a plurality of target elements found by using the second sub-path, so that further confirmation is required in step S204.
Optionally, the detecting that the area of the page element is obtained by using the first sub-path query, and determining that the page element with the area not equal to zero is a suspected element includes:
acquiring the length, width or height of a page element in a page by using a first sub-path query;
and detecting whether an item with the length, the width or the height of zero exists, if so, determining that the area of the corresponding page element is zero, otherwise, determining that the corresponding page element is a suspected element.
The size of the Page element in the Page can be measured by adopting Page Ruler, and the Page Ruler is a plug-in of a Page measuring Ruler and can effectively measure the size of the Page element.
During detection, the area can be determined to be zero as long as any size of the page elements is measured to be zero, and the corresponding page elements are invisible page elements and are not suspected elements.
Step S204, the positions of all the page elements in the page selected by using the page element path are respectively compared with the positions of the target elements in the page, and if the comparison result shows that the same positions exist, the target elements are determined to be the elements positioned by the page element path.
In the application, after the target element is determined, in order to determine whether the target element is an element to be located by the test case, the target element needs to be further confirmed.
And positioning the positions of all the page elements selected by the page element path from the page, similarly, positioning the position of the target element in the page, and if the position of the target element in the page is the same as the position of any page element selected by the page element path, indicating that the page element is the element to be positioned finally.
Through the steps, elements which are not required to be selected in the page can be eliminated, and the accuracy of the target elements in the path of the page elements is greatly improved, so that the case execution passing rate is ensured, and the debugging cost of testers is reduced.
Originally, when a tester records a case, a method for identifying which positioning element is used is generally adopted in a mode of adding an ID selector in a service code when the tester cannot debug the case. The method provided by the application can generate more reliable element positioning according to the actual situation of the page elements.
Meanwhile, aiming at the condition that a plurality of page elements can be positioned when the test case is executed, the processing method provided by the scheme can eliminate the elements which are not selected in the page, and effectively improves the accuracy of the target elements selected by the page element path, thereby ensuring the case execution passing rate and reducing the debugging cost of testers.
According to the method and the device, a page element path is generated for a test case according to a preset element path generation rule, whether at least two page elements are selected when the page element path is triggered is detected, if the at least two page elements are selected when the page element path is triggered, the page element path is divided into a first sub-path and a second sub-path, the page elements in the outermost page are selected at least when the first sub-path is triggered, all the page elements except the page elements selected when the first sub-path is triggered are selected when the second sub-path is triggered, the area of the page elements obtained by using the first sub-path query is detected, the page elements with the area not being zero are determined to be suspected elements, the page elements with the area not being zero are obtained by using the second sub-path query within a page range corresponding to the suspected elements, the positions of all the page elements selected by using the page element path in the page are respectively compared with the positions of the target elements in the page, and if the comparison result is that the same position exists, the target elements are determined to be the elements positioned by the page element path, so that the test case element positioning is accurately realized, and the test case testing personnel pass the debugging cost is reduced.
Referring to fig. 3, which is a schematic flow chart of a method for locating an element of a test case provided in the third embodiment of the present application, as shown in fig. 3, the method for locating an element of a test case may include the following steps:
step S301, generating a page element path for the test case according to a preset element path generating rule, and detecting whether at least two page elements are selected when the page element path is triggered.
Step S302, if it is detected that at least two page elements are selected when the page element path is triggered, splitting the page element path into a first sub-path and a second sub-path.
Step S303, detecting the area of the page element obtained by using the first sub-path query, determining the page element with the area not being zero as a suspected element, and obtaining the page element with the area not being zero as a target element by using the second sub-path query within a page range corresponding to the suspected element.
The contents of steps S301 to S303 are the same as those of steps S201 to S203, and the descriptions of steps S201 to S203 may be referred to, which are not repeated herein.
And step S304, sequentially comparing the positions of all the page elements selected by the page element path with the target elements by using a document position comparison method.
In the present application, a Document position class method, that is, a method class of composition Document position in a Document Object Model (DOM) interface, is compared, so as to compare the position relationship between two elements. The composedocumentposition () method compares the document position of the current node with the specified node in the document order. The DOM is a standard programming interface for the W3C organization to process extensible markup language.
When using the compare documentposition method class, the return value may be:
1: without relation, these two elements do not belong to the same document;
2: the first element (P1) is located after the second element (P2);
4: the first element (P1) is positioned before the second element (P2);
8: the first element (P1) is located within the second element (P2);
16: the second element (P2) is located within the first element (P1);
32: two attributes that have no relationship or are two nodes in the same element;
40: the first element (P1) is in the same position as the second element (P2).
Where the return value may be a combination of values, for example, return 20 means that P2 is inside P1 (16) and P1 precedes P2 (4).
Step S305, determining a position comparison result, wherein the position comparison result comprises the same position, the front-back relationship and the inclusion relationship.
Through the above process, the document positions of the two elements are compared by using the composedocumentposition, and the result is various: identical in position, A before B, A after B, A within B, B within A, etc.
Step S306, if the comparison result indicates that the same position exists, determining that the target element is an element located by the page element path.
The content of step S306 is the same as that of step S204, and reference may be made to the description of step S204, which is not repeated herein.
According to the method, the page element path is generated for the test case according to a preset element path generation rule, whether at least two page elements are selected when the page element path is triggered is detected, if the at least two page elements are selected when the page element path is triggered, the page element path is divided into a first sub-path and a second sub-path, the page elements in the outermost page are at least selected when the first sub-path is triggered, all the page elements except the page elements selected when the first sub-path is triggered are selected when the second sub-path is triggered, the area of the page elements obtained by using the first sub-path query is detected, the page elements with the area not being zero are determined to be suspected elements, the page elements with the area not being zero are obtained by using the second sub-path query within a page range corresponding to the suspected elements, a comparison document position method is used, all the page elements selected by the page element path are sequentially compared with the target elements, if the comparison result is that the same position exists, the target elements are determined to be the elements positioned by the page element path, so that the positioning of the target elements is accurately realized, the test case positioning of the test case is improved, and the test case executing cost is reduced.
Corresponding to the element positioning method of the test case in the foregoing embodiment, fig. 4 shows a structural block diagram of an element positioning device of the test case provided in the fourth embodiment of the present application, where the element positioning device is applied to the server in fig. 1, and a computer device corresponding to the server is connected to a corresponding database to obtain corresponding data in the database. The computer equipment can also be connected with a corresponding client, the client is operated by a user, and the user can provide a corresponding test report to the server through the client. For convenience of explanation, only portions related to the embodiments of the present application are shown.
Referring to fig. 4, the element positioning apparatus includes:
the path detection module 41 is configured to generate a page element path for the test case according to a preset element path generation rule, and detect whether at least two page elements are selected when the page element path is triggered;
the path splitting module 42 is configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered, where the first sub-path at least selects a page element in an outermost page of all the page elements when triggered, and the second sub-path selects all page elements except the page element selected when the first sub-path is triggered;
a target element determining module 43, configured to detect the area of the page element obtained through query by using the first sub-path, determine that the page element with the area that is not zero is a suspected element, and obtain the page element with the area that is not zero as a target element through query by using the second sub-path in a page range corresponding to the suspected element;
and the positioning determining module 44 is configured to compare the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page, and determine that the target elements are the elements positioned by the page element path if the comparison result shows that the same positions exist.
Optionally, the path detecting module 41 includes:
the element characteristic detection unit is used for detecting the element characteristics of the page elements contained in the test cases;
a first path generating unit configured to generate a page element path corresponding to the page element using the ID selector if the element feature is detected as the first feature;
and the second path generating unit is used for generating the page element path corresponding to the page element by using the class selector if the element characteristic is detected to be the second characteristic.
Optionally, the path detecting module 41 further includes:
the text element detection unit is used for recording the content of the corresponding page element and generating a text selector for inquiring the text content according to the content of the element feature if the element feature is detected to be a text node feature and the content of the corresponding element is not empty after the element feature of the page element contained in the test case is detected;
a third path generating unit for generating a page element path corresponding to the page element using the text selector.
Optionally, the positioning determining module 44 includes:
the position comparison unit is used for sequentially comparing the positions of all the page elements selected by the page element path with the target elements by using a document position comparison method;
and the comparison result determining unit is used for determining a position comparison result, and the position comparison result comprises the same position, a front-back relationship and an inclusion relationship.
Optionally, the target element determining module 43 includes:
the side length obtaining unit is used for obtaining the length, the width or the height of the page element in the page by using the first sub-path query;
and the suspected element determining unit is used for detecting whether an item with the length, the width or the height of zero exists, if the item with the length, the width or the height of zero exists, the area of the corresponding page element is determined to be zero, and if the item with the length, the width or the height of zero exists, the corresponding page element is determined to be the suspected element.
Optionally, the path splitting module 42 includes:
the splitting point determining unit is used for extracting the page levels of all the page elements corresponding to the page element paths and determining the page elements with the levels as the outermost layers;
and the path splitting unit is used for intercepting paths corresponding to the page elements with the outermost layer as first sub-paths from the page element paths, and intercepting paths corresponding to the remaining page elements from the page element paths as second sub-paths.
It should be noted that, because the above-mentioned information interaction between the modules, the execution process, and other contents are based on the same concept, specific functions, and technical effects brought by the method embodiment of the present application may be specifically referred to a part of the method embodiment, and are not described herein again.
Fig. 5 is a schematic structural diagram of a computer device according to a fifth embodiment of the present application. As shown in fig. 5, the computer apparatus of this embodiment includes: the test case component positioning system comprises at least one processor (only one shown in fig. 5), a memory, and a computer program stored in the memory and executable on the at least one processor, wherein the processor implements the steps of any of the above-described element positioning method embodiments of the test case when executing the computer program.
The computer device may include, but is not limited to, a processor, a memory. It will be appreciated by those skilled in the art that fig. 5 is merely an example of a computer device and is not intended to be limiting, and that a computer device may include more or fewer components than those shown, or some components may be combined, or different components may be included, such as a network interface, a display screen, and input devices, etc.
The Processor may be a CPU, or other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory includes readable storage medium, internal memory, etc., where the internal memory may be a memory of the computer device, and the internal memory provides an environment for the operating system and the execution of computer-readable instructions in the readable storage medium. The readable storage medium may be a hard disk of the computer device, and in other embodiments may also be an external storage device of the computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, provided on the computer device. Further, the memory may also include both internal and external storage units of the computer device. The memory is used for storing an operating system, application programs, a BootLoader (BootLoader), data, and other programs, such as program codes of a computer program, and the like. The memory may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules, so as to perform all or part of the functions described above. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the above-mentioned apparatus may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method of the embodiments described above can be implemented by a computer program, which can be stored in a computer readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code, recording medium, computer Memory, read-Only Memory (ROM), random Access Memory (RAM), electrical carrier signals, telecommunications signals, and software distribution media. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.
When the computer program product runs on a computer device, the computer device is enabled to implement the steps in the method embodiments.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/computer device and method may be implemented in other ways. For example, the above-described apparatus/computer device embodiments are merely illustrative, and for example, a module or a unit may be divided into only one logical function, and may be implemented in other ways, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not implemented. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be through some interfaces, indirect coupling or communication connection of devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.
Claims (10)
1. An element positioning method for a test case, the element positioning method comprising:
generating a page element path for the test case according to a preset element path generation rule, and detecting whether at least two page elements are selected when the page element path is triggered;
if at least two page elements are selected when the page element path is detected to be triggered, splitting the page element path into a first sub-path and a second sub-path, wherein the page elements in the outermost page in all the page elements are selected at least when the first sub-path is triggered, and all the page elements except the page elements selected when the first sub-path is triggered are selected when the second sub-path is triggered;
detecting the area of a page element obtained by using the first sub-path query, determining the page element with the area not being zero as a suspected element, and obtaining the page element with the area not being zero as a target element by using the second sub-path query in a page range corresponding to the suspected element;
and comparing the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page, and if the comparison result shows that the same positions exist, determining that the target elements are the elements positioned by the page element path.
2. The element positioning method according to claim 1, wherein generating a page element path for the test case according to a preset element path generation rule comprises:
detecting element characteristics of page elements contained in the test case;
if the element characteristic is detected to be a first characteristic, generating a page element path corresponding to the page element by using an ID selector;
and if the element characteristic is detected to be the second characteristic, generating a page element path corresponding to the page element by using a class selector.
3. The element localization method according to claim 2, wherein after detecting the element features of the page elements included in the test case, the method further comprises:
if the element features are detected to be text node features and the corresponding element contents are not empty, recording the contents of the corresponding page elements, and generating a text selector for inquiring the text contents according to the contents of the element features;
generating a page element path corresponding to a page element using the text selector.
4. The element localization method according to claim 1, wherein comparing the positions in the page of all the page elements selected using the page element path with the positions in the page of the target element respectively comprises:
comparing the positions of all the page elements selected by the page element path with the target element in sequence by using a method for comparing document positions;
and determining a position comparison result, wherein the position comparison result comprises the same position, a front-back relationship and an inclusion relationship.
5. The element localization method according to claim 1, wherein detecting an area of a page element obtained by using the first sub-path query, and determining a page element with an area different from zero as a suspected element comprises:
acquiring the length, width or height of a page element in a page by using the first sub-path query;
and detecting whether an item with the length, the width or the height of zero exists, if so, determining that the area of the corresponding page element is zero, otherwise, determining that the corresponding page element is a suspected element.
6. The element localization method of any of claims 1 to 5, wherein splitting the page element path into a first sub-path and a second sub-path comprises:
extracting the levels of the pages where all the page elements corresponding to the page element paths are located, and determining the levels as the outermost page elements;
and intercepting paths corresponding to the page elements with the outermost layer as first sub-paths from the page element paths, and intercepting paths corresponding to the remaining page elements from the page element paths as second sub-paths.
7. An element locator for a test case, the element locator comprising:
the path detection module is used for generating a page element path for the test case according to a preset element path generation rule and detecting whether at least two page elements are selected when the page element path is triggered;
the path splitting module is configured to split the page element path into a first sub-path and a second sub-path if it is detected that at least two page elements are selected when the page element path is triggered, at least the page element in an outermost page of all the page elements is selected when the first sub-path is triggered, and all the page elements except the page element selected when the first sub-path is triggered are selected when the second sub-path is triggered;
a target element determining module, configured to detect an area of a page element obtained through query using the first sub-path, determine that the page element with the area that is not zero is a suspected element, and obtain the page element with the area that is not zero as a target element through query using the second sub-path in a page range corresponding to the suspected element;
and the positioning determining module is used for comparing the positions of all the page elements in the page selected by using the page element path with the positions of the target elements in the page respectively, and determining the target elements as the elements positioned by the page element path if the comparison result shows that the same positions exist.
8. The element locator device of claim 7, wherein the path detection module comprises:
the element characteristic detection unit is used for detecting the element characteristics of the page elements contained in the test case;
a first path generating unit configured to generate a page element path corresponding to a page element using an ID selector if it is detected that the element feature is a first feature;
and the second path generating unit is used for generating the page element path corresponding to the page element by using the class selector if the element characteristic is detected to be the second characteristic.
9. A computer device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, the processor implementing the element localization method as claimed in any one of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the element localization method according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211005007.3A CN115344494A (en) | 2022-08-22 | 2022-08-22 | Element positioning method and device of test case, computer equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211005007.3A CN115344494A (en) | 2022-08-22 | 2022-08-22 | Element positioning method and device of test case, computer equipment and medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115344494A true CN115344494A (en) | 2022-11-15 |
Family
ID=83954411
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211005007.3A Pending CN115344494A (en) | 2022-08-22 | 2022-08-22 | Element positioning method and device of test case, computer equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115344494A (en) |
-
2022
- 2022-08-22 CN CN202211005007.3A patent/CN115344494A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10713149B2 (en) | Processing automation scripts of software | |
CN106294134B (en) | The collapse localization method and device of code | |
CN107665171B (en) | Automatic regression testing method and device | |
CN103246602B (en) | Code coverage determines method and system, code coverage detection method and system | |
US9740506B2 (en) | Automating interactions with software user interfaces | |
US10901879B2 (en) | Method and apparatus for automatic testing of web pages | |
CN111522741B (en) | Interface test code generation method and device, electronic equipment and readable storage medium | |
US20160210181A1 (en) | Analysis apparatus and analysis method | |
CN109783356A (en) | A kind of automated testing method and terminal | |
CN114116496A (en) | Automatic testing method, device, equipment and medium | |
CN112241370B (en) | API interface class checking method, system and device | |
US6745348B2 (en) | Method for estimating number of internationalization faults in software code | |
KR101696694B1 (en) | Method And Apparatus For Analysing Source Code Vulnerability By Using TraceBack | |
CN110262870B (en) | Method, device, computer equipment and storage medium for locating exception by dump file | |
KR20100069147A (en) | Method and apparatus for testing quality of website | |
US20080306752A1 (en) | Method and system for automatic testing in a business scenario environment | |
CN111444093B (en) | Method and device for determining quality of project development process and computer equipment | |
CN113312258A (en) | Interface testing method, device, equipment and storage medium | |
CN110532458B (en) | Method and device for determining search mode, server and storage medium | |
CN115481025A (en) | Script recording method and device for automatic test, computer equipment and medium | |
CN115344494A (en) | Element positioning method and device of test case, computer equipment and medium | |
CN110866492B (en) | Baseline branch identification method and device and computer system | |
CN113868137A (en) | Method, device and system for processing buried point data and server | |
CN116610552A (en) | Test case recommendation method and device, storage medium and electronic equipment | |
CN114546799A (en) | Point burying log checking method and device, electronic equipment, storage medium and product |
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 |