Method and device for automatically testing user interface and electronic equipment
By combining pytest, Selenium and POIUM UI automated testing methods, the problem of time-consuming and labor-consuming manual regression testing is solved, and efficient and accurate page testing is achieved and problem-localization is quickly achieved.
Patent Information
- Application Number
- CN202510542105.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-08-15
AI Technical Summary
Traditional page testing mainly relies on manual regression testing, which consumes a lot of time and manpower, and is prone to omissions and cannot meet the testing needs.
The UI automated testing method based on the pytest framework combined with Selenium, POIUM and Monkey tests includes configuring the running environment, building Page Object models, writing test cases and executing Monkey scripts to feedback test results.
Improve the efficiency, accuracy and stability of the test, and technicians can quickly locate problems and reduce the risk of online problems.
Smart Images

Figure CN120492362A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of software testing, and in particular to a user interface automated testing method, a device thereof, and an electronic device. Background Art
[0002] During the software development and testing process, page modifications need to be tested and regressed. Page testing often requires compatibility testing. Traditional compatibility testing often cannot meet the requirements of testing different devices. As software systems become more and more complex, they need to be comprehensively tested to detect their impact on device performance.
[0003] Currently, traditional page testing mainly relies on manual regression testing. However, manual regression testing requires a lot of time and manpower and is prone to missing scenarios, which cannot meet testing needs. Summary of the Invention
[0004] The purpose of the embodiments of the present invention is to provide a user interface automated testing method to solve the problem that traditional page testing mainly relies on manual regression testing, which consumes a lot of time and manpower and is prone to missing scenarios. It cannot meet the testing needs. The specific technical solution is as follows:
[0005] In the first aspect of the present invention, a UI automation testing method based on the pytest framework combined with Selenium, POIUM, and Monkey testing is provided, including:
[0006] Configure the test case runtime environment, which includes the project environment and tool runtime environment required for using pytest, Selenium, POIUM, and Monkey testing;
[0007] Build Page Object model based on POIUM;
[0008] Write test cases based on pytest;
[0009] Execute test cases and Monkey scripts and provide feedback on test results.
[0010] Optionally, the building of the Page Object model based on POIUM includes:
[0011] Create a corresponding Page class for each page or module of the UI being tested;
[0012] In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements;
[0013] Build relationships between Page classes through inheritance and composition.
[0014] Optionally, the test case writing based on pytest includes:
[0015] In the pytest test file, import the Page Object model and Selenium module;
[0016] Use pytest's test function definition syntax to write test cases.
[0017] Optionally, the test function definition syntax of pytest is used to write test cases, including:
[0018] Use pytest's parameterization function to provide different test data for test cases;
[0019] Initialize and clean up the test case.
[0020] Optionally, executing the Monkey test and feeding back the test result includes:
[0021] Set the parameters of the Monkey test, including the information in the configuration file and the pre-set data;
[0022] Call the Monkey testing tool according to the parameters, and use Selenium and POIUM to monitor UI page operations and application resources in real time, and generate test reports.
[0023] Beneficial effects of the present invention:
[0024] An embodiment of the present invention provides a user interface automation testing method, comprising: configuring a test case runtime environment, including the project environment and tool runtime environment required for testing using pytest, Selenium, POIUM, and Monkey; building a Page Object model based on POIUM; writing test cases based on pytest; executing the test cases and Monkey scripts, and providing feedback on the test results. This solution, combining Selenium and POIUM, enables precise manipulation and element location of complex UI interfaces. Selenium provides a rich set of browser manipulation and element location methods, while POIUM further simplifies the code writing for element location and manipulation. The combination of the two significantly improves test efficiency, accuracy, and stability. After executing the test case, technicians can quickly locate issues by reviewing the test report, significantly speeding up problem resolution and reducing the risk of online issues.
[0025] In order to solve the above problem, in a second aspect of the present invention, a user interface automated testing device is provided, comprising:
[0026] The environment configuration module is used to configure the running environment of the test cases, including the project environment and tool running environment required for pytest, Selenium, POIUM and Monkey testing;
[0027] Model building module, used to build Page Object model based on POIUM;
[0028] Test writing module, used to write test cases based on pytest;
[0029] The test execution module is used to execute test cases and Monkey scripts and feedback the test results.
[0030] Optionally, the model building module is specifically used to:
[0031] Create a corresponding Page class for each page or module of the UI being tested;
[0032] In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements;
[0033] Build relationships between Page classes through inheritance and composition.
[0034] Optionally, the test writing module includes:
[0035] Model import unit, used to import Page Object model and Selenium module in pytest test file;
[0036] The use case writing unit is used to write test cases using pytest's test function definition syntax.
[0037] Optionally, the use case writing unit is specifically used to:
[0038] Use pytest's parameterization function to provide different test data for test cases;
[0039] Initialize and clean up the test case.
[0040] In order to solve the above problem, in a third aspect of the present invention, an electronic device is provided, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus;
[0041] Memory for storing computer programs;
[0042] The processor is used to implement the method steps described above when executing the program stored in the memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following briefly describes the drawings required for the specific embodiments or the description of the prior art. Similar elements or parts are generally identified by similar reference numerals throughout the drawings. Elements or parts in the drawings are not necessarily drawn to scale.
[0044] Figure 1 This is a flowchart of the UI automation testing method of the present invention based on the pytest framework combined with Selenium, POIUM and Monkey testing. DETAILED DESCRIPTION
[0045] The following embodiments of the technical solution of the present invention will be described in detail with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention and are therefore only examples and are not intended to limit the scope of protection of the present invention.
[0046] It should be noted that, unless otherwise specified, the technical or scientific terms used in the present invention should have the common meanings understood by those skilled in the art to which the present invention belongs.
[0047] like Figure 1 As shown, in order to solve the problems in the prior art, the present invention provides a user interface automation testing method to solve the problem that traditional page testing mainly relies on manual regression testing. However, manual regression testing takes a lot of time and manpower and is prone to omissions. The problem of being unable to meet testing needs. Among them, the user interface (UserInterface, referred to as UI) is also called the user interface. The user interface is a medium for interaction and information exchange between the system and the user. The purpose is to enable users to operate the hardware conveniently and efficiently to achieve two-way interaction and complete work with the help of hardware. The user interface is broadly defined, including human-computer interaction and graphical user interface. Generally, user interfaces exist in the field of information exchange between humans and machines.
[0048] It should be noted that the user interface automated testing method provided by the embodiment of the present invention can be applied to electronic devices. In practical applications, the electronic devices can be: smart phones, tablet computers, laptop computers and other devices, which are all reasonable.
[0049] Selenium is a web application testing tool that simulates user operations in a browser to automate web page testing. POIUM is a Python-based Page Object model library that makes the positioning and operation of UI elements more concise and maintainable. Monkey testing is a stress testing tool that randomly generates user event streams to test application stability. pytest is a Python testing framework with advantages such as flexible test case organization, a rich plugin mechanism, and concise syntax.
[0050] The following first introduces a user interface automation testing method provided by an embodiment of the present invention.
[0051] like Figure 1 As shown, an embodiment of the present invention provides a user interface automated testing method, which may include the following steps:
[0052] S101, configure the running environment of the test case, which includes the project environment and tool running environment required when using pytest, Selenium, POIUM and Monkey testing.
[0053] Understandably, to meet testing requirements, you need to perform some basic installation and download configuration on the software testing environment. For example, you need to install the Python runtime environment, install pytest, Selenium, POIUM, and Monkey test-related databases, and download the corresponding browser driver so that it can be used with Selenium to achieve automated control of the browser.
[0054] S102: Build a Page Object model based on POIUM.
[0055] For example, in one implementation, building a Page Object model based on POIUM may include:
[0056] For each page or module of the UI under test, create a corresponding Page class; the Page Object model (PO pattern) is a design pattern used in automated testing, mainly used to reduce code duplication and improve the maintainability of test cases.
[0057] In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements;
[0058] Build relationships between Page classes through inheritance and composition.
[0059] UI elements can be pre-programmed into the test program, such as login operations: enter account number, enter password, click to agree to the agreement, click to confirm login, and verify successful login. Location methods can include account ID, account nickname, etc. Operation methods can include clicking, inputting, and getting text.
[0060] It is understandable that a page may have multiple sub-modules. Then, through inheritance and combination, the sub-modules can use the Page class of the sub-module as the attribute of the parent page Page class to achieve hierarchical management and operation of page elements.
[0061] S103, write test cases based on pytest.
[0062] For example, in one implementation, writing a test case based on pytest may include:
[0063] In the pytest test file, import the Page Object model and Selenium module;
[0064] Use pytest's test function definition syntax to write test cases.
[0065] In the test case, you can instantiate the Page class and call the operation methods of the page elements to achieve automated operations on the UI interface.
[0066] For example, using pytest's test function definition syntax, writing a test case may include:
[0067] Use pytest's parameterization function to provide different test data for test cases;
[0068] Initialize and clean up the test case.
[0069] For example, different combinations of user names and passwords can be parameterized to test the correctness of the login function under different input conditions.
[0070] The process of initializing and cleaning the test case may be a method for initializing and cleaning data in the prior art.
[0071] S104, execute the test case and Monkey script and feedback the test results.
[0072] Exemplarily, executing the test case and the Monkey script and feeding back the test results may include:
[0073] Set the parameters of the Monkey test, including the information in the configuration file and the pre-set data;
[0074] Call the Monkey testing tool according to the parameters, and use Selenium and POIUM to monitor UI page operations and application resources in real time, and generate test reports.
[0075] For example, the parameters may include packaged basic methods, such as logging, assertions, data operations, browser operations, etc. In addition, to facilitate the technicians' review, the generated test report may be automatically sent to the technicians via email or other means.
[0076] The resources occupied by an application may include CPU and memory.
[0077] This invention configures a test case runtime environment, including the project and tool runtime environments required for testing using pytest, Selenium, POIUM, and Monkey; builds a PageObject model based on POIUM; writes test cases based on pytest; executes the test cases and Monkey scripts, and provides feedback on the test results. This solution, combining Selenium and POIUM, enables precise manipulation and element location on complex UI interfaces. Selenium provides a rich set of browser manipulation and element location methods, while POIUM further simplifies the code for element location and manipulation. The combination of these two greatly improves test efficiency, accuracy, and stability. After executing the test case, technicians can quickly locate issues by viewing the test report, significantly speeding up problem resolution and reducing the risk of online issues.
[0078] In contrast to the above method embodiment, an embodiment of the present invention provides a user interface automated testing device, which may include:
[0079] The environment configuration module is used to configure the running environment of the test cases, including the project environment and tool running environment required for pytest, Selenium, POIUM and Monkey testing;
[0080] Model building module, used to build Page Object model based on POIUM;
[0081] Test writing module, used to write test cases based on pytest;
[0082] The test execution module is used to execute test cases and Monkey scripts and feedback the test results.
[0083] This invention configures a test case runtime environment, including the project and tool runtime environments required for testing using pytest, Selenium, POIUM, and Monkey; builds a PageObject model based on POIUM; writes test cases based on pytest; executes the test cases and Monkey scripts, and provides feedback on the test results. This solution, combining Selenium and POIUM, enables precise manipulation and element location on complex UI interfaces. Selenium provides a rich set of browser manipulation and element location methods, while POIUM further simplifies the code for element location and manipulation. The combination of these two greatly improves test efficiency, accuracy, and stability. After executing the test case, technicians can quickly locate issues by viewing the test report, significantly speeding up problem resolution and reducing the risk of online issues.
[0084] Optionally, the model building module is specifically used to:
[0085] Create a corresponding Page class for each page or module of the UI being tested;
[0086] In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements;
[0087] Build relationships between Page classes through inheritance and composition.
[0088] Optionally, the test writing module includes:
[0089] Model import unit, used to import Page Object model and Selenium module in pytest test file;
[0090] The use case writing unit is used to write test cases using pytest's test function definition syntax.
[0091] Optionally, the use case writing unit is specifically used to:
[0092] Use pytest's parameterization function to provide different test data for test cases;
[0093] Initialize and clean up the test case.
[0094] An embodiment of the present invention further provides an electronic device, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus.
[0095] Memory for storing computer programs;
[0096] The processor is used to implement a user interface automatic testing method provided by an embodiment of the present invention when executing a program stored in the memory.
[0097] The communication bus mentioned in the terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not mean that there is only one bus or only one type of bus.
[0098] The communication interface is used for communication between the above terminal and other devices.
[0099] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage. Alternatively, the memory may be at least one storage device located away from the processor.
[0100] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components.
[0101] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the user interface automation testing method described in any of the above embodiments is implemented.
[0102] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes a user interface automation testing method described in any one of the above embodiments.
[0103] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0104] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some or all of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and description of the present invention.
Claims
1. A user interface automated testing method, characterized in that: include: Configure the test case runtime environment, which includes the project environment and tool runtime environment required for using pytest, Selenium, POIUM, and Monkey testing; Build Page Object model based on POIUM; Write test cases based on pytest; Execute test cases and Monkey scripts and provide feedback on test results.
2. The method according to claim 1, characterized in that The POIUM-based Page Object model construction includes: Create a corresponding Page class for each page or module of the UI being tested; In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements; Build relationships between Page classes through inheritance and composition.
3. The method according to claim 1 or 2, characterized in that The test cases written based on pytest include: In the pytest test file, import the Page Object model and Selenium module; Use pytest's test function definition syntax to write test cases.
4. The method according to claim 3, characterized in that The test function definition syntax of pytest is used to write test cases, including: Use pytest's parameterization function to provide different test data for test cases; Initialize and clean up the test case.
5. The method according to claim 1 or 2, characterized in that The execution of test cases and Monkey scripts and feedback of test results include: Set the parameters of the Monkey test, including the information in the configuration file and the pre-set data; Call the Monkey testing tool according to the parameters, and use Selenium and POIUM to monitor UI page operations and application resources in real time, and generate test reports.
6. A user interface automated testing device, characterized in that: include: The environment configuration module is used to configure the running environment of the test cases, including the project environment and tool running environment required for pytest, Selenium, POIUM and Monkey testing; Model building module, used to build Page Object model based on POIUM; Test writing module, used to write test cases based on pytest; The test execution module is used to execute test cases and Monkey scripts and feedback the test results.
7. The device according to claim 6, characterized in that The model building module is specifically used to: Create a corresponding Page class for each page or module of the UI being tested; In the Page class, use the annotations and methods provided by POIUM to define the UI elements in the page, including the positioning method and operation method of the elements; Build relationships between Page classes through inheritance and composition.
8. The device according to claim 6 or 7, characterized in that The test writing module includes: Model import unit, used to import Page Object model and Selenium module in pytest test file; The use case writing unit is used to write test cases using pytest's test function definition syntax.
9. The device according to claim 6 or 7, characterized in that The use case writing unit is specifically used for: Use pytest's parameterization function to provide different test data for test cases; Initialize and clean up the test case.
10. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; Memory for storing computer programs; A processor, configured to implement the method steps described in any one of claims 1 to 5 when executing a program stored in a memory.