A UI automation test framework optimization method and system

By optimizing the UI automation testing framework and adopting script recording, encapsulated search, click and page snapshot methods, combined with continuous integration tools, the problems of difficulty in locating error pages and code duplication in existing technologies have been solved, achieving efficient and accurate automated testing.

CN114077537BActive Publication Date: 2024-08-30FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202010819220.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-14
Publication Date
2024-08-30
Estimated Expiration
2040-08-14

AI Technical Summary

Technical Problem

Existing UI automation testing frameworks have limitations in page operation testing. They cannot accurately locate error pages, their syntax is not concise enough, resulting in a high failure rate of test case execution, and code duplication wastes time and is inefficient.

Method used

By optimizing the UI automation testing framework, using script recording to obtain UI page elements, setting framework timeouts, encapsulating search, click, and page snapshot methods, combining exception handling, and utilizing the continuous integration tool Jenkins for continuous integration, detailed test reports are generated.

Benefits of technology

It improved the success rate of test case execution, simplified test case writing, reduced repetitive code, ensured the accuracy and efficiency of testing, realized full-process automated testing, and improved test quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114077537B
    Figure CN114077537B
Patent Text Reader

Abstract

The present invention provides an optimization method for a UI automated test framework, the optimization method comprising: step S1, recording a script before testing to obtain UI page elements; building an automated test framework and introducing required code modules; step S2, setting a framework timeout according to the actual project situation, encapsulating the test framework by searching for elements, encapsulating the test framework by clicking on elements, encapsulating the test framework by page snapshots, encapsulating the test framework by exception handling, and testing the UI page use case by the encapsulated test framework; step S3, after the use case is executed, writing the test result into a test report; after the use case fails to execute, outputting an error code log, and simultaneously writing the error page snapshot into the test report details of the corresponding use case. The present invention improves the success rate of use case execution and improves test efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer communication equipment, and in particular to an optimization method and system for a UI automated testing framework. Background Art

[0002] UI automated testing is applied to shorten the testing cycle, avoid human errors and improve the efficiency of regression testing. However, there is no testing framework in the existing technology that can meet any testing requirements of the site. The existing automated testing framework provides a large number of encapsulation methods, but still has limitations in testing page operations. Therefore, it is necessary to further encapsulate based on the original framework and provide a general solution.

[0003] At present, there are still the following problems when using the original framework method:

[0004] (1) When an error occurs during the use case execution, the framework will output an error message, but the error page cannot be located;

[0005] (2) The syntax is not concise enough. Simple functions require long test cases, which wastes time and is inefficient due to large amounts of repeated code.

[0006] (3) Polling element status to determine page stability has a large error compared to the actual stable state of the page, resulting in a high failure rate for use case execution, inability to guarantee the availability of use cases, and a waste of troubleshooting investment. Summary of the invention

[0007] To overcome the above problems, the purpose of the present invention is to provide an optimization method for a UI automation test framework, which simplifies the writing of use cases, reduces a large amount of repeated code, supports the completion of test scripts in a short time, and releases manpower.

[0008] The present invention is implemented by the following scheme: a method for optimizing a UI automated testing framework, the optimization method comprising the following steps:

[0009] Step S1: Record the script before testing to obtain UI page elements; build an automated testing framework and introduce the required code modules;

[0010] Step S2, setting the framework timeout time according to the actual situation of the project, encapsulating the test framework by searching elements, encapsulating the test framework by clicking elements, encapsulating the test framework by page snapshots, encapsulating the test framework by exception handling, and testing the UI page use case with the encapsulated test framework;

[0011] Step S3: After the use case is executed successfully, the test result is written into the test report; after the use case fails to execute, the error code log is output, and the error page snapshot is simultaneously written into the test report details of the corresponding use case.

[0012] Furthermore, the optimization method also includes:

[0013] Step S4: Continuous integration is performed using the continuous integration tool Jenkins. Test cases are run on a daily basis, and test reports are output and pushed to operators. The test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

[0014] Furthermore, the element search method is to poll the page element status within the timeout range; the element click method is divided into two situations: situation one is that the number of requests initiated by the site changes after clicking the element; situation two is that the site does not initiate a request after clicking the element; for situation one, directly use the click method of the unencapsulated test framework; for situation two, after finding the element and before clicking the element, use the js method to determine whether the number of requests of the current site changes. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and determine.

[0015] Furthermore, when a page operation times out or an abnormal error blocks the execution of a use case, the page snapshot method is called to take a screenshot of the error interface, and the image is saved in a set folder. When a test report is generated, the corresponding image is pulled from the folder and inserted into the test report for push.

[0016] Furthermore, the exception handling method is to take into account that during the execution of the use case, network fluctuations may occur, causing the page to freeze, thereby exceeding the timeout period, so each node has a page retry refresh function set; and when an exception occurs, an error on the server causes no data, the exception information is captured and the log is output.

[0017] Furthermore, the test framework encapsulated in step S2 tests the UI page use case in a further specific manner as follows: determine whether the number of requests of the current site changes after clicking the element, if not, use the click method of the test framework before encapsulation to click; determine whether an exception occurs in the click, if not, end the process, if yes, perform exception handling, use the abnormal page snapshot to capture, generate a test report and end the process; if there is a change, use the click method of the encapsulated test framework to poll and search for page elements to determine whether the element is found, if the element is found, use the JS method to determine whether the number of requests initiated by the current site has changed, if yes, continue to poll and wait; if no, click the page element and end the process; if the element is not found, determine whether the timeout period has expired, if no, continue to poll and search for page elements, if yes, perform exception handling, use the abnormal page snapshot to capture, generate a test report and end the process.

[0018] The present invention also provides an optimization system for a UI automated testing framework, the system comprising a script recording module, a test execution module, and a test report output module;

[0019] The script recording module is used to record scripts before testing and obtain UI page elements; build an automated testing framework and introduce required code modules;

[0020] The execution test module is used to set the framework timeout time according to the actual situation of the project, encapsulate the test framework by searching elements, clicking elements, encapsulating the test framework by page snapshots, and encapsulating the test framework by exception handling. The encapsulated test framework tests the UI page use case;

[0021] The output test report module is used to write the test results into the test report after the use case is executed successfully; after the use case fails to execute, the error code log is output, and the error page snapshot is simultaneously written into the test report details of the corresponding use case.

[0022] Furthermore, the system also includes a data analysis module;

[0023] The data analysis module is used to perform continuous integration with the help of the continuous integration tool Jenkins, run test cases on a daily basis, output test reports and push them to operators; the test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

[0024] Furthermore, the element search method is to poll the page element status within the timeout range; the element click method is divided into two situations: situation one is that the number of requests initiated by the site changes after clicking the element; situation two is that the site does not initiate a request after clicking the element; for situation one, directly use the click method of the unencapsulated test framework; for situation two, after finding the element and before clicking the element, use the js method to determine whether the number of requests of the current site changes. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and determine.

[0025] Furthermore, when a page operation times out or an abnormal error blocks the execution of a use case, the page snapshot method is called to take a screenshot of the error interface, and the image is saved in a set folder. When a test report is generated, the corresponding image is pulled from the folder and inserted into the test report for push.

[0026] Furthermore, the exception handling method is to take into account that during the execution of the use case, network fluctuations may occur, causing the page to freeze, thereby exceeding the timeout period, so each node has a page retry refresh function set; and when an exception occurs, an error on the server causes no data, the exception information is captured and the log is output.

[0027] Furthermore, the encapsulated test framework tests the UI page use case in the following specific ways: determine whether the number of requests of the current site changes after clicking the element. If not, use the click method of the test framework before encapsulation to click; determine whether an exception occurs in the click. If not, end the process. If yes, perform exception handling, use the snapshot capture of the abnormal page to generate a test report and end the process; if there is a change, use the click method of the encapsulated test framework to poll and search for page elements to determine whether the element is found. If the element is found, use the JS method to determine whether the number of requests initiated by the current site has changed. If yes, continue to poll and wait; if no, click the page element and end the process; if the element is not found, determine whether the timeout period has expired. If no, continue to poll and search for page elements. If yes, perform exception handling, use the snapshot capture of the abnormal page to generate a test report and end the process.

[0028] The beneficial effects of the present invention are: 1. The framework optimization method dynamically determines the waiting time for page stability, improves the success rate of use case execution, and improves test efficiency;

[0029] 2. The framework optimization method simplifies the use case writing, reduces a lot of duplicate code, supports the completion of test scripts in a short time, and releases manpower;

[0030] 3. An innovation was made effectively, overcoming a difficulty of UI automated testing, accurately judging the stability of the page, achieving the goal of full-process automated testing of the site, and improving the quality of testing;

[0031] 4. The test result information is complete, which is convenient for troubleshooting and subsequent optimization analysis. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] Figure 1 It is a schematic flow chart of the method of the present invention.

[0033] Figure 2 It is a flow chart of testing the UI page use case by the encapsulated test framework of the present invention.

[0034] Figure 3 It is a system principle block diagram of the present invention. DETAILED DESCRIPTION

[0035] The present invention will be further described below in conjunction with the accompanying drawings.

[0036] See also Figure 1 As shown, an optimization method of a UI automation test framework of the present invention comprises the following steps:

[0037] Step S1: Record a script before testing to obtain UI page elements (page elements include but are not limited to path, name, unique identifier, etc.); build an automated testing framework and introduce the required code modules;

[0038] Step S2, setting the framework timeout time according to the actual situation of the project, encapsulating the test framework by searching elements, encapsulating the test framework by clicking elements, encapsulating the test framework by page snapshots, encapsulating the test framework by exception handling, and testing the UI page use case with the encapsulated test framework;

[0039] Step S3: After the use case is executed successfully, the test result is written into the test report; after the use case fails to execute, the error code log is output, and the error page snapshot is simultaneously written into the test report details of the corresponding use case.

[0040] Step S4: Continuous integration is performed using the continuous integration tool Jenkins. Test cases are run on a daily basis, and test reports are output and pushed to operators. The test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

[0041] 1. Find element encapsulation

[0042] Poll (i.e., query each page element in sequence) the element status within the timeout range, and provide a method for finding page elements after encapsulation. This method for finding elements is built-in to the original framework, but it does not do fault tolerance processing. For example, when clicking on a page quickly, the previous click needs to load other js (i.e., JavaScript) as the pre-content for the next click. The original framework does not do compatibility processing, which will cause errors when clicking quickly. This framework is encapsulated on the basis of the original framework, and determines whether the page has reached a stable state by judging the state of the target element and whether all elements of the page have been loaded. This greatly reduces the failure rate of test case execution due to incomplete loading of system resources.

[0043] 2. Click element mode encapsulation

[0044] There are two cases for the encapsulation of click elements: one is that the number of requests initiated by the site changes after the element is clicked, such as login, deletion and other operations; the other is that the site does not initiate a request after the element is clicked, such as copy and paste and other operations;

[0045] Two click methods are encapsulated for the above two situations. In both cases, after finding the element and before clicking the element, the js method (i.e., JavaScript method) is used to determine whether the number of requests of the current site has changed. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and determine (i.e., by polling, the element information obtained in each request is compared with the information obtained in the previous request. When the results of multiple rounds of comparisons are consistent, the polling ends and it is determined that the current page has been loaded.). The difference is that in case one, the number of requests is determined to have changed after clicking the element, while in case two, the click method of the original framework is directly used.

[0046] 3. Page snapshot packaging

[0047] When the page operation times out or reports an error, blocking the execution of the test case, call the page snapshot method, take a screenshot of the error interface, save the image in a specified folder, and when generating a test report, pull the corresponding image from the folder and insert it into the test report for push. The page snapshot method is an existing technology, but the original technology is just a screenshot, it will not be associated with a specific use case, and for the user, it is just a photo. This framework encapsulates the output of the test report and associates it with each test case, that is, the snapshot corresponds to the test case, and the user does not need to maintain it manually.

[0048] 4. Exception handling encapsulation

[0049] Considering that network fluctuations may cause page freezes during the execution of the use case, thus exceeding the timeout period, each node has a page retry refresh function set up; and when an exception occurs, such as an error on the server resulting in no data, the exception information is captured and the log is output.

[0050] See also Figure 2 As shown, the test framework encapsulated in step S2 tests the UI page use case further specifically as follows: determine whether the number of requests of the current site changes after clicking the element, if not, use the click method of the test framework before encapsulation to click; determine whether an exception occurs in the click, if not, end the process, if yes, perform exception handling, use the snapshot capture of the abnormal page, generate a test report and end the process; if there is a change, use the click method of the encapsulated test framework to poll and find the page element, determine whether the element is found, find the element, use the JS method to determine whether the number of requests initiated by the current site has changed, if yes, continue to poll and wait; if no, click the page element and end the process; if the element is not found, determine whether the timeout period is exceeded, if no, continue to poll and find the page element, if yes, perform exception handling, use the snapshot capture of the abnormal page, generate a test report and end the process.

[0051] See also Figure 3 As shown, the present invention also provides an optimization system for a UI automated testing framework, the system comprising a script recording module, a test execution module, a test report output module, and a data analysis module;

[0052] The script recording module is used to record scripts before testing and obtain UI page elements; build an automated testing framework and introduce required code modules;

[0053] The execution test module is used to set the framework timeout time according to the actual situation of the project, encapsulate the test framework by searching elements, clicking elements, encapsulating the test framework by page snapshots, and encapsulating the test framework by exception handling. The encapsulated test framework tests the UI page use case;

[0054] The output test report module is used to write the test results into the test report after the use case is executed successfully; after the use case fails to execute, the error code log is output, and the error page snapshot is simultaneously written into the test report details of the corresponding use case.

[0055] The data analysis module is used to perform continuous integration with the help of the continuous integration tool Jenkins, run test cases on a daily basis, output test reports and push them to operators; the test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

[0056] Among them, the element search method is to poll the page element status within the timeout range; the element click method is divided into two situations: situation one is that the number of requests initiated by the site changes after clicking the element, such as login, deletion and other operations; situation two is that the site does not initiate a request after clicking the element, such as copy and paste and other operations; for situation one, directly use the click method of the unencapsulated test framework, and for situation two, use the js method to determine whether the number of requests of the current site has changed after finding the element and before clicking the element. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and judge (that is, through polling, the element information obtained for each request is compared with the information obtained in the previous time. When the results of multiple rounds of comparisons are consistent, the polling ends and it is determined that the current page has been loaded.).

[0057] The page snapshot method is to call the page snapshot method to take a screenshot of the error interface when a page operation times out or an error exception blocks the execution of the use case, and save the picture in a set folder. When generating a test report, pull the corresponding picture from the folder and insert it into the test report for pushing.

[0058] The exception handling method is to take into account that during the execution of the use case, network fluctuations may cause page freezes, thereby exceeding the timeout period, so each node has a page retry refresh function; and when an exception occurs, an error occurs on the server side resulting in no data, the exception information is captured and the log is output.

[0059] The encapsulated test framework further tests the UI page use case as follows: determine whether the number of requests of the current site changes after clicking the element. If not, use the click method of the unencapsulated test framework to click; determine whether an exception occurs in the click. If not, end the process. If yes, perform exception handling, use the abnormal page snapshot to capture, generate a test report and end the process; if there is a change, use the click method of the encapsulated test framework to poll and find the page element to determine whether the element is found. If the element is found, use the JS method (i.e., JavaScript method) to determine whether the number of requests initiated by the current site has changed. If yes, continue to poll and wait; if no, click the page element and end the process; if the element is not found, determine whether the timeout period has expired. If no, continue to poll and find the page element. If yes, perform exception handling, use the abnormal page snapshot to capture, generate a test report and end the process.

[0060] The above description is only a preferred embodiment of the present invention. All equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the present invention.

Claims

1. A method for optimizing a UI automated testing framework, characterized in that: The optimization method comprises the following steps: Step S1: Record the script before testing to obtain UI page elements; build an automated testing framework and introduce the required code modules; Step S2, setting the framework timeout time according to the actual situation of the project, encapsulating the test framework by searching elements, encapsulating the test framework by clicking elements, encapsulating the test framework by page snapshots, encapsulating the test framework by exception handling, and testing the UI page use case with the encapsulated test framework; Step S3: After the test case is executed successfully, the test result is written into the test report; After the use case execution fails, the error code log is output, and the error page snapshot is written into the test report details of the corresponding use case; the element search method is to poll the page element status within the timeout period; the element click method is divided into two cases: case one is that the number of requests initiated by the site changes after clicking the element; case two is that the site does not initiate a request after clicking the element; for case one, the click method of the unencapsulated test framework is directly used; for case two, after finding the element and before clicking the element, the js method is used to determine whether the number of requests of the current site has changed. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and determine.

2. The optimization method of a UI automation test framework according to claim 1, characterized in that: The optimization method further comprises: Step S4: Continuous integration is performed using the continuous integration tool Jenkins. Test cases are run on a daily basis, and test reports are output and pushed to operators. The test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

3. The optimization method of a UI automation test framework according to claim 1, characterized in that: The page snapshot method is to call the page snapshot method to take a screenshot of the error interface when a page operation times out or an error exception blocks the execution of the use case, and save the picture in a set folder. When generating a test report, pull the corresponding picture from the folder and insert it into the test report for pushing.

4. The optimization method of a UI automation test framework according to claim 1, characterized in that: The exception handling method is to consider that during the execution of the use case, there may be network fluctuations that cause the page to freeze, thereby exceeding the timeout period, so each node has a page retry refresh function; When an exception occurs, the server fails and no data is found, the exception information is captured and the log is output.

5. The optimization method of a UI automation test framework according to claim 1, characterized in that: The encapsulated test framework in step S2 further specifically tests the UI page use case by: judging whether the number of requests of the current site changes after clicking the element, if not, using the click method of the test framework before encapsulation to click; judging whether an exception occurs in the click, if not, ending the process, if yes, performing exception handling, using the snapshot capture of the abnormal page, generating a test report and ending the process; if there is a change, using the click method of the encapsulated test framework to poll and search for page elements, judging whether the element is found, and if the element is found, using the JS method to judge whether the number of requests initiated by the current site changes, if yes, continuing to poll and wait; No, click on the page element and end the process; If the element is not found, determine whether the timeout period has expired. If not, continue to poll to find the page element. If yes, perform exception handling, capture the exception page snapshot, generate a test report and end the process.

6. An optimization system for a UI automated testing framework, characterized in that: The system includes a script recording module, a test execution module, and a test report output module; The script recording module is used to record the script before testing and obtain UI page elements; Build an automated testing framework and introduce required code modules; The execution test module is used to set the framework timeout time according to the actual situation of the project, encapsulate the test framework by searching elements, clicking elements, encapsulating the test framework by page snapshots, and encapsulating the test framework by exception handling. The encapsulated test framework tests the UI page use case; The test report output module is used to write the test results into the test report after the test case is executed successfully; After the use case execution fails, the error code log is output, and the error page snapshot is written into the test report details of the corresponding use case; the element search method is to poll the page element status within the timeout period; the element click method is divided into two cases: case one is that the number of requests initiated by the site changes after clicking the element; case two is that the site does not initiate a request after clicking the element; for case one, the click method of the unencapsulated test framework is directly used; for case two, after finding the element and before clicking the element, the js method is used to determine whether the number of requests of the current site has changed. If the number of requests does not change, click again; if the number of requests still changes, continue to poll and determine.

7. The optimization system of a UI automated testing framework according to claim 6, characterized in that: The system also includes a data analysis module; The data analysis module is used to perform continuous integration with the help of the continuous integration tool Jenkins, run test cases on a daily basis, output test reports and push them to operators; the test reports are stored on the content server to facilitate subsequent data analysis of failure causes and pass rates.

8. The optimization system of a UI automated testing framework according to claim 6, characterized in that: The page snapshot method is to call the page snapshot method to take a screenshot of the error interface when a page operation times out or an error exception blocks the execution of the use case, and save the picture in a set folder. When generating a test report, pull the corresponding picture from the folder and insert it into the test report for pushing.

9. The optimization system of a UI automated testing framework according to claim 6, characterized in that: The exception handling method is to consider that during the execution of the use case, there may be network fluctuations that cause the page to freeze, thereby exceeding the timeout period, so each node has a page retry refresh function; When an exception occurs, the server fails and no data is found, the exception information is captured and the log is output.

10. The optimization system of a UI automated testing framework according to claim 6, characterized in that: The encapsulated test framework further tests the UI page use case as follows: determine whether the number of requests of the current site changes after clicking on the element. If not, use the click method of the test framework before encapsulation to click; determine whether an exception occurs in the click. If not, end the process. If yes, perform exception handling, use the snapshot capture of the abnormal page, generate a test report and end the process; if there is a change, use the click method of the encapsulated test framework to poll and search for page elements to determine whether the element is found. If the element is found, use the JS method to determine whether the number of requests initiated by the current site changes. If yes, continue to poll and wait; No, click on the page element and end the process; If the element is not found, determine whether the timeout period has expired. If not, continue to poll to find the page element. If yes, perform exception handling, capture the exception page snapshot, generate a test report and end the process.

Citation Information

Patent Citations

  • System and method for implementing view development of Web application automatic testing

    CN104991777A

  • Selenium-based Web application automatic test framework and construction method and system thereof

    CN110851356A

  • Automatic testing method, device and equipment for WEB page cases, and storage medium

    CN110941546A

  • Test automation modeling

    US20160335171A1

  • Web page testing method and apparatus, electronic device, and medium

    WO2019196274A1