Page testing methods, apparatus, equipment and computer-readable storage media
By obtaining the correspondence between the identification information and feature information of web page elements, especially the coordinate information, and constructing a DOM tree structure, the problem of web page automated testing failing due to changes in element attributes is solved, achieving more stable testing and lower maintenance costs.
Patent Information
- Application Number
- CN202211255103.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-13
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-10-13
AI Technical Summary
In existing technologies, web page automated testing scripts are prone to failure due to changes in page element attribute information, leading to unstable testing.
By obtaining the correspondence between the identification information and feature information of page elements, especially the coordinate information, a DOM tree structure is constructed, elements are located for testing, and element identification information is updated to adapt to layout changes.
It improves the stability of page testing and reduces maintenance costs, while enhancing the convenience of element positioning and the reliability of testing.
Smart Images

Figure CN115687095B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to page testing methods, page testing apparatus, computer equipment, and computer-readable storage media. Background Technology
[0002] With the continuous development of internet technology, software products are being updated and iterated at an increasingly rapid pace. To ensure the functional accuracy of software products, software testing is an indispensable part of the development process. Web page (web) automated testing is one of the important software testing technologies. Currently, web automated testing typically involves locating elements based on their attribute information after the front-end page development is complete, and then performing automated testing. Element attribute information can include Extensible Markup Language (XML), XPath, Cascading Style Sheets (CSS), classes, etc. However, when the attribute information of page elements changes, the automated test script may fail, making it impossible to test the page elements. Summary of the Invention
[0003] This application provides a page testing method, apparatus, device, and computer-readable storage medium. By locating elements using their coordinate information on a page, the method can test those elements, thereby improving the stability of page testing.
[0004] In a first aspect, embodiments of this application provide a page testing method, which includes: obtaining the correspondence between the identification information and feature information of elements in a page; the feature information of the elements includes the coordinate information of the elements in the page; running a test script for the page, determining the coordinate information of the elements in the page according to the correspondence; the test script is generated based on the identification information of the elements; testing the elements according to the coordinate information of the elements in the page, and outputting the test results.
[0005] It is evident that in this technical solution, locating elements by their coordinate information on the page and then testing those elements helps improve the stability of page testing.
[0006] In one implementation, obtaining the correspondence between the identification information and feature information of elements on the page includes: parsing the page and constructing a tree structure corresponding to the page; mapping nodes in the tree structure to elements on the page; obtaining the identification information and feature information of nodes in the tree structure; the feature information of nodes in the tree structure includes the coordinate information of the nodes on the page; and constructing the correspondence between the identification information and feature information of the corresponding elements on the page based on the identification information and feature information of nodes in the tree structure.
[0007] It is evident that, in this technical solution, by constructing a correspondence between the identification information and feature information of elements on the page, it is easier to maintain the identification information and feature information of elements.
[0008] In one implementation, the feature information of nodes in the tree structure also includes the node label, node number, and node content; the feature information of elements also includes the node label, node number, and node content.
[0009] In one implementation, the page includes a first page and a second page; the second page is the updated version of the first page; the method further includes: comparing elements in the first page with elements in the second page to determine invalid elements in the first page and newly added elements in the second page; matching invalid elements with newly added elements to determine a target element that matches between invalid elements and newly added elements; and updating the identification information of the target element in the second page based on the identification information of the target element in the first page.
[0010] As can be seen, in this technical solution, by comparing the elements in the first page with the elements in the second page and updating the identification information of the elements in the second page, it is beneficial to reduce the page maintenance cost.
[0011] In one implementation, comparing elements on a first page with elements on a second page to determine invalid elements on the first page and newly added elements on the second page includes: comparing elements on the first page with elements on the second page according to a first preset rule to determine corresponding similar elements and first identical elements on the first and second pages, as well as first invalid elements on the first page other than similar elements and first identical elements, and first newly added elements on the second page other than similar elements and first identical elements; and determining second invalid elements on the first page and second newly added elements on the second page from similar elements according to a second preset rule; wherein invalid elements on the first page include first invalid elements and second invalid elements, and newly added elements on the second page include first newly added elements and second newly added elements.
[0012] In one implementation, according to a first preset rule, similar elements and first identical elements corresponding to the first page and the second page are determined, including: elements in the first page and the second page that have the same coordinate information, node labels, and node content, but different node numbers, are determined as similar elements corresponding to the first page and the second page; elements in the first page and the second page that have the same coordinate information, node labels, node numbers, and node content are determined as first identical elements corresponding to the first page and the second page.
[0013] In one implementation, according to a second preset rule, determining the second invalid element in the first page and the second newly added element in the second page from similar elements includes: determining the node number of the similar element in the first page as the original number of the corresponding similar element in the second page; determining the second identical element in the first page and the second page according to the level to which the similar element belongs in the second page and the order of the similar elements in the level; comparing the original number of the second identical element in the second page with the original number of the similar element in the second page that belongs to the same level as the second identical element to determine the second newly added element in the second page; and determining the similar element in the first page whose node number is the same as the original number of the second newly added element as the second invalid element in the first page.
[0014] Secondly, embodiments of this application provide a page testing apparatus, which includes: an acquisition unit, configured to acquire the correspondence between the identification information and feature information of elements in a page; the feature information of the elements includes the coordinate information of the elements in the page; and a processing unit, configured to run a test script for the page, determine the coordinate information of the elements in the page according to the correspondence; the test script is generated based on the identification information of the elements; the elements are tested according to the coordinate information of the elements in the page, and the test results are output.
[0015] Thirdly, embodiments of this application provide a computer device, including: a processor, a communication interface, and a memory, wherein the processor, the communication interface, and the memory are interconnected, wherein the memory stores executable program code, and the processor is used to call the executable program code to implement the method as described in the first aspect and any possible implementation thereof.
[0016] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the methods described in the first aspect and any possible implementation thereof.
[0017] Fifthly, embodiments of this application provide a computer program product comprising a computer program or computer instructions that, when executed by a processor, implement the methods as described in the first aspect and any possible implementation thereof.
[0018] In a sixth aspect, embodiments of this application provide a computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method as described in the first aspect and any of its possible implementations.
[0019] In this embodiment, by obtaining the correspondence between the identification information and feature information of elements on the page, it is easier to maintain the identification information and feature information of elements on the page. Furthermore, when running the test script of the page, the feature information of the element can be determined from the correspondence between the identification information and feature information of the element on the page based on the element's identification information. Then, the element can be located based on the coordinate information included in the feature information, so as to facilitate element testing. Compared with using the element's attribute information (such as XPath, CSS, class, etc.) for element location, it is beneficial to improve the stability of page testing. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of the implementation environment of a page testing method provided in an embodiment of this application;
[0022] Figure 2 This is a flowchart illustrating a page testing method provided in an embodiment of this application;
[0023] Figure 3 This is a schematic diagram illustrating the generation of a DOM tree based on an HTML document, provided in an embodiment of this application.
[0024] Figure 4 This is a flowchart illustrating another page testing method provided in an embodiment of this application;
[0025] Figure 5 This is a schematic diagram illustrating the representation of elements in a first page and a second page according to an embodiment of this application;
[0026] Figure 6 This is a schematic diagram illustrating another representation of elements in the first and second pages provided in an embodiment of this application;
[0027] Figure 7 This is a schematic diagram of the structure of a page testing device provided in an embodiment of this application;
[0028] Figure 8 It is a structural diagram of a computer device provided in an embodiment of the present application. Detailed Implementation
[0029] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0030] Please see Figure 1 This is a schematic diagram illustrating the implementation environment of a page testing method provided in an embodiment of this application. Figure 1 As shown, this implementation environment may include a page testing device 102 and a database 104. The database 104 may store the correspondence between the identification information and feature information of elements in the page. The page testing device 102 may be a server or a terminal device.
[0031] The terminal devices involved in the embodiments of this application can be personal computers, laptops, smartphones, tablets, smartwatches, smart voice interaction devices, smart home appliances, vehicle terminals, and smart wearable devices, but are not limited to these. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, and cloud storage. The database can be a local database or a cloud database accessible to the server. The terminal device and the server can be connected directly or indirectly through wired or wireless communication, and this application embodiment does not impose any limitations on this.
[0032] Please see Figure 2 This is a flowchart illustrating a page testing method provided in this application, which can be applied to... Figure 1 In the implementation environment shown, this is performed by the page testing device 102, such as Figure 2 As shown, the method includes, but is not limited to, the following steps:
[0033] S201, Obtain the correspondence between the identification information and feature information of elements on the page.
[0034] A page refers to the page currently being tested, such as a webpage written in Hypertext Markup Language (HTML). In this embodiment, the page may include one or more elements, and the correspondence between the identification information and feature information of the elements on the page may be presented in tabular form. In other implementations, the correspondence between elements may also be presented in other forms. The feature information of an element may include the coordinate information of the element on the page.
[0035] In one embodiment, the specific method for obtaining the correspondence between the identification information and feature information of elements on a page can be as follows: First, the page is parsed to construct a tree structure corresponding to the page, where the nodes in the tree structure correspond to the elements on the page; then, the identification information and feature information of the nodes in the tree structure are obtained, where the feature information of the nodes in the tree structure includes the coordinate information of the nodes on the page; finally, based on the identification information and feature information of the nodes in the tree structure, the correspondence between the identification information and feature information of the corresponding elements on the page is constructed. The tree structure corresponding to the page can be, for example, the document object model (DOM) tree of the page. The DOM tree can be generated based on the HTML document corresponding to the page. The DOM tree can use hierarchical nodes to represent the structure of the HTML document corresponding to the page, and the elements in the HTML document (i.e., the elements on the page) can be regarded as nodes in the DOM tree. In other words, the tree structure corresponding to the page can be used to represent the hierarchical relationship of elements on the page.
[0036] Example, Figure 3 This application provides a schematic diagram of generating a DOM tree based on an HTML document, as shown in the embodiment of the present application. Figure 3 As shown, the nodes in the DOM tree correspond to the content in the HTML document. For example, the root node 3021 in the DOM tree corresponds to the content in the HTML document. The child nodes of 3021 are 3022 and 3023. 3022 corresponds to none in the HTML document, and 3023 corresponds to class="data" in the HTML document. The child nodes of 3023 are 3024 and 3025. 3024 corresponds to the content in the HTML document. text1, 3025 corresponds to the HTML document text2 This represents the hierarchical structure of an HTML document.
[0037] For each node in the tree structure corresponding to the page, a unique identifier for that node can be generated, which is the element's identifier. Optionally, the identifier can be a universally unique identifier (UUID). The characteristic information of each node may include the node's coordinate information, which refers to the coordinates used to represent the actual position of the node on the page, so that the node's position on the page can be located based on the node's coordinate information. The node's coordinate information can be obtained, for example, by executing JS (javascript, a scripting language) statements.
[0038] In one embodiment, after obtaining the correspondence between the identification information and feature information of elements on the page, the correspondence can be stored in a database in the form of a table, or in a cloud storage, or in other specified locations. This application does not limit this.
[0039] S202, run the test script on the page and determine the coordinate information of the element on the page according to the correspondence.
[0040] The test script can be generated based on element identification information. The identification information of elements on the page distinguishes different elements, and the test script can contain different test instructions for different elements. For example, for a text box input element on the page, the test script may include text box input test instructions; for a button element on the page, the test script may include button click test instructions; and for a list box element on the page, the test script may include dropdown list selection test instructions.
[0041] Furthermore, when running the test script on the page, based on the element identification information in the test script, the feature information corresponding to the identification information of each element can be determined from the correspondence, and then the coordinate information of each element can be determined.
[0042] S203: Test the element based on its coordinates on the page and output the test results.
[0043] Specifically, during the execution of the page's test script, elements can be located based on their coordinates within the page. Then, based on these locations, the elements are tested, and the test results are obtained and output.
[0044] Before testing an element, you can first launch a browser. After launching the browser, the page will be displayed through the browser. Then, according to the test instructions in the test script, you can control the browser to interact with the server to complete the test of the element.
[0045] In this embodiment, by obtaining the correspondence between the identification information and feature information of elements on the page, it is easier to maintain the identification information and feature information of elements on the page. Furthermore, when running the test script of the page, the feature information of the element can be determined from the correspondence between the identification information and feature information of the element on the page based on the element's identification information. Then, the element can be located based on the coordinate information included in the feature information, so as to facilitate element testing. Compared with using the element's attribute information (such as XPath, CSS, class, etc.) for element location, it is beneficial to improve the stability of page testing.
[0046] In one embodiment, the layout of elements on the page may change, for example, developers may change the layout of elements according to actual needs. Based on this, this application provides another page testing method, please refer to [link to relevant documentation]. Figure 4 The following is a flowchart illustrating another page testing method provided in this application, which may include, but is not limited to, the following steps:
[0047] S401, compare the elements in the first page with the elements in the second page to determine the invalid elements in the first page and the newly added elements in the second page.
[0048] The second page is the updated version of the first page; that is, the second page is the version with the element layout changed from the first page.
[0049] In one embodiment, before comparing elements on the first page with elements on the second page, elements on the first page can be represented by feature information, and elements on the second page can be represented by feature information. The feature information of an element may include its coordinates on the page, the node label, node number, and node content within the page's tree structure. Taking a DOM tree as an example, the node label can refer to the node label in the corresponding HTML document within the DOM tree; the node number refers to the node's number within the same level of nodes in the DOM tree; and the node content can refer to the content in the corresponding HTML document within the DOM tree. For example,... Figure 3 As shown, Figure 3 The node tag for 3021 is ' / ', its node number is 1, and its content is empty (i.e., no content). The node tag for 3022 is ' / ', its node number is 1, and its content is 'none'. The node tag for 3023 is ' / ', its node number is 2, and its content is 'class="data"'. The node tag for 3024 is ' / / '. The node number is 1, and the node content is text1; the node label for node 3025 is / / The node number is 1, and the node content is text2.
[0050] Optionally, elements can be represented in the following format: `<node tag>(node number)node content`. It's worth noting that since a page's tree structure can include nodes at multiple levels, for nodes not at the first level, the format needs to include the node tag and node number of the node to which it belongs. For example, as shown... Figure 3 As shown, 3021 is a first-level node, which can be represented as (1). 3022 is a second-level node, and its format requires adding the node label and node number of the first-level node to which 3022 belongs (i.e., 3021), which can be represented as (1) / (1)none. Similarly, 3023 can be represented as (1) / (2)class="data". 3024 is a third-level node, and its format requires adding the node label and node number of the second-level node to which 3024 belongs (i.e., 3023), as well as the node label and node number of the first-level node to which 3023 belongs (i.e., 3021), which can be represented as (1) / (2) / (1) text1, similarly, 3025 can be represented as (1) / (2) / (1)text2.
[0051] In one embodiment, elements on the first page are represented by feature information of elements on the first page, and elements on the second page are represented by feature information of elements on the second page. Then, according to a first preset rule, elements on the first page and elements on the second page are compared to determine similar elements and first identical elements on the first and second pages, as well as first invalid elements on the first page other than similar elements and first identical elements, and first newly added elements on the second page other than similar elements and first identical elements. The first preset rule may include: ① determining elements on the first and second pages that have the same coordinate information, node labels, and node content, but different node numbers, as similar elements on the first and second pages; ② determining elements on the first and second pages that have the same coordinate information, node labels, node numbers, and node content, as first identical elements on the first and second pages.
[0052] For example, such as Figure 5 As shown, 5011 on the first page can be represented as (1) / (1) / (1)style1, 5012 on the second page can be represented as (1) / (1) / (1) style1, 5011 and 5012 have the same node information. Assuming that 5011 and 5012 also have the same coordinate information on the page, then 5011 and 5012 can be identified as the first corresponding identical element; 5021 on the first page can be represented as (1) / (2) / (2), 5022 on the second page can be represented as (1) / (3) / (3) 5021 and 5022 have the same node label and node content, but different node numbers. Assuming that 5021 and 5022 have the same coordinate information on the page, then 5021 and 5022 can be identified as corresponding similar elements.
[0053] Furthermore, according to the second preset rule, the second invalid element in the first page and the second newly added element in the second page can be determined from the similar elements. The second preset rule may include: ① determining the node number of the similar element in the first page as the original number of the corresponding similar element in the second page; ② determining the second identical element in the first page and the second page according to the level to which the similar element belongs in the second page and the order of the similar elements in the level; wherein, in the second page, there may be one or more similar elements in the same level, and for similar elements in the same level, the first similar element can be determined as the second identical element; ③ comparing the original number of the second identical element in the second page with the original number of the similar element in the second page that belongs to the same level as the second identical element. ④ Determine the second newly added element in the second page; specifically, in the second page, for similar elements at the same level, the original sequence number of the similar element can be compared with the original sequence number of the previous second identical element in a top-down order: if the original sequence number of the current similar element is greater than the original sequence number of the previous second identical element, then the current similar element is determined as the second identical element; if the original sequence number of the current similar element is less than the original sequence number of the previous second identical element, then the similar element is determined as the second newly added element; ⑤ The similar elements in the first page whose node sequence number is the same as the original sequence number of the second newly added element are determined as the second invalid elements in the first page.
[0054] For example, such as Figure 6 As shown, firstly, according to ① in the first preset rule, it can be determined that 6011 in the first page and 6012 in the second page are corresponding similar elements, 6021 in the first page and 6022 in the second page are corresponding similar elements, 6031 in the first page and 6032 in the second page are corresponding similar elements, 6041 in the first page and 6042 in the second page are corresponding similar elements, and 6051 in the first page and 6052 in the second page are corresponding similar elements. Then, the node number (2) of 6011 in the first page is determined as the original number of 6012 in the second page. Similarly, the original number of 6022 in the second page is (3), the original number of 6042 is (5), the original number of 6032 is (4), and the original number of 6052 is (6). Secondly, since 6012, 6022, 6042, 6032, and 6052 on the second page belong to the same level, the first similar element 6012 on the second page can be identified as the second identical element. Next, the original number (3) of 6022 on the second page is compared with the original number (2) of the previous second identical element 6012. Since (3) is greater than (2), 6022 on the second page is identified as the second identical element. Next, the original number (5) of 6042 on the second page is compared with the original number (3) of the previous second identical element 6022. Since (5) is greater than (3), 6042 on the second page is identified as the second identical element. Finally, the original number (4) of 6032 on the second page is compared with the original number (5) of the previous second identical element 6042. Since (4) is less than (5), 6032 on the second page is identified as the second newly added element. Similarly, 6052 on the second page can be identified as the second identical element. Finally, 6031, whose node number in the first page is the same as the original number (4) of the second newly added element 6032 in the second page, is identified as the second invalid element.
[0055] After identifying the first and second invalid elements on the first page, and the first and second newly added elements on the second page, the first and second invalid elements on the first page can be designated as invalid elements on the first page, and the first and second newly added elements on the second page can be designated as newly added elements on the second page. Correspondingly, the first identical elements and the second identical elements on the first and second pages can also be designated as identical elements on the first and second pages. In other words, the elements on the first page can be divided into identical elements and invalid elements, and the elements on the second page can be divided into identical elements and newly added elements.
[0056] S402, Match the failed element with the new element to determine the target element that matches the failed element and the new element.
[0057] In this context, a matching target element refers to an element with the same function. If a failed element on the first page and a newly added element on the second page have the same kinetic energy, then the failed element and the newly added element with the same function can be identified as matching target elements.
[0058] S403, based on the identification information of the target element on the first page, update the identification information of the target element on the second page.
[0059] In one embodiment, if the identification information of the target element in the first page is different from that in the second page, the identification information of the target element in the second page can be updated to the identification information of the target element in the first page.
[0060] S404, Obtain the correspondence between the identification information and feature information of elements in the second page.
[0061] The identification information of elements on the second page refers to the updated identification information of the elements. The feature information of elements on the second page includes the coordinate information of the elements on the second page. The correspondence between the identification information and feature information of elements on the second page can be presented in the form of a table.
[0062] S405, run the test script on the second page, and determine the coordinate information of the element on the second page according to the correspondence.
[0063] The test script for the second page is generated based on the updated identifier information of the elements on the second page. When the test script for the second page is run, the feature information corresponding to the identifier information of each element can be determined from the correspondence between the identifier information and feature information of the elements on the second page, and thus the coordinate information of each element can be determined.
[0064] S406: Test the element based on its coordinates on the second page and output the test results.
[0065] During the execution of the test script on the second page, elements can be located based on their corresponding coordinates. Then, based on these locations, the elements on the second page are tested, and the test results are obtained and output.
[0066] In this embodiment, when the first page is updated to the second page, the identification information of the elements on the second page can be updated by comparing the elements on the first page with the elements on the second page, thus reducing page maintenance costs. Furthermore, when running the test script for the second page, the feature information of the elements on the second page can be determined from the correspondence between the identification information and feature information of the elements on the second page. Then, the coordinate information included in the feature information can be used to locate the elements on the second page, facilitating testing. Compared to using the attribute information (such as XPath, CSS, class, etc.) of the elements on the second page for element location, this method improves the stability of page testing.
[0067] For further details, please see Figure 7 This is a schematic diagram of the structure of a page testing device provided in an embodiment of this application. The page testing device 700 may include:
[0068] The acquisition unit 701 is used to acquire the correspondence between the identification information and feature information of elements in the page; the feature information of the element includes the coordinate information of the element in the page;
[0069] The processing unit 702 is used to run the test script of the page, determine the coordinate information of the element in the page according to the correspondence; the test script is generated based on the element's identification information; the element is tested according to the coordinate information of the element in the page, and the test results are output.
[0070] In one implementation, the processing unit 702 is further configured to parse the page and construct a tree structure corresponding to the page; the nodes in the tree structure correspond to the elements in the page; the acquisition unit 701 is further configured to acquire the identification information and feature information of the nodes in the tree structure; the feature information of the nodes in the tree structure includes the coordinate information of the nodes in the page; the processing unit 702 is further configured to construct the correspondence between the identification information and feature information of the corresponding elements in the page based on the identification information and feature information of the nodes in the tree structure.
[0071] In one implementation, the feature information of nodes in the tree structure also includes the node label, node number, and node content; the feature information of elements also includes the node label, node number, and node content.
[0072] In one implementation, the page includes a first page and a second page; the second page is the updated version of the first page; the processing unit 702 is further configured to compare the elements in the first page with the elements in the second page to determine the invalid elements in the first page and the newly added elements in the second page; match the invalid elements with the newly added elements to determine the target element that matches the invalid elements and the newly added elements; and update the identification information of the target element in the second page according to the identification information of the target element in the first page.
[0073] In one implementation, the processing unit 702 is further configured to compare elements in the first page with elements in the second page according to a first preset rule, and determine corresponding similar elements and first identical elements in the first page and the second page, as well as first invalid elements in the first page other than similar elements and first identical elements, and first newly added elements in the second page other than similar elements and first identical elements; and determine second invalid elements in the first page and second newly added elements in the second page from the similar elements according to the second preset rule; wherein, the invalid elements in the first page include first invalid elements and second invalid elements, and the newly added elements in the second page include first newly added elements and second newly added elements.
[0074] In one implementation, the processing unit 702 is further configured to determine similar elements and first identical elements corresponding to the first page and the second page according to a first preset rule, including: determining elements in the first page and the second page that have the same coordinate information, node labels, and node content, but different node numbers as similar elements corresponding to the first page and the second page; and determining elements in the first page and the second page that have the same coordinate information, node labels, node numbers, and node content as first identical elements corresponding to the first page and the second page.
[0075] In one implementation, the processing unit 702 is further configured to determine, according to a second preset rule, a second invalid element in the first page and a second newly added element in the second page from similar elements, including: determining the node number of the similar element in the first page as the original number of the corresponding similar element in the second page; determining the second identical element in the first page and the second page according to the level to which the similar element belongs in the second page and the order of the similar elements in the level; comparing the original number of the second identical element in the second page with the original number of the similar element in the second page that belongs to the same level as the second identical element to determine the second newly added element in the second page; and determining the similar element in the first page whose node number is the same as the original number of the second newly added element as the second invalid element in the first page.
[0076] It is understood that the functions of each functional unit of the page testing device provided in this application embodiment can be specifically implemented according to the relevant methods in the above method embodiments, and the specific implementation process can be referred to the relevant descriptions in the above method embodiments, which will not be repeated here.
[0077] Please see Figure 8 , Figure 8 This is a schematic diagram of the structure of a computer device 800 provided in an embodiment of this application. The computer device may include a communication interface 801, a memory 802, and a processor 803. The communication interface 801, memory 802, and processor 803 are connected via one or more communication buses, which are used to enable communication between these components. The communication interface 801 may include a standard wired interface or a wireless interface (such as a WIFI interface). The memory 802 may include volatile memory, such as random-access memory (RAM); the memory 802 may also include non-volatile memory, such as flash memory, solid-state drive (SSD), etc.; the memory 802 may also include a combination of the above types of memory. The processor 803 may be a central processing unit (CPU). The processor 803 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), etc. The aforementioned PLD can be a field-programmable gate array (FPGA), a generic array logic (GAL), etc.
[0078] Optionally, the memory 802 is also used to store program instructions, which the processor 803 can also call to implement the page testing method in the embodiments of this application.
[0079] In one implementation, the processor 803 calls program instructions stored in the memory 802 to: obtain the correspondence between the identification information and feature information of elements in the page; the feature information of the elements includes the coordinate information of the elements in the page; run the test script of the page, and determine the coordinate information of the elements in the page according to the correspondence; the test script is generated based on the identification information of the elements; test the elements according to the coordinate information of the elements in the page, and output the test results.
[0080] In one implementation, the processor 803 may also call the program instructions to: parse the page and construct a tree structure corresponding to the page; map the nodes in the tree structure to the elements in the page; obtain the identification information and feature information of the nodes in the tree structure; the feature information of the nodes in the tree structure includes the coordinate information of the nodes in the page; and construct the correspondence between the identification information and feature information of the corresponding elements in the page based on the identification information and feature information of the nodes in the tree structure.
[0081] In one implementation, the feature information of nodes in the tree structure also includes the node label, node number, and node content; the feature information of elements also includes the node label, node number, and node content.
[0082] In one implementation, the page includes a first page and a second page; the second page is the updated version of the first page; the processor 803 can also call the program instructions to: compare the elements in the first page with the elements in the second page to determine the invalid elements in the first page and the newly added elements in the second page; match the invalid elements with the newly added elements to determine the target element that matches the invalid elements and the newly added elements; and update the identification information of the target element in the second page according to the identification information of the target element in the first page.
[0083] In one implementation, the processor 803 may also call the program instructions to: compare the elements in the first page with the elements in the second page according to a first preset rule, and determine the corresponding similar elements and first identical elements in the first page and the second page, as well as the first invalid elements in the first page other than the similar elements and the first identical elements, and the first newly added elements in the second page other than the similar elements and the first identical elements; determine the second invalid elements in the first page and the second newly added elements in the second page from the similar elements according to a second preset rule; wherein the invalid elements in the first page include the first invalid elements and the second invalid elements, and the newly added elements in the second page include the first newly added elements and the second newly added elements.
[0084] In one implementation, the processor 803 may also call the program instruction to: identify elements in the first page and the second page that have the same coordinate information, node labels, and node content, but different node numbers, as similar elements in the first page and the second page; and identify elements in the first page and the second page that have the same coordinate information, node labels, node numbers, and node content as the first identical elements in the first page and the second page.
[0085] In one implementation, the processor 803 may further invoke the program instructions to: determine the second invalid element in the first page and the second newly added element in the second page from similar elements according to the second preset rule, including: determining the node number of the similar element in the first page as the original number of the corresponding similar element in the second page; determining the second identical element in the first page and the second page according to the level to which the similar element belongs in the second page and the order of the similar elements in the level; comparing the original number of the second identical element in the second page with the original number of the similar element in the second page that belongs to the same level as the second identical element to determine the second newly added element in the second page; and determining the similar element in the first page whose node number is the same as the original number of the second newly added element as the second invalid element in the first page.
[0086] It should be understood that the principles and beneficial effects of the computer device 800 in solving the problem described in the embodiments of this application are the same as those in this application. Figures 2-6 The embodiments shown and the foregoing content have similar principles and beneficial effects in solving the problem, and will not be repeated here for the sake of brevity.
[0087] Accordingly, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the method described in the embodiments of this application.
[0088] Accordingly, this application also provides a computer program product, which includes a computer program or computer instructions, which, when executed by a processor, implement the methods in this application.
[0089] Accordingly, this application provides a computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in this application.
[0090] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0091] The steps in the method of this application embodiment can be adjusted, combined, or deleted according to actual needs.
[0092] The modules in the device of this application embodiment can be merged, divided, and deleted according to actual needs.
[0093] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by program instructions and related hardware. The program instructions can be stored in a computer-readable storage medium, which may include: flash drive, ROM, RAM, disk or optical disk, etc.
[0094] The above-disclosed embodiments are merely one example of this application and only a part of the embodiments of this application. They should not be construed as limiting the scope of this application.
Claims
1. A page testing method, characterized in that, The method includes: Obtain the correspondence between the identification information and feature information of elements on the page; the feature information of the element includes the coordinate information of the element on the page; Run the test script for the page, and determine the coordinate information of the element in the page according to the correspondence; the test script is generated based on the identification information of the element; Based on the coordinate information of the element in the page, the element is tested, and the test results are output. The step of obtaining the correspondence between the identification information and feature information of elements on the page includes: The page is parsed to construct a tree structure corresponding to the page; the nodes in the tree structure correspond to the elements in the page. Obtain the identification information and feature information of the nodes in the tree structure; the feature information of the nodes in the tree structure includes the coordinate information of the nodes on the page; Based on the identification and feature information of the nodes in the tree structure, construct the correspondence between the identification and feature information of the corresponding elements in the page; The feature information of nodes in the tree structure also includes the node label, node number, and node content; the feature information of elements also includes the node label, node number, and node content. The page includes a first page and a second page; the second page is an updated version of the first page; the method further includes: Compare the elements on the first page with the elements on the second page to determine the invalid elements on the first page and the newly added elements on the second page; The failed element is matched with the newly added element to determine the target element that matches the failed element among the newly added elements; Update the identification information of the target element on the second page based on the identification information of the target element on the first page.
2. The method as described in claim 1, characterized in that, The step of comparing the elements in the first page with the elements in the second page to determine the invalid elements in the first page and the newly added elements in the second page includes: According to the first preset rule, the elements in the first page are compared with the elements in the second page to determine the corresponding similar elements and the first identical elements in the first page and the second page, as well as the first invalid elements in the first page other than the similar elements and the first identical elements, and the first newly added elements in the second page other than the similar elements and the first identical elements. According to the second preset rule, a second invalid element in the first page and a second newly added element in the second page are determined from the similar elements; wherein, the invalid element in the first page includes the first invalid element and the second invalid element, and the newly added element in the second page includes the first newly added element and the second newly added element.
3. The method as described in claim 2, characterized in that, The step of determining similar elements and first identical elements in the first page and the second page according to the first preset rule includes: Elements in the first page and the second page that have the same coordinate information, node labels, and node content, but different node numbers, are identified as similar elements in the first page and the second page respectively. Elements that share the same coordinate information, node label, node number, and node content in both the first page and the second page are identified as the first identical elements in the first page and the second page.
4. The method as described in claim 3, characterized in that, The step of determining the second invalid element in the first page and the second newly added element in the second page from the similar elements according to the second preset rule includes: The node number of the similar element in the first page is determined as the original number of the corresponding similar element in the second page; Based on the level to which the similar element belongs in the second page and the order in which the similar element is arranged in the level, determine the second identical element corresponding to the first page and the second page; The original sequence number of the second identical element in the second page is compared with the original sequence number of similar elements in the second page that belong to the same level as the second identical element to determine the second newly added element in the second page; similar elements in the first page whose node sequence number is the same as the original sequence number of the second newly added element are determined as the second invalid elements in the first page.
5. A computer device, characterized in that, The device includes a memory, a processor, and a network interface. The processor is connected to the memory and the network interface. The network interface is used to provide network communication functions. The memory is used to store program code. The processor is used to call the program code to execute the method according to any one of claims 1-4.
6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-4.
Citation Information
Patent Citations
User interface test method and device, storage medium and computer equipment
CN111552627A