Python-based Web system automatic test method
By building a UI automation testing framework and an interface automation testing framework based on the POM pattern using Python, and combining them with a visual testing platform, the problems of low testing efficiency and high maintenance costs of traditional web systems are solved, achieving efficient and low-cost testing results.
Patent Information
- Application Number
- CN202510855744.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-25
- Publication Date
- 2025-10-24
AI Technical Summary
Traditional web system testing methods are inefficient, error-prone, and disconnected from UI testing and interface testing, resulting in high maintenance costs and a lack of intuitive visual interfaces and detailed test result displays.
We built a UI automation testing framework based on the POM pattern using Python, combined with an interface automation testing framework, and used Selenium and httprunner tools to construct a visual testing platform. We also created an intuitive GUI interface using the Tkinter library to achieve unification of UI and interface testing.
It improves the execution efficiency of web automation testing, reduces project risks and labor costs, simplifies testing operations, and enhances test accuracy and maintainability.
Smart Images

Figure CN120832302A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of software testing, and particularly relates to a Python-based Web system automatic testing method. BACKGROUND
[0002] With the increasing complexity and diversification of Web applications, traditional manual testing methods have been difficult to meet the efficiency and accuracy requirements of modern software development delivery. Therefore, Web automatic testing as an efficient and comprehensive testing method has gradually become an important part of software quality assurance. The visual testing interface makes the testing operation simpler and the results clearer.
[0003] However, the existing testing methods have the following pain points: traditional web system testing relies on manual script writing, which is low in efficiency and prone to errors; UI testing and interface testing are separated, and different tools are often used for UI and interface testing, resulting in a doubled maintenance cost; visual operation and result display are missing, the testing lacks an intuitive operation interface and the testing result display is too simple, lacking intuitive logs, which increases the testing threshold.
[0004] A software automatic testing method and system with low maintenance cost disclosed in Chinese patent No. CN112699055B discloses a testing method, which comprises the following steps: S1, identifying and describing the test object; S2, obtaining the test case, splitting out the test action and test data, and performing unique identification and description; S3, generating a test script by combining the test object, test data and test action described in S1 and S2; S4, generating a test execution file by organizing and arranging the test script described in S3; and S5, generating a test report by running the test execution file described in S4. However, the testing method cannot visually display the monitoring data, and the testing threshold is high. SUMMARY
[0005] The technical problem to be solved by the application is to provide a Python-based Web system automatic testing method, which can improve the execution efficiency of Web automatic testing, avoid the problem of high usage threshold, and reduce project risk and labor cost.
[0006] The technical solution of the application is to provide a Python-based Web system automatic testing method, which comprises the following steps: interface test data grabbing, page element acquisition, test framework building, and creating a visual testing platform by combining UI and interface cases.
[0007] The interface test data grabbing uses the charls tool to perform data packet grabbing, sets up a proxy and installs an SSL certificate, and performs file conversion in yaml format after completing the packet grabbing;
[0008] The page element acquisition uses the method provided by Selenium to acquire the relevant information of the element, analyzes and processes the page, and encapsulates (PO, Page Object page object); (PO, Page Object page object) is a test design pattern in Selenium, encapsulates independent classes for page elements buttons, input boxes, selection boxes, and page clicks, inputs, and movements, and each page has a corresponding PO class, similar to object-oriented, which can make the test code more readable, maintainable, and reusable;
[0009] The test framework is built based on Python, and both a UI automation test framework and an interface automation test framework are established, so as to test the Web system; the UI automation test framework uses a page object model, constructs a logic layer, a business layer, and an object layer; the interface automation test framework uses a recording method and an httprunner framework to automatically create test cases.
[0010] The visual test platform combining UI and interface case creation uses the controls and components of the Tkinter standard graphical user interface (GUI) library to build an intuitive and fully functional user interface for executing test processes, real-time viewing and analyzing test results, and combining UI testing and interface testing with the same function when building page function tags, returning test results containing UI and interface testing, and verifying each other to improve test accuracy and reduce costs.
[0011] Preferably, the relevant information of the element includes text content, size, and attribute value.
[0012] Preferably, the UI automation test framework uses unittest, which is a unit test framework in Python standard library, to write automated test scripts, organize and run test cases, output result reports, and the interface automation test framework uses httprunner to achieve automated testing, performance testing, online monitoring, and continuous integration of multiple testing requirements by writing and maintaining a yaml script.
[0013] Preferably, the file conversion of the yaml script uses har2case to parse http request and response data in the har file and automatically generate structured yaml test cases. The project uses multiple python libraries to handle file reading and writing, data parsing, and log recording tasks to ensure efficient and stable conversion process.
[0014] As preferred, Tkinter is used to create a visual automatic test platform for executing test procedures, viewing and analyzing test results in real time, placing UI automation testing and interface automation testing of the same function in the same method when building a page function tag, returning test results containing UI automation testing and interface automation testing, and sending a test report by email after the test is completed.
[0015] As preferred, the object layer provides a common class to implement the core component WebDriver function of Selenium, controls the browser to perform a series of operations including opening a webpage, clicking a button, filling out a form, simulates real user behavior, interacts with the webpage, and thus realizes the automatic testing of the webpage.
[0016] As preferred, the logic layer takes a function page of a test system as a Page class, each Page class maintains a set of elements of the page and a method of operating the elements, and the number of Page classes is subject to the specific test system.
[0017] As preferred, the element searching method of Selenium includes at least one of the searching methods through ID, Class, Css Selector, and Xpath.
[0018] As preferred, the interface automation testing uses recording to distinguish functions, and each function page is matched with the Page class.
[0019] Compared with the prior art, the present application has the following advantages:
[0020] The present application uses POM mode to perform UI automation testing, separates element positioning and operation logic, encapsulates each page as an independent class, improves code reuse rate and maintainability, and avoids global script reconstruction. Interface automation testing using the recording method combined with the httprunner framework can realize rapid case writing and running, not only ensures software quality but also improves test efficiency and reduces labor cost. The combination of UI automation testing and interface automation testing of the same function realizes high unification of test scenarios, not only reduces maintenance cost but also supports each other. BRIEF DESCRIPTION OF DRAWINGS
[0021] Figure 1 Flow chart of the Web system automatic testing method.
[0022] Figure 2 PO mode call relationship diagram.
[0023] Figure 3To interface automatic test flow chart.
[0024] Figure 4 To create GUI interface flow chart. DETAILED DESCRIPTION
[0025] The application will be further described in the specific embodiments in conjunction with the accompanying drawings:
[0026] As Figure 1 A Python-based web system automatic test method, comprising the following steps: interface test data grabbing, page element acquisition, test framework building, and creating a visual test platform combining UI and interface cases, wherein,
[0027] The interface test data grabbing uses the charls tool to perform data packet grabbing, sets up a proxy, installs an SSL certificate, and performs yaml format file conversion after completing the packet grabbing;
[0028] The page element acquisition uses the method provided by Selenium to acquire the text content, size, attribute value and other information of the element, analyzes and processes the page, and encapsulates (PO, Page Object page object); (PO, Page Object page object) is a test design mode in Selenium, encapsulates independent classes for the element buttons, input boxes, selection boxes and page clicks, inputs and movements of the page, each page has a corresponding PO class, similar to object-oriented, can make the test code more readable, high maintainability and high reusability;
[0029] The test framework building establishes a UI automatic test framework and an interface automatic test framework based on python, thereby testing the web system; the UI automatic test framework uses a page object model, constructs a logic layer, a business layer and an object layer; the interface automatic test framework uses a recording method and an httprunner framework to automatically create test cases; the object layer provides a public class to realize the core component WebDriver function of Selenium, controls the browser to perform a series of operations including opening a webpage, clicking a button, filling a form, simulates real user behavior, interacts with the webpage, thereby realizing automatic test of the webpage; the logic layer takes a function page of the test system as a Page class, each Page class maintains the element set and the method of operating the element of the page, and the number of Page classes is subject to the specific test system;
[0030] The test platform is created by combining UI and interface cases, using the controls and components of the Tkinter standard graphical user interface library to build an intuitive and fully functional user interface for executing test processes and viewing and analyzing test results in real time. When building page function tags, UI testing and interface testing are combined, and the test results include UI and interface testing, which are verified with each other to improve test accuracy and reduce costs
[0031] The test framework of the embodiment is used to perform UI automation testing and interface automation testing. The UI automation testing is equivalent to simulating user behavior to perform automatic operations on a browser. The interface automation testing can automatically perform interface operations. Using automation testing can reduce project labor costs and complete repetitive work of various types of functional testing.
[0032] The test framework of the embodiment is based on Python and POM. Python 3 language can be installed, and the language version can be between 3.x (such as 3.4 to 3.8). The Selenium and httprunner tools are added to the system variable path, the browser and the corresponding browser driver are installed, and it is ensured that the water monitoring platform can be successfully logged in.
[0033] In the UI automation testing, a logical layer webpage is constructed, which includes multiple pages such as login of the test platform, hydrophone monitoring, pressure monitoring, and alarm. Each page corresponds to a Page class, and each Page class maintains a set of elements of the page and methods for operating the elements. An object layer webbase is constructed to store page element positioning and control operation. A business layer webcase is constructed to execute corresponding test cases. The core component WebDriver of Selenium controls the browser to perform a series of operations such as opening a webpage, clicking a button, and filling out a form. Real user behavior is simulated to interact with the webpage, thereby realizing automatic testing of the webpage. Figure 2 As shown in the figure, if the page elements change due to demand changes, only the element code in the page object needs to be changed, and the business logic remains unchanged, thereby enhancing the maintenance efficiency.
[0034] In the business layer construction step, the methods for operating page elements in Selenium are encapsulated. After the object is obtained, the element operation is performed to achieve the purpose of operating the Web.
[0035] In the object layer construction step, the element searching method of Selenium includes at least one of the searching methods through ID, Class, CssSelector, and Xpath.
[0036] In interface automation testing, the interface recording is performed by packet capture tools such as Fiddler, Charles, etc., and then exported to the standard universal har format (http archive). Multiple function pages export multiple files such as login, hydrophone monitoring, pressure monitoring, and alarm, which correspond to the logical layer constructed by UI automation testing. Then, httprunner converts the har (http archive) format data packet into a yaml / json format test file, and finally generates a pytest format test case, so as to facilitate the execution of these test cases by pytest. Figure 3
[0037] A standard graphical user interface is created to quickly build a GUI application. Tkinter is used to build an intuitive and fully functional user interface, and the page information includes test execution progress, test function buttons, real-time log display, and test result pass rate display. Such interface design not only greatly simplifies the complexity of test work, but also significantly improves the efficiency and accuracy of testing. The GUI interface creation process is as shown in Figure 4
[0038] When building the page function label, the UI test and interface test cases of the same function are combined. The test result returned after the page executes the function is the common test result of UI and interface. If one of them fails, the whole test fails. The specific test report will be sent to the set mailbox.
[0039] The test report is generated by HtmlTestRunner and other frameworks, and the report is sent to the predetermined mailbox in the form of an email, providing the specific test results to the test personnel or relevant person in charge.
[0040] The UI automation test of the application uses the POM mode, and the element positioning and operation logic are separated. Each page is encapsulated as an independent class, which improves the code reuse rate and maintainability, and avoids global script reconstruction. The interface automation test uses the httprunner framework of Python, which has a powerful and flexible tool for writing, executing, and reporting test cases. It can also automatically record interface cases to generate test files, improve test efficiency, and reduce labor costs.
[0041] The UI automation test and the interface automation test of the same function are combined, which realizes the high unification of the test scene, reduces the maintenance cost, and can support each other.
[0042] The GUI application is generated to realize the visualization of the test function, display the test function module, test log, and test progress of the system, facilitate the operation and execution of the test personnel, and reduce the test threshold.
[0043] The above description is only for the preferred embodiments of the present application, but should not be understood as a limitation to the claims. Any equivalent changes made according to the description of the present application are included in the patent protection scope of the present application.
Claims
1. A Python-based web system automation testing method, characterized in that: It comprises the following steps: interface test data capture, page element acquisition, test framework building, and creating a visual test platform combining UI and interface cases, wherein, The interface test data capture uses the charls tool to capture data packets, sets up a proxy, installs an SSL certificate, and converts the captured data into a yaml format file after completion. The page element acquisition uses the methods provided by Selenium to obtain the relevant information of the elements, analyzes and processes the page, and encapsulates it. The test framework building establishes a UI automation test framework and an interface automation test framework based on Python, thereby testing the Web system. The UI automation test framework uses a page object model, constructs a logic layer, a business layer, and an object layer. The interface automation test framework uses the recording method and the httprunner framework to automatically create test cases. The visual test platform created by combining UI and interface cases uses the controls and components of the Tkinter standard graphical user interface library to build an intuitive and fully functional user interface for executing test processes, real-time viewing and analyzing test results. When building page function tags, the UI test and the interface test of the same function are combined, and the test results include UI and interface tests, which are verified with each other to improve test accuracy and reduce costs.
2. The Python-based web system automation testing method of claim 1, wherein: The relevant information of the elements includes text content, size, and attribute values.
3. The Python-based web system automation testing method of claim 1, wherein: The UI automation test framework uses unittest to write automated test scripts, organize and run test cases, and output result reports. The interface automation test framework uses httprunner to write and maintain a yaml script to achieve test requirements.
4. The Python-based web system automation testing method of claim 3, wherein: The yaml script file conversion uses har2case to parse the http request and response data in the har file and automatically generate structured yaml test cases.
5. The Python-based web system automation testing method of claim 1, wherein: Tkinter is used to create a visual automated test platform for executing test processes, real-time viewing and analyzing test results. When building page function tags, the UI automation test and the interface automation test of the same function are placed in the same method, and the test results include UI automation test and interface automation test. After the test is completed, a test report is sent by email.
6. The Python-based web system automation testing method of claim 1, wherein: The object layer provides a public class to implement the core component WebDriver function of Selenium, controls the browser to perform a series of operations, including opening a webpage, clicking a button, filling out a form, simulating real user behavior, interacting with the webpage, and thereby achieving automated testing of the webpage.
7. The Python-based web system automation testing method of claim 1, wherein: The logic layer takes the functional pages of the test system as a Page class, each Page class maintains the element set of the page and the method of operating the elements, and the number of Page classes is determined by the specific test system.
8. The Python-based web system automation testing method of claim 6, wherein: The Selenium element search method includes at least one of the search methods through ID, Class, Css Selector, and Xpath.
9. The Python-based web system automation testing method of claim 7, wherein: The interface automation test distinguishes functions when recording, and each functional page matches the Page class.
Citation Information
Patent Citations
A software automation testing method and system with low maintenance cost
CN112699055B
Cited By
WebUI self-adaptive test system and method based on multi-agent cooperation and multi-mode perception
CN121434099A
Webui adaptive testing system and method based on multi-agent cooperation and multi-modal perception
CN121434099B