Application program testing method and device, electronic equipment and storage medium
By selecting target pages from the application's pages, obtaining the document object model tree, and generating automated test cases, the problem of extended testing cycles is solved, and testing efficiency and the probability of problem discovery are improved.
Patent Information
- Application Number
- CN202211440172.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-17
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2042-11-17
AI Technical Summary
In existing technologies, application testing tasks are extended depending on the project size and functional complexity, resulting in longer testing cycles, low efficiency in identifying problems, and impact on development progress.
By selecting the target page from multiple pages of the application, obtaining the document object model tree, determining the node weight value based on the number of times page elements are clicked, generating automated test cases, and conducting tests.
It improves the efficiency of application testing, enabling quick problem detection and shortening the development and update process.
Smart Images

Figure CN115904969B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of testing technology, and in particular to an application testing method and apparatus, electronic device and storage medium. Background Technology
[0002] An application (APP) is a computer program designed to perform one or more specific tasks. It interacts with the user and has a visual user interface. With the development of intelligence and digitalization, more and more applications are appearing in people's lives. During the development and updating of applications, in order to check their functional stability, it is often necessary to use pre-written automated test cases to test the applications.
[0003] In related technologies, the testing tasks for applications often depend on the size of the project and the complexity of its functions. After several product iterations, some applications become more complex, significantly extending the testing cycle and reducing the efficiency of actually discovering problems, which can easily affect the application's development schedule. Summary of the Invention
[0004] The main objective of this application is to provide an application testing method, apparatus, electronic device, and storage medium, which aims to improve the efficiency of application testing.
[0005] To achieve the above objectives, a first aspect of this application provides an application testing method, the method comprising:
[0006] Select several target pages from multiple pages of the application;
[0007] Obtain the document object model tree of each of the target pages; wherein, the nodes in the document object model tree are page elements in the target pages;
[0008] The weight value of the node in the document object model tree is determined based on the number of times each page element is clicked.
[0009] Starting from the root node of the document object model tree, the document object model tree is traversed according to the weight values corresponding to each node, and automated test cases are generated based on the traversal path.
[0010] The application is tested according to the automated use cases, and the test results are obtained.
[0011] In some embodiments, selecting a plurality of target pages from a plurality of pages of the application includes:
[0012] Test coverage of page elements in each of the aforementioned pages;
[0013] Based on the test coverage, select several target pages from the page list.
[0014] In some embodiments, selecting a plurality of target pages from the page based on the test coverage includes:
[0015] The test coverage is sorted from largest to smallest, and the pages at the bottom of the sort are selected as target pages.
[0016] Alternatively, the test coverage can be sorted in ascending order, and the top few pages in the sort can be selected as target pages.
[0017] In some embodiments, determining the weight value corresponding to a node in the document object model tree based on the number of clicks on each of the page elements includes:
[0018] Calculate the total number of clicks for all page elements in the target page based on the number of clicks for each page element.
[0019] Calculate the ratio of the number of clicks to the total number of clicks, and use the ratio as the weight value of the node in the document object model tree.
[0020] In some embodiments, traversing the document object model tree according to the weight values corresponding to each node includes:
[0021] If the currently traversed node has untraversed child nodes, then select the node with the largest weight value from the untraversed child nodes and traverse it.
[0022] Alternatively, if the currently traversed node does not have any untraversed child nodes, then select the node with the largest weight value from the untraversed sibling nodes for traversal.
[0023] In some embodiments, generating automated use cases based on traversal paths includes:
[0024] Analyze each node on the traversal path and record the traversal order of each node;
[0025] Based on the traversal order, test cases are generated sequentially for each of the nodes;
[0026] By integrating the various test cases, automated test cases are obtained.
[0027] In some embodiments, testing the application based on the automated use cases to obtain test results includes:
[0028] Run the application according to the automated use case and obtain the running results;
[0029] If the running result is consistent with the expected result, then the application test is deemed to have passed;
[0030] Alternatively, if the running result is inconsistent with the expected result, the application test is determined to have failed.
[0031] To achieve the above objectives, a second aspect of this application provides an application testing apparatus, the apparatus comprising:
[0032] A selection module is used to select several target pages from multiple pages of the application;
[0033] The acquisition module is used to acquire the document object model tree of each of the target pages; wherein, the nodes in the document object model tree are page elements in the target pages;
[0034] The processing module is used to determine the weight value of the node in the document object model tree based on the number of times each page element is clicked.
[0035] The traversal module is used to traverse the document object model tree starting from the root node, according to the weight value of each node, and generate automated test cases based on the traversal path.
[0036] The execution module is used to test the application based on the automated test cases and obtain test results.
[0037] To achieve the above objectives, a third aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.
[0038] To achieve the above objectives, a fourth aspect of the present application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method described in the first aspect.
[0039] The application testing method, apparatus, electronic device, and storage medium proposed in this application select several target pages from multiple pages of the application; obtain a document object model tree (DOM) for each target page; wherein the nodes in the DOM tree are page elements of the target page; determine the weight value corresponding to the node in the DOM tree based on the number of clicks of each page element; traverse the DOM tree starting from the root node according to the magnitude of the weight value corresponding to each node, and generate automated test cases based on the traversal path; test the application based on the automated test cases to obtain test results. This application can generate automated test cases based on page elements with higher click counts, which can increase the probability of discovering problems, facilitate the rapid functional verification of the application, and improve the efficiency of application testing. Attached Figure Description
[0040] Figure 1 This is a flowchart of the application testing method provided in the embodiments of this application;
[0041] Figure 2 This is a schematic diagram of the structure of a document object model tree provided in an embodiment of this application;
[0042] Figure 3 This is one of the embodiments provided in this application. Figure 1 The flowchart of step S105 in the process;
[0043] Figure 4 This is one of the embodiments provided in this application. Figure 1 The flowchart of step S101 in the text;
[0044] Figure 5 This is one of the embodiments provided in this application. Figure 1 The flowchart of step S103 in the process;
[0045] Figure 6 This is one of the embodiments provided in this application. Figure 1 The flowchart of step S104 in the process;
[0046] Figure 7 This is another embodiment provided in this application. Figure 1 The flowchart of step S104 in the process;
[0047] Figure 8 This is a schematic diagram of the structure of the application testing device provided in the embodiments of this application;
[0048] Figure 9 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0050] It should be noted that although functional modules are divided in the device schematic diagram and a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than the module division in the device or the order in the flowchart. The terms "first," "second," etc., in the specification, claims, and the aforementioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0051] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0052] First, let's analyze some of the terms used in this application:
[0053] An application (APP) is a computer program designed to perform one or more specific tasks. It runs in user mode, interacts with the user, and has a visual user interface. Applications are typically divided into two parts: a graphical user interface (GUI) and an engine. The GUI displays graphics and characters and provides an event-driven user interface that controls the user's operation. The engine is the core component for developing programs or systems on an electronic platform. Using the engine, developers can quickly establish and implement the necessary functions of the program, or utilize it to assist the program's operation. Generally, an engine is a supporting component of a program or system. Common program engines include game engines, search engines, and antivirus engines.
[0054] The Document Object Model (DOM) is a standard programming interface recommended by the W3C for processing Extensible Markup Language (EXPLAIN). It is a platform- and language-independent application programming interface (API) that allows dynamic access to programs and scripts to update their content, structure, and document style (HTML and XML documents are defined through the specification section). Documents can be further processed, and the results can be added to the current page. The DOM is a tree-based API that requires the entire document to be represented in memory during processing.
[0055] W3C: It is an abbreviation for World Wide Web Consortium. It is a non-profit organization that sets web standards, such as HTML, XHTML, CSS, and XML.
[0056] During application development and updates, automated test cases are frequently used to test the application's functionality and stability. Specifically, this process typically involves automatically generating test cases based on the required functionality, having testers run the test cases, and comparing the actual results with the expected results. If they match, the test is considered passed, and the application's functionality meets expectations. Conversely, if they do not match, the test has failed, and the application's functionality does not meet expectations.
[0057] In related technologies, the testing tasks for applications often depend on the size of the project and the complexity of its functions. After several product iterations, some applications become more complex, significantly extending the testing cycle and reducing the efficiency of actually discovering problems, which can easily affect the application's development schedule.
[0058] Based on this, embodiments of this application provide an application testing method and apparatus, an electronic device, and a storage medium, aiming to improve the efficiency of application testing.
[0059] The methods provided in this application embodiment can be executed in applications involving shopping, gaming, and social networking. For example, in shopping applications, there may be a need for consumers to complain about product quality issues or delivery problems. In this scenario, the methods provided in this application embodiment can be used to quickly test and verify the application, identify problematic business nodes, and efficiently resolve problems encountered by consumers during the shopping process. As another example, in gaming applications, there may be game-related issues such as bugs. In this scenario, the methods provided in this application embodiment can be used to detect game processes, identify and fix related bugs, thereby improving the player's gaming experience.
[0060] The application testing method, apparatus, electronic device, and storage medium provided in this application are specifically described through the following embodiments. First, the testing method in the embodiments of this application is described.
[0061] The application testing method provided in this application relates to the field of testing technology. The application testing method provided in this application can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, etc.; the server can be configured as 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, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms; the software can be an application implementing the application testing method, but is not limited to the above forms.
[0062] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0063] It should be noted that in all specific embodiments of this application, when processing data related to user identity or characteristics, such as user information, user behavior data, user historical data, and user location information, user permission or consent is obtained first. Furthermore, the collection, use, and processing of this data comply with relevant laws, regulations, and standards of the relevant countries and regions. In addition, when embodiments of this application require access to sensitive personal information of users, separate permission or consent from the user is obtained through pop-ups or redirects to confirmation pages. Only after obtaining the user's separate permission or consent is the necessary user-related data for the proper functioning of the embodiments of this application obtained.
[0064] Figure 1 This is an optional flowchart of the application testing method provided in the embodiments of this application. Figure 1 The method may include, but is not limited to, steps S101 to S105.
[0065] Step S101: Select several target pages from multiple pages of the application;
[0066] In this step, generally speaking, during the operation of an application, there will be multiple pages depending on the functions implemented and the business processes. These pages often include multiple page elements. Specifically, for example, in some embodiments, page elements in an application page may include virtual buttons, search boxes, category keys, message centers, etc. Users can interact with the application to perform corresponding operations on various page elements. The application responds to the user's interaction operations and can fulfill corresponding functional requirements, such as jumping to the corresponding page or performing corresponding calculations to obtain the required results, etc. This application does not impose specific limitations on this process.
[0067] In this step, when testing the application, some pages can be selected from multiple pages of the application, and these selected pages are recorded as the target pages. It is understood that the number of these "some" pages is not specifically limited. In some embodiments, it can be all pages of the application; in other embodiments, it can be a subset of the application's pages.
[0068] Step S102: Obtain the document object model tree of each target page; wherein, the nodes in the document object model tree are page elements in the target page;
[0069] In this step, each page of the application has its own corresponding Document Object Model (DOM) tree. For example, if the application exists as a webpage, the browser creates the DOM tree for that page when it is loaded. (See also...) Figure 2 , Figure 2 This diagram illustrates a Document Object Model (DOM) tree, which typically includes multiple levels of nodes with interconnected relationships. For a page, the corresponding nodes in the DOM tree are the page elements. The top node in the DOM tree is the root node, which is generally the application's entry point. The connections between nodes indicate business relationships between them. This is achieved through DOM creation... Figure 2 The tree diagram shown grants application developers control over the page's content and structure. Using the APIs provided by the DOM, developers can easily delete, add, replace, or modify any page element (node). This improves application development and debugging efficiency.
[0070] In this step, the Document Object Model (DOM) tree corresponding to each target page is obtained. Automated test cases can then be generated based on the DOM tree. Specifically, the method for obtaining the DOM tree is not limited in this embodiment. In some embodiments, it may be obtained locally on the terminal where the application is installed; in other embodiments, it may be obtained from the application's backend server.
[0071] Step S103: Determine the weight value of the node in the document object model tree based on the number of times each page element is clicked;
[0072] After obtaining the document object model tree of the target page, it is easy to understand the various page elements included in each target page. Furthermore, this step also obtains the number of clicks on each page element. Here, the number of clicks refers to the total number of times users have clicked on page elements since the application went live. Specifically, the number of clicks can be recorded within a preset time period, which can be a day, a week, or any other time interval of any length; this application does not impose any specific restrictions on this.
[0073] After obtaining the click count of each page element, we can determine whether each element is frequently accessed and used by users. Therefore, we can determine the weight value of the node in the Document Object Model (DOM) tree based on the click count. It's understandable that since the nodes in the DOM tree are page elements, if a page element is clicked frequently, it indicates that it is frequently accessed and used, possibly for implementing important functions. Therefore, page elements with more clicks can be assigned higher weight values, and vice versa.
[0074] It should be noted that the above embodiments are only used to illustrate the principle of determining the weight value, and this application does not limit the specific value.
[0075] Step S104: Starting from the root node of the document object model tree, traverse the document object model tree according to the weight value corresponding to each node, and generate automated test cases based on the traversal path.
[0076] In this step, after determining the weight value of each node, the document object model tree can be traversed starting from the root node according to the weight value of each node. During the traversal, a traversal path is obtained according to the order in which each node is traversed. In this embodiment, automated test cases can be generated based on this traversal path.
[0077] In some specific embodiments, automated use cases can be generated based on a pre-defined random event stream. This pre-defined random event stream may include click events, swipe events, key input events, touch input events, and application close events, etc. This application does not impose any limitations on this.
[0078] Step S105: Test the application according to the automated use case and obtain the test results.
[0079] In this step, after obtaining automated test cases, the application can be tested based on these cases to obtain the corresponding test results. Generally, the test results for the application can include two types: pass and fail. When the test result is pass, it indicates that the application is basically functioning normally and can be put into use; conversely, when the test result is fail, it indicates that there are problems with the application's operation and further improvements are needed.
[0080] It is understood that in this embodiment, the traversal path is generated by traversing the nodes in the document object model tree. During the traversal, the number of clicks on the page elements corresponding to each node is used as the traversal basis, which allows page elements with more clicks to be prioritized in the traversal path. Therefore, the generated automated test cases can reach the page elements corresponding to more important and frequently used functions more quickly, which is conducive to quickly discovering business problems and execution failures in the application, improving the testing efficiency of the application, facilitating the staff to quickly change the problems, and shortening the development and update process of the application.
[0081] Of course, it should be noted that application testing is generally not a matter of testing a single function or a subset of functions and then ending the test. In some embodiments, test coverage can be used as an indicator to determine when to stop testing. When the test coverage of page elements is high, the application test can be terminated. Specifically, in this embodiment, the test coverage of each page can be judged. If the test coverage of each page is higher than a preset threshold, the current application test is considered to meet the preset requirements, and the application test task is terminated. For example, in some embodiments, the preset threshold for the test coverage of a page can be set to 95%. Then, several target pages are selected from multiple pages to begin the application test task. At the same time, the current test coverage of each page is detected. When the current test coverage of each page is higher than the preset 95%, and no test failures occur, the current application test task can be considered to have met the preset requirements, and the application test task is terminated. If there is a page with a current test coverage rate lower than the preset 95% test coverage rate, the current application test task is considered incomplete, and the corresponding tests can continue. This process continues until the current test coverage rate of each page is higher than the preset threshold of 95%, thus completing the application test and ending the application stability test task.
[0082] Specifically, please refer to Figure 3 In some embodiments, step S105 may include, but is not limited to, steps S1051 to S1053:
[0083] S1051, Run the application according to the automation use case and obtain the running results;
[0084] S1052, If the running result is consistent with the predetermined result, then the application test is determined to be successful;
[0085] S1053, or, if the running result is inconsistent with the predetermined result, then the application test is determined to have failed.
[0086] In this embodiment, as described above, the automated test cases may include multiple random event streams. When executing the automated test cases, the application can be run according to the automated test cases. At this time, the automated test cases will send pre-set random event streams to the application to simulate user operations on the application under test. Specifically, during the testing process, random event streams can be randomly selected from the pre-set random event streams and sent to the application for execution, to randomly check the responsiveness and stability of page elements in the application. The application responds to the automated test cases by executing business processes and obtains corresponding running results. In this embodiment, the running results during the actual testing process can be compared with the theoretically predetermined results to see if they are consistent, such as whether the business feedback corresponding to certain page elements is normal. If the running results are consistent with the predetermined results, the application test is considered passed. Conversely, if the running results are inconsistent with the predetermined results, the application test is considered failed.
[0087] For example, if the random event stream indicates a touchscreen back button click, the touchscreen back button is identified as the currently tested page element. The touchscreen back button click event stream is then sent to the application, and a response is awaited. The test result is then determined based on the application's response. For instance, if the application executes a back operation according to the simulated touchscreen back button click event stream, the test for that page element is considered normal. Conversely, if the application crashes or freezes, the test for that page element is considered problematic, the application is unstable, and repair is required.
[0088] Please see Figure 4 In some embodiments, step S101 may include, but is not limited to, steps S1011 to S102:
[0089] Step S1011: Detect the test coverage of page elements in each of the pages;
[0090] Step S1012: Select several target pages from the pages according to the test coverage.
[0091] In this application embodiment, when selecting a target page, in some embodiments, the selection can be based on the test coverage of the page elements within the target page. Specifically, for example, in some embodiments, the test coverage of page elements in each page can be detected first. Here, test coverage refers to the proportion of page elements that have completed testing out of the total number of page elements. It is understood that the lower the test coverage of a page, the more content it still needs to test, and the higher the probability of potential problems. Therefore, in this application embodiment, when selecting a target page, a page with a lower test coverage can be selected as the target page.
[0092] Specifically, in some possible implementation schemes, selecting several target pages from the pages based on the test coverage includes:
[0093] The test coverage is sorted from largest to smallest, and the pages at the bottom of the sort are selected as target pages.
[0094] Alternatively, the test coverage can be sorted in ascending order, and the top few pages in the sort can be selected as target pages.
[0095] In this application embodiment, when selecting pages with low test coverage as target pages, in some embodiments, the test coverage can be sorted to select several corresponding pages as target pages. Specifically, for example, the test coverage corresponding to each obtained page can be sorted from largest to smallest. Then, the pages at the bottom of the sorted list are selected as target pages. Alternatively, the test coverage corresponding to each current page can be sorted from smallest to largest, and the pages at the top of the sorted list are selected as target pages. Of course, the specific number of these "several" can be flexibly chosen as needed, and this application does not impose any restrictions on this. In this way, by sorting the test coverage of each current page and then selecting some pages with low test coverage from the sorted sequence as target pages, rapid testing of pages that may have many problems can be achieved, improving testing efficiency.
[0096] Reference Figure 5 In step S103 of some embodiments, determining the weight value corresponding to the node in the document object model tree based on the number of clicks on each of the page elements includes:
[0097] Step S1031: Calculate the total number of clicks on all page elements in the target page based on the number of clicks on each page element;
[0098] Step S1032: Calculate the ratio of the number of clicks to the total number of clicks, and use the ratio as the weight value corresponding to the node in the document object model tree.
[0099] In this embodiment, when calculating the weight value of each node, the total number of clicks on all page elements in the target page can be calculated first based on the number of clicks on each page element. Then, the ratio of each click count to the total number of clicks can be calculated, and this ratio can be used as the weight value of the node. For example, assuming a page contains 5 page elements, the total number of clicks on these page elements is 100, and one of the page elements is clicked 15 times, then the weight value of the node corresponding to that page element can be determined as 0.15. Of course, the above example is only used to illustrate the implementation method in this embodiment and does not mean that the specific number of page elements and the click situation are limited.
[0100] Reference Figure 6 In step S104 of some embodiments, traversing the document object model tree according to the weight values corresponding to each node includes:
[0101] Step S1041: If the currently traversed node has untraversed child nodes, then select the node with the largest weight value from the untraversed child nodes for traversal.
[0102] Alternatively, in step S1042, if the currently traversed node does not have any untraversed child nodes, then select the node with the largest weight value from the untraversed sibling nodes for traversal.
[0103] In this embodiment, when traversing the document object model tree, for each node, the node at the upper level and connected to it is its parent node, the node at the same level is its sibling node, and the node at the lower level and connected to it is its child node. During the traversal, for the currently traversed node, it can first be determined whether it has any untraversed child nodes. If child nodes exist, the traversal can continue downwards, that is, the node with the largest weight value among its child nodes can be selected as the currently traversed node to continue the traversal. If it has no untraversed child nodes, the node with the largest weight value among its untraversed sibling nodes can be selected as the currently traversed node to continue the traversal. Of course, if the node also has no untraversed sibling nodes, it can backtrack upwards until a node with child nodes or sibling nodes is found.
[0104] Reference Figure 7 In step S104 of some embodiments, generating automated use cases based on the traversal path includes:
[0105] Step S1043: parse each node on the traversal path and record the traversal order of each node;
[0106] Step S1044: Generate test cases for each node sequentially according to the traversal order;
[0107] Step S1045: Integrate the various test cases to obtain automated test cases.
[0108] In this embodiment of the application, when generating automated test cases based on the traversal path, firstly, each node on the traversal path can be parsed, and the traversal order of each node can be obtained according to the path. It can be understood that in this embodiment of the application, the traversal order can, to a certain extent, reflect the importance of the page elements corresponding to each node. That is, the page elements traversed first have a higher probability of being clicked when put into operation. Therefore, in order to quickly discover problems that have a significant impact on functionality, these page elements can be tested first, thereby improving the efficiency of testing.
[0109] In this embodiment, after obtaining the traversal order, test cases for each node can be generated sequentially according to the traversal order. These test cases can then be integrated to obtain automated test cases. It should be noted that when integrating the test cases, they need to be arranged in the order they were generated so that more important test cases can be executed first. This allows for faster execution of page elements corresponding to more important and frequently used functions, facilitating the rapid discovery of business problems and execution failures in the application. This improves application testing efficiency, allows staff to quickly modify issues, and shortens the application development and update process.
[0110] Please see Figure 8 This application also provides an application testing apparatus that can implement the above-described application testing method. The apparatus includes:
[0111] A selection module is used to select several target pages from multiple pages of the application;
[0112] The acquisition module is used to acquire the document object model tree of each of the target pages; wherein, the nodes in the document object model tree are page elements in the target pages;
[0113] The processing module is used to determine the weight value of the node in the document object model tree based on the number of times each page element is clicked.
[0114] The traversal module is used to traverse the document object model tree starting from the root node, according to the weight value of each node, and generate automated test cases based on the traversal path.
[0115] The execution module is used to test the application based on the automated test cases and obtain test results.
[0116] In some embodiments, the selection module is specifically used for:
[0117] Test coverage of page elements in each of the aforementioned pages;
[0118] Based on the test coverage, select several target pages from the page list.
[0119] In some embodiments, the selection module is specifically used for:
[0120] The test coverage is sorted from largest to smallest, and the pages at the bottom of the sort are selected as target pages.
[0121] Alternatively, the test coverage can be sorted in ascending order, and the top few pages in the sort can be selected as target pages.
[0122] In some embodiments, the processing module is specifically used for:
[0123] Calculate the total number of clicks for all page elements in the target page based on the number of clicks for each page element.
[0124] Calculate the ratio of the number of clicks to the total number of clicks, and use the ratio as the weight value of the node in the document object model tree.
[0125] In some embodiments, the traversal module is specifically used for:
[0126] If the currently traversed node has untraversed child nodes, then select the node with the largest weight value from the untraversed child nodes and traverse it.
[0127] Alternatively, if the currently traversed node does not have any untraversed child nodes, then select the node with the largest weight value from the untraversed sibling nodes for traversal.
[0128] In some embodiments, the traversal module is specifically used for:
[0129] Analyze each node on the traversal path and record the traversal order of each node;
[0130] Based on the traversal order, test cases are generated sequentially for each of the nodes;
[0131] By integrating the various test cases, automated test cases are obtained.
[0132] In some embodiments, the execution module is specifically used for:
[0133] Run the application according to the automated use case and obtain the running results;
[0134] If the running result is consistent with the expected result, then the application test is deemed to have passed;
[0135] Alternatively, if the running result is inconsistent with the expected result, the application test is determined to have failed.
[0136] It is understandable that, such as Figure 1 The content of the application testing method embodiments shown is applicable to the application testing device embodiments. The specific functions implemented by the application testing device embodiments are the same as those shown in the examples. Figure 1 The application testing method shown in the embodiment is the same, and the beneficial effects achieved are the same as those described above. Figure 1 The beneficial effects achieved by the application testing method embodiments shown are also the same.
[0137] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described application testing method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0138] Please see Figure 9 , Figure 9 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes:
[0139] The processor 901 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to achieve the technical solutions provided in the embodiments of this application.
[0140] The memory 902 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 902 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 902 and is called and executed by the processor 901 using the application testing method of the embodiments of this application.
[0141] The 903 input / output interface is used to implement information input and output.
[0142] The communication interface 904 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.).
[0143] Bus 905 transmits information between various components of the device (e.g., processor 901, memory 902, input / output interface 903, and communication interface 904);
[0144] The processor 901, memory 902, input / output interface 903, and communication interface 904 are connected to each other within the device via bus 905.
[0145] It is understandable that, such as Figure 1 The content of the application testing method embodiments shown is applicable to the embodiments of this electronic device, and the specific functions implemented by the embodiments of this electronic device are the same as those shown. Figure 1 The application testing method shown in the embodiment is the same, and the beneficial effects achieved are the same as those described above. Figure 1 The beneficial effects achieved by the application testing method embodiments shown are also the same.
[0146] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described application testing method.
[0147] Similarly, it is understandable that, as Figure 1 The content of the application testing method embodiments shown is applicable to the embodiments of this computer-readable storage medium, and the specific functions implemented by the embodiments of this computer-readable storage medium are the same as those shown below. Figure 1 The application testing method shown in the embodiment is the same, and the beneficial effects achieved are the same as those described above. Figure 1 The beneficial effects achieved by the application testing method embodiments shown are also the same.
[0148] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0149] The application testing method, application testing device, electronic device, and storage medium provided in this application embodiment select several target pages from multiple pages of the application; obtain the document object model tree (DOM) of each target page; wherein the nodes in the DOM tree are page elements of the target page; determine the weight value corresponding to the node in the DOM tree based on the number of clicks of each page element; traverse the DOM tree starting from the root node according to the size of the weight value corresponding to each node, and generate automated test cases based on the traversal path; test the application based on the automated test cases to obtain test results. This application can generate automated test cases based on page elements with higher click counts, which can increase the probability of discovering problems, facilitate the rapid functional verification of the application, and improve the efficiency of application testing.
[0150] The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided by the embodiments of this application. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0151] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0152] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this application are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is changed and sub-operations described as part of a larger operation are executed independently.
[0153] Furthermore, although this application is described in the context of functional modules, it should be understood that, unless otherwise stated to the contrary, one or more of the functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding this application. Rather, given the properties, functions, and internal relationships of the various functional modules in the apparatus disclosed herein, the actual implementation of the module will be understood within the scope of conventional technology for an engineer. Therefore, those skilled in the art can implement the application set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of this application, which is determined by the full scope of the appended claims and their equivalents.
[0154] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0155] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable storage medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable storage medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0156] More specific examples (a non-exhaustive list) of computer-readable storage media include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable storage media can even be paper or other suitable media on which programs can be printed, because programs can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0157] It should be understood that various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0158] In the foregoing description of this specification, the references to terms such as "one embodiment," "another embodiment," or "some embodiments," etc., indicate that a specific feature, structure, material, or characteristic described in connection with an embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0159] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.
[0160] The above is a detailed description of the preferred embodiments of this application, but this application is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of this application, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. An application testing method, characterized in that, The method includes: Select several target pages from multiple pages of the application; Obtain the document object model tree of each of the target pages; wherein, the nodes in the document object model tree are page elements in the target pages; The weight value of each node in the document object model tree is determined based on the number of times each page element is clicked; wherein, the number of clicks is the total number of times the user clicks the page element after the application is put into operation; Starting from the root node of the document object model tree, the document object model tree is traversed according to the weight value of each node, and each node on the traversal path is parsed and the traversal order of each node is recorded; according to the traversal order, test cases for each node are generated in sequence; and the test cases are integrated to obtain automated test cases. The application is tested sequentially using the test cases in the automated test cases to obtain test results. The step of determining the weight value corresponding to the node in the document object model tree based on the number of clicks of each of the page elements includes: Calculate the total number of clicks for all page elements in the target page based on the number of clicks for each page element. Calculate the ratio of the number of clicks to the total number of clicks, and use the ratio as the weight value corresponding to the node in the document object model tree; The step of traversing the document object model tree according to the weight values corresponding to each node includes: If the currently traversed node has untraversed child nodes, then select the node with the largest weight value from the untraversed child nodes and traverse it. If the currently traversed node does not have any untraversed child nodes, then select the node with the largest weight value from the untraversed sibling nodes and traverse it. If the currently visited node has no unvisited child nodes or sibling nodes, return to the parent node of the currently visited node for traversal.
2. The method according to claim 1, characterized in that, The step of selecting several target pages from multiple pages of the application includes: Test coverage of page elements in each of the aforementioned pages; Based on the test coverage, select several target pages from the page list.
3. The method according to claim 2, characterized in that, The step of selecting several target pages from the page based on the test coverage includes: The test coverage is sorted from largest to smallest, and the pages at the bottom of the sort are selected as target pages. Alternatively, the test coverage can be sorted in ascending order, and the top few pages in the sort can be selected as target pages.
4. The method according to any one of claims 1 to 3, characterized in that, The step of testing the application based on the automated use cases and obtaining test results includes: Run the application according to the automation use case and obtain the running results; If the running result is consistent with the expected result, then the application test is deemed to have passed; Alternatively, if the running result is inconsistent with the expected result, the application test is determined to have failed.
5. An application testing device, characterized in that, The device includes: A selection module is used to select several target pages from multiple pages of the application; The acquisition module is used to acquire the document object model tree of each of the target pages; wherein, the nodes in the document object model tree are page elements in the target pages; The processing module is used to determine the weight value of the node in the document object model tree based on the number of times each page element is clicked; wherein, the number of clicks is the total number of times the user clicks the page element after the application is put into operation; The traversal module is used to traverse the document object model tree starting from the root node, according to the weight value of each node, and parse each node on the traversal path, record the traversal order of each node; generate test cases for each node in sequence according to the traversal order; and integrate the test cases to obtain automated test cases. The execution module is used to test the application sequentially using the test cases according to the order of each test case in the automated test case, and obtain test results; The processing module is specifically used for: Calculate the total number of clicks for all page elements in the target page based on the number of clicks for each page element. Calculate the ratio of the number of clicks to the total number of clicks, and use the ratio as the weight value corresponding to the node in the document object model tree; The traversal module is specifically used for: If the currently traversed node has untraversed child nodes, then select the node with the largest weight value from the untraversed child nodes and traverse it. If the currently traversed node does not have any untraversed child nodes, then select the node with the largest weight value from the untraversed sibling nodes and traverse it. If the currently visited node has no unvisited child nodes or sibling nodes, return to the parent node of the currently visited node for traversal.
6. An electronic device, characterized in that, The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the application testing method according to any one of claims 1 to 4.
7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the application testing method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Application test method and device and storage medium
CN112527689A
