UI (User Interface) automatic test method and equipment for battery replacement program and medium

Through the combination of the Playwright framework and the pytest testing framework, the UI automation testing of the battery swap program is realized, solving the problem of inefficiency of traditional UI testing, and ensuring the integrity of the test and system stability.

CN120276970APending Publication Date: 2025-07-08AULTON NEW ENERGY AUTOMOBILE TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411675094.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Priority Date
2023-12-29
Filing Date
2024-11-21
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

During the traditional UI testing process, each function needs to be tested manually, resulting in inefficient and easy to miss testing some functions.

Method used

Using the UI automation testing method based on the Playwright framework, we simulate the user login page, define page elements and operation functions, use the pytest test framework to execute test tasks, and automate the UI testing of the battery swap program.

Benefits of technology

Improve testing efficiency, ensure that all functions are fully tested, reduce human errors, and improve system stability and regression testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120276970A_ABST
    Figure CN120276970A_ABST
Patent Text Reader

Abstract

The invention discloses a UI automatic test method and device for a power conversion program and a medium, and the method comprises the steps: simulating a login page of a user, and storing a storage state after login as an identity verification certificate; obtaining a page element of a predefined operation page based on the identity verification certificate, and determining an operation function corresponding to the operation page based on the page operation class; based on the page element and the operation function, determining a test task corresponding to page content in the operation page; and based on the pytest test framework and the page operation class, executing a test task corresponding to the operation page of the power conversion program. Based on the provided UI automatic testing method, the interactive operation of an actual interface is simulated through script codes, the complex, tedious and fixed operation step flow is solidified, use case parameterization and result logging are achieved, then regression testing efficiency is improved, system stability is guaranteed, testing efficiency can be effectively improved, and the method is suitable for popularization and application. And the problem that partial functions are easily forgotten to be tested manually is solved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application claims priority from the invention patent application filed with the China National Intellectual Property Administration on December 29, 2023, with the application number 202311865994.9 and the invention title "A UI Automation Testing Method, Device, and Medium for Battery Swapping Procedures". The entire content of the above-mentioned Chinese patent application is incorporated herein by reference. Technical Field

[0002] This application relates to the field of automation testing, and particularly to a UI automation testing method, device, and medium for battery swapping procedures. Background Art

[0003] UI refers to the software interface, which can also be called the UI interface.

[0004] Before a software is launched, it is usually necessary to test the UI interface to ensure the perfection of its functions and logic.

[0005] In the traditional UI testing process, it is usually necessary for developers to manually test each function of the UI interface, which results in low testing efficiency and may cause some functions to be untested due to forgetfulness. Summary of the Invention

[0006] To solve the above problems, this application proposes a UI automation testing method for battery swapping procedures, including:

[0007] Based on the user's trigger, confirm that the user runs the test program, where the test program is implemented based on the Playwright framework;

[0008] Based on the test program, simulate the user's login page and save the storage state after the user logs in as an authentication credential;

[0009] Based on the page operation class, determine the pre-defined page elements and operation functions of the operation page;

[0010] Based on the page elements and the operation functions, trigger the test tasks corresponding to the page content in the operation page, where the page content includes: basic information, vehicle model information, charger information, and expansion compartment information;

[0011] Based on the pytest testing framework, execute the test tasks corresponding to the page operation class.

[0012] This application also proposes a UI automation testing method for battery swapping procedures, including:

[0013] Based on a preset trigger condition, trigger the running of the test program to test the operation page of the battery swapping procedure;

[0014] Among them, the steps of running the test program to test the operation page of the battery swapping program include:

[0015] Simulate the user's login page and save the storage state after login as an authentication credential;

[0016] Obtain the page elements of the predefined operation page based on the authentication credential, and determine the operation functions corresponding to the operation page based on the page operation class;

[0017] Determine the test tasks corresponding to the page content in the operation page based on the page elements and the operation functions;

[0018] Execute the test tasks corresponding to the operation page of the battery swapping program based on the pytest test framework and the page operation class.

[0019] In one example, based on the test program, simulate the user's login page and save the storage state after the user logs in as an authentication credential, specifically including:

[0020] Create a Playwright object, start a browser instance, and set the corresponding browser parameters;

[0021] Create a browser context and create a page object;

[0022] Start the login page, and after the login page is loaded, determine the input box for the login information and fill in the login information;

[0023] Determine the login button, click the login button, and wait for a preset duration to complete the login;

[0024] Convert the storage state of the browser context into a JSON string and assign it to a specified variable;

[0025] Save the specified variable as the authentication credential of the user;

[0026] Close the browser context and close the browser instance.

[0027] In one example, simulate the user's login page and save the storage state after login as an authentication credential, specifically including:

[0028] Start the login page, and after the login page is loaded, determine the input box for the login information in the login page and define the first dictionary corresponding to the login information, where the first dictionary contains the login information;

[0029] Through the user login method corresponding to the first dictionary, simulate the filling of the login information, determine the login button, click the login button, and wait for a preset duration to complete the login;

[0030] Convert the storage state of the predefined browser context into a JSON string, assign the storage state of the browser context to a specified variable, and save the specified variable as the authentication credential;

[0031] Preferably, before starting the login page, the method further includes:

[0032] Define a user management class in the API layer and make the user management class inherit from the base class for network encapsulation; define a user login method to accept specified parameters containing user login information;

[0033] Create a Playwright instance object according to the user management class, start a browser instance, set corresponding browser parameters, and create a browser context and a page object.

[0034] In one example, based on the page operation class, determine the definition and operation functions of the page elements of the operation page, specifically including:

[0035] Determine a page operation class that inherits from the base asset page class, and based on the page operation class, initialize the operation page through the passed-in Page object and locate each page element in the operation page. The page elements include input boxes, dropdown boxes, and operation buttons based on query conditions;

[0036] Among them, define an enter method to enter the battery replacement equipment transformation page in the operation page and locate the page elements in the battery replacement equipment transformation page to implement the page jump function;

[0037] Define a search method to execute a query operation. By locating the input box and dropdown box of the query conditions, filling in the query parameters, and clicking the corresponding query button, implement the search function;

[0038] Define an add method to execute an add operation. By clicking the corresponding add button, enter the add page to implement the project add function.

[0039] In one example, obtain the page elements of the predefined operation page and determine the operation functions corresponding to the operation page based on the page operation class, specifically including:

[0040] Determine a page operation class that inherits from the base asset page class, and based on the page operation class, initialize the operation page through the passed-in Page object;

[0041] Locate each page element in the operation page, where the page elements include but are not limited to at least one of the following: input box based on query conditions, dropdown box, operation button;

[0042] Determine the operation function corresponding to the operation page based on the page operation class. Among them, the steps of determining the operation function corresponding to the operation page based on the page operation class include but are not limited to at least one of the following:

[0043] Define an enter method to enter the battery replacement equipment transformation page in the operation page, and locate the page elements in the battery replacement equipment transformation page to implement the page jump function;

[0044] Define the operate method as a placeholder to implement corresponding specified operations based on requirements;

[0045] Define a search method to perform a query operation. By locating the input box and dropdown box of the query conditions, filling in query parameters, and clicking the corresponding query button, the search function is implemented;

[0046] Define an add method to perform an add operation. By clicking the corresponding add button, enter the add page to implement the project add function.

[0047] In one example, based on the page elements and the operation function, trigger the test task corresponding to the page content in the operation page, specifically including:

[0048] For basic information, generate a process name, which is obtained based on a fixed prefix and a random suffix;

[0049] Determine the corresponding input box through the query conditions, and input the corresponding project name into this input box;

[0050] Determine the corresponding dropdown box through the query conditions, and select the corresponding option as the selected transformation site;

[0051] Determine the corresponding input box through the query conditions, and input the corresponding core content into this input box.

[0052] In one example, the page content includes: basic information; based on the page elements and the operation function, determine the test task corresponding to the page content in the operation page, specifically including:

[0053] Based on the page elements and the operation function, determine the first sub-test task corresponding to the basic information in the page content;

[0054] Among them, the execution process of the first sub-test task includes:

[0055] Generate a process name for the basic information, where the process name is obtained based on a fixed prefix and a random suffix;

[0056] Determine the corresponding input box according to the query condition, and input the corresponding project name into the input box;

[0057] Determine the corresponding dropdown box according to the query condition, and select the corresponding option as the selected transformation site;

[0058] Determine the corresponding input box according to the query condition, and input the corresponding core content into the input box.

[0059] In one example, based on the page element and the operation function, trigger the test task corresponding to the page content in the operation page, specifically including:

[0060] For the vehicle model information, query whether there is a corresponding vehicle model field in the input data;

[0061] If it exists, click the operation button on the operation page for upgrading and compatible vehicle models;

[0062] Loop through each element in the vehicle model field to obtain and display the corresponding vehicle model;

[0063] Click the corresponding vehicle models on the operation page in sequence; among them, if you click the operation button for moving the vehicle model to the right, move the corresponding vehicle model to the right and use it as the selected vehicle model list; if you click the operation button for moving the vehicle model to the left, move the corresponding vehicle model to the left and use it as the to-be-selected vehicle model list.

[0064] In one example, the page content includes: vehicle model information; based on the page element and the operation function, determine the test task corresponding to the page content in the operation page, specifically including:

[0065] Based on the page element and the operation function, determine the second sub-test task corresponding to the vehicle model information in the page content;

[0066] Among them, the execution process of the second sub-test task includes:

[0067] For the vehicle model information, query whether there is a corresponding vehicle model field in the input data;

[0068] If it exists, click the operation button on the operation page for upgrading and compatible vehicle models;

[0069] Loop through each element in the vehicle model field to obtain and display the corresponding vehicle model;

[0070] Click on the corresponding vehicle models on the operation page in sequence; among them, if the operation button for moving the vehicle model to the right is clicked, move the corresponding vehicle model to the right and use it as the selected vehicle model list; if the operation button for moving the vehicle model to the left is clicked, move the corresponding vehicle model to the left and use it as the vehicle models to be selected list.

[0071] In one example, based on the page elements and the operation functions, trigger the test tasks corresponding to the page content in the operation page, specifically including:

[0072] For the charger information or the extended compartment information, query whether there is a corresponding charger field or extended compartment field in the input data;

[0073] If it exists, click the operation button for upgrading the charger or upgrading the extended compartment on the operation page, and click the operation button for adding;

[0074] Fill in the charger information or the extended compartment information in the pop-up box. The charger information and the extended compartment information respectively include: the original value, net value, quantity, and price corresponding to the charger and the extended compartment;

[0075] If there are fields for purchase, internal transfer, external transfer, or reduction in the charger information or the extended compartment information, loop through each element in this field, calculate the total amount based on the quantity and price of the charger or the extended compartment, and fill in the corresponding information into the corresponding form;

[0076] Click the operation button for submission or cancellation to continue adding or stop adding;

[0077] Click the operation button for indicating details or assets, and take screenshots based on requirements.

[0078] In one example, the method further includes:

[0079] Add the original values of the charger and the extended compartment to obtain the original value of the core materials, and add the net values of the charger and the extended compartment to obtain the net value of the core materials;

[0080] Take the opposite numbers of the original value of the core materials and the net value of the core materials to obtain the original value change of the monotonic outbound and the net value change of the monotonic outbound respectively.

[0081] In one example, the page content includes: charger information and extended compartment information; based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page, specifically including:

[0082] Based on the page element and the operation function, determine the third sub-test task corresponding to the charger information and the expansion bin information in the page content;

[0083] Among them, the execution process of the third sub-test task includes:

[0084] For the charger information or the expansion bin information, query whether there is a corresponding charger field or expansion bin field in the input data;

[0085] If it exists, click the operation button for upgrading the charger or upgrading the expansion bin on the operation page, and click the operation button for adding;

[0086] Fill in the charger information or the expansion bin information in the pop-up box, calculate the parameters corresponding to the charger or the expansion bin based on the charger information or the expansion bin information, and fill the calculated parameters into the corresponding form;

[0087] Click the operation button for submitting or canceling to continue adding or stop adding, click the operation button for indicating details or assets, and take screenshots based on requirements;

[0088] Preferably, the charger information and the expansion bin information respectively include: the original value, net value, quantity, and price corresponding to the charger and the expansion bin; calculating the parameters corresponding to the charger or the expansion bin based on the charger information or the expansion bin information includes:

[0089] Add the original values of the charger and the expansion bin to obtain the original value of the core materials, and add the net values of the charger and the expansion bin to obtain the net value of the core materials;

[0090] Take the opposite numbers of the original value of the core materials and the net value of the core materials to obtain the original value change of the monotonic outbound and the net value change of the monotonic outbound respectively;

[0091] And / or, if there are fields for purchase, internal transfer, external transfer, or reduction in the charger information or the expansion bin information, loop through each element in the field, and calculate the total amount based on the quantity and price of the charger or the expansion bin.

[0092] In an example, based on the pytest testing framework, execute the test task corresponding to the page operation class, specifically including:

[0093] Import the pytest testing framework and the page operation class, and define the test case class corresponding to the test task; among them, in the test case class, use the decorator of pytest as a precondition to automatically call and set the scope of action;

[0094] Determine the environmental test function methods included in the test case class, obtain the page instance, assign it to the corresponding page object, create an instance object, and pass the assignment to this instance object;

[0095] Enter the page for the transformation of the battery swapping device;

[0096] In the page for the transformation of the battery swapping device, based on the other test function methods included in the test case class, execute the test tasks corresponding to the page operation class, and call the corresponding function methods to execute the test operations; among them, the other test function methods can skip the test function method or specify the test data through different decorators of pytest.

[0097] In one example, based on the pytest test framework and the page operation class, execute the test tasks corresponding to the operation page of the battery swapping program, specifically including:

[0098] Import the pytest test framework and the page operation class,

[0099] Under the pytest test framework, execute the corresponding test tasks based on the operation functions of the page operation class;

[0100] Define the test case class corresponding to the test tasks; among them, the preconditions in the test case class are the decorators of pytest, which are used to automatically call and set the scope of action;

[0101] Based on the environmental test function methods included in the test case class, obtain the page instance, assign it to the corresponding page object, create an instance object, and pass the assignment to this instance object;

[0102] Enter the page for the transformation of the battery swapping device. In the page for the transformation of the battery swapping device, based on the other test function methods included in the test case class, execute the test tasks corresponding to the page operation class, and call the corresponding function methods to execute the test operations;

[0103] Among them, the other test function methods are used to skip the test function method or specify the test data through different decorators of pytest, and the other test function methods are at least used to test the search function and the project addition function.

[0104] In one example, execute the test tasks corresponding to the page operation class, and call the corresponding function methods to execute the test operations, specifically including:

[0105] Determine the pre-established convention rules, among which, the convention rules include: each yml file corresponds to a single source code module file in the case layer, and each data key value in the yml file corresponds to a single method name in the source code module file;

[0106] Determine the hook function defined in the source code module file, receive the function information included in the class for parameterized calls for dynamically generating test cases through the hook function, and parameterize the function information through custom tags;

[0107] For the case layer, obtain a second dictionary containing the parameterized function information from the yml file, which represents the input data of the test case;

[0108] Pass it to the api layer in the form of the second dictionary through the case layer, so that the api layer uses the specified parameters in the second dictionary to process the audit logic and passes it to the corresponding request library.

[0109] On the other hand, the present application also proposes a UI automation testing device, including:

[0110] At least one processor; and,

[0111] A memory communicatively connected to the at least one processor; wherein,

[0112] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the UI automation testing method as described in any of the above examples.

[0113] On the other hand, the present application also proposes a non-volatile computer storage medium storing computer-executable instructions, and the computer-executable instructions are set as: the UI automation testing method as described in any of the above examples.

[0114] The UI automation testing method for the battery swapping program proposed by the present application can bring the following beneficial effects:

[0115] Based on the proposed UI automation testing method, simulate the interactive operations of the actual interface through script code, solidify the complex and cumbersome fixed operation steps and processes, realize test case parameterization and result logging, thereby improving the regression testing efficiency and ensuring system stability, and can effectively improve the testing efficiency and solve the problem that it is easy for humans to forget to test some functions.

[0116] In the automation testing method, when writing test cases, developers do not need to go into too many details. They only need to add a few lines of code to complete the automation testing process for a search or new function, achieving clear architecture and code decoupling.

[0117] It can automatically identify and associate the files with the same name in the case layer and the data layer, without the need to manually specify the file name, minimizing the errors that occur during configuration, facilitating parameterization, and greatly enhancing the readability and maintainability of the program code.

[0118] During the running process, it can call the built-in inspect function of playwright to gradually view the exceptions and logs during the script running. For relatively complex controls, it can also automatically obtain their positioning methods as references during debugging to achieve breakpoint debugging. Brief Description of the Drawings

[0119] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:

[0120] Figure 1 It is a schematic flowchart of the UI automation test method for the battery swapping program in the embodiment of the present application;

[0121] Figure 2 It is a schematic diagram of the tracking effect in the embodiment of the present application;

[0122] Figure 3 It is a schematic diagram of the effect of a single screenshot in the embodiment of the present application;

[0123] Figure 4 It is a schematic diagram of the effect of the overall screenshot in the embodiment of the present application;

[0124] Figure 5 It is a schematic diagram of the overall effect of the UI automation test method for the battery swapping program in the embodiment of the present application;

[0125] Figure 6 It is in the embodiment of the present application Figure 5 The schematic diagram of the first part of the effect;

[0126] Figure 7 It is in the embodiment of the present application Figure 5 The schematic diagram of the second part of the effect;

[0127] Figure 8 It is a schematic diagram of the inspect function in the embodiment of the present application;

[0128] Figure 9 It is a schematic diagram of the UI automation test device for the battery swapping program in the embodiment of the present application;

[0129] Figure 10 It is a schematic flowchart of the UI automation test method for the battery swapping program in another case in the embodiment of the present application. Detailed Description of the Invention

[0130] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments of this application and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of them. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts belong to the scope of protection of this application.

[0131] The following will detail the technical solutions provided by each embodiment of this application in conjunction with the drawings.

[0132] An embodiment of this application provides a UI automation testing method for the battery swapping program. As Figure 1 shown, the method contains multiple steps and is mainly implemented based on scripts. The script contains code in multiple layers. For example, it can include: the api directory (corresponding to the code of the page layer, encapsulating the element operations of each page and providing methods for the serv layer to call externally), the serv directory (corresponding to the code of the service layer, encapsulating specific common use case steps and providing methods for the case layer to call externally), the case directory (corresponding to the code of the case use case layer, used to write test cases, and can achieve parameterization by associating with the data in the data layer), the data directory (corresponding to the configuration file of the data data layer, used to configure the test parameterized data corresponding to the test cases), the util directory (providing globally shared utility classes), conftest.py (a file provided based on pytest, used to write fixtures for pytest to call), and test.env (configuring the paths and relevant URLs of the project).

[0133] As Figure 1 shown, it includes:

[0134] S101: Based on the trigger of the user, confirm that the user runs the test program, where the test program is implemented based on the Playwright framework.

[0135] As Figure 10 shown, a UI automation testing method for the battery swapping program is provided, including step S1001: Based on a preset trigger condition, trigger the running of the test program to test the operation page of the battery swapping program. The preset trigger condition here can be a user click or selection.

[0136] The battery swapping program refers to a program applied in a battery swapping station, which can control the battery swapping equipment in the battery swapping station. The user mainly refers to R & D testers, and the Playwright framework is an open-source UI automation testing tool.

[0137] After running the test program, a browser will be automatically launched. Meanwhile, as Figure 2 shown, red dots will appear on the page, facilitating the user to visually track the controls in the current operation. After the test program finishes running, it can automatically capture the data on the page and save screenshots, facilitating automated batch processing and subsequent statistics.

[0138] S102: Based on the test program, simulate the user's login page and save the storage state after the user logs in as an authentication credential.

[0139] As Figure 10 shown, in S1001, the steps of running the test program to test the operation page of the battery swapping program include S1002 - S1005.

[0140] Among them, S1002: Simulate the user's login page and save the storage state after logging in as an authentication credential.

[0141] Specifically, before starting the login page, define the user management class in the API layer, and make the user management class (for example, sync_playwright()) inherit from the basic class for network encapsulation (for example, the basic asset page class); define the user login method to accept the specified parameters containing the user login information. At this time, create a Playwright object through sync_playwright() of the user management class, allowing the browser engine to control the browser, start a browser instance through playwright.chromium.launch() (for example, use the Chrome browser), and set the corresponding browser parameters; among them, the browser parameters can include: headless = False means running the browser in a visible mode, slow_mo = 10 means reducing the speed during operation, and channel = 'chrome' means using the Chrome browser.

[0142] Create a browser context through browser.new_context(no_viewport = True) (where no_viewport = True means not creating a browser window, that is, incognito mode) and create a page object through context.new_page().

[0143] Launch the login page through page.goto(). After the login page finishes loading, determine the input boxes for the login information (including: account, password) on the login page through page.get_by_placeholder(), define the first dictionary corresponding to the login information, which contains the login information, and fill in the login information through the fill() method.

[0144] Through the user login method corresponding to the first dictionary, simulate the filling of login information, determine the login button through page.get_by_role(), click the login button through the click() method, and wait for a preset duration through page.wait_for_timeout() (for example, set to 500 milliseconds to give the page some time to complete the login operation), and then complete the login.

[0145] Convert the storage state of the predefined browser context to a JSON string through json.dumps(context.storage_state()), and assign it (that is, the storage state of the browser context) to a specified variable (for example, token). Save the specified variable token as the user's authentication credential through auth_util.set_asset_token(token).

[0146] Close the browser context through context.close(), and close the browser instance through browser.close().

[0147] S103: Based on the page operation class, determine the pre-defined page elements and operation functions of the operation page.

[0148] Similarly, S1003: Obtain the pre-defined page elements of the operation page based on the authentication credential, and determine the operation function corresponding to the operation page based on the page operation class. Among them, the page elements are already defined in the operation page, and the operation function is determined according to the function methods included in the page operation class.

[0149] Specifically, this part corresponds to the code in the page layer, determine the page operation class (such as the EquipmentRemakePage class) that inherits from the basic asset page class (such as the BaseAssetPage class), and based on the page operation class, initialize the operation page through the passed-in Page object, and locate each page element in the operation page. The page elements include but are not limited to at least one of the following: input box based on query conditions, dropdown box, operation button; the query conditions can include: please enter the project name, please enter the creator, which correspond to the input box and are input by the user, and can also include: select the affiliated company, select the approval progress, select the transformation site, select the transformation progress, which correspond to the dropdown box and are selected by the user, and the operation buttons include: query, reset, new, submit, cancel, etc.

[0150] Among them, when determining the operation function, it can include but is not limited to at least one of the following:

[0151] Define the enter method to enter the replacement equipment transformation page in the operation page and locate the page elements in the replacement equipment transformation page to implement the page jump function.

[0152] Define the operate method as a placeholder to implement corresponding specified operations based on requirements.

[0153] Define search to perform a query operation. By locating the input box and dropdown box for query conditions, filling in query parameters, and clicking the corresponding query button, the search function is implemented.

[0154] Define the add method to perform an add operation. By clicking the corresponding add button, enter the add page to implement the project add function.

[0155] S104: Based on the page elements and the operation functions, trigger the test tasks corresponding to the page content in the operation page. The page content includes: basic information, vehicle model information, charger information, and expansion compartment information.

[0156] Similarly, S1004: Based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page.

[0157] Specifically, this part corresponds to the code in the page layer. Here, for different information, the test tasks are divided into multiple sub-test tasks, including at least the first sub-test task, the second sub-test task, and the third sub-test task.

[0158] At this time, based on the page elements and the operation functions, determine the first sub-test task corresponding to the basic information in the page content. The first sub-test task is for the basic information, and the execution process of the first sub-test task includes:

[0159] For the basic information, generate a process name, which is obtained based on a fixed prefix and a random suffix. For example, flow_name.

[0160] Determine the corresponding input box through the query conditions and enter the corresponding project name into this input box. For example, find an input box through the placeholder text "Please enter the project name" of the page element.

[0161] Determine the corresponding dropdown box through the query conditions and select the corresponding option as the selected transformation site. For example, find a dropdown box through the placeholder text "Please select the transformation site" of the page element and click on this list to expand the options. Then, it finds the first option with the specific text xdata['remake_station'] through the page element "listitem" and clicks on this option to indicate the selection of the corresponding transformation site.

[0162] Determine the corresponding input box based on the query conditions, and input the corresponding core content into the input box. For example, find another input box through the placeholder text "Please briefly summarize the core content" of the page element, and fill in the specific description text xdata['remake_desc'] into the input box to represent the input of the corresponding core content.

[0163] Based on the page elements and operation functions, determine the second sub-test task corresponding to the basic information in the page content. The second sub-test task is for vehicle information, and the execution process of the second sub-test task includes:

[0164] For vehicle information, query whether there is a corresponding vehicle field (such as the vehicle field) in the input data.

[0165] If it exists, click the operation button on the operation page for upgrading compatible vehicles, loop through each element in the vehicle field, and obtain and display the corresponding vehicles. At this time, the display is divided into two dialog boxes on the left and right. The left one is the list of vehicles to be selected, and the right one is the list of selected vehicles.

[0166] Based on the requirements, click the corresponding vehicles on the operation page in sequence; among them, if you click the operation button for moving the vehicle to the right, move the corresponding vehicle to the right and use it as the list of selected vehicles; if you click the operation button for moving the vehicle to the left, move the corresponding vehicle to the left and use it as the list of vehicles to be selected.

[0167] Based on the page elements and operation functions, determine the third sub-test task corresponding to the basic information in the page content. The third sub-test task is for charger information and expansion warehouse information, and the execution process of the third sub-test task includes:

[0168] For charger information or expansion warehouse information, query whether there is a corresponding charger field (such as the charger field) or expansion warehouse field (such as the warehouse field) in the input data.

[0169] If it exists, click the operation button for upgrading the charger or upgrading the expansion warehouse on the operation page, and click the operation button for adding.

[0170] Fill in the charger information or expansion warehouse information in the pop-up box, calculate the parameters corresponding to the charger or expansion warehouse based on the charger information or expansion warehouse information, and fill in the calculated parameters into the corresponding form. At this time, the user can click the operation button for submitting or canceling to continue adding or stop adding, click the operation button for indicating details or assets, and take screenshots based on the requirements.

[0171] Among them, the charger information and the expansion bin information respectively include: the original value, net value, quantity, and price corresponding to the charger and the expansion bin, which are filled in by the user based on the actual situation.

[0172] If there are fields for purchase (such as the "buy" field), internal transfer (such as the "inner" field), external transfer (such as the "between" field), or reduction (such as the "minus" field) in the charger information or the expansion bin information, then loop through each element in the field, calculate the total amount based on the quantity and price of the charger or the expansion bin (this part of the information has been obtained in the above information), and fill in the corresponding form with the corresponding information (in addition to the above charger information and expansion bin information, it can also include the calculated total amount).

[0173] At this time, the corresponding task has been completed. The user can click the operation buttons for submission or cancellation to continue adding new tasks or stop adding tasks. Of course, according to the requirements, the user can also click the operation buttons for details or assets and take screenshots based on the requirements. The screenshot effects can be as Figure 3 and Figure 4 shown. Among them, Figure 3 is a schematic diagram of the single screenshot effect, Figure 4 is a schematic diagram of the overall screenshot effect.

[0174] Of course, when calculating the parameters corresponding to the charger or the expansion bin based on the charger information or the expansion bin information and filling in the calculated parameters into the corresponding form, the original values of the charger and the expansion bin can also be added together to obtain the original value of the core materials (mainly including the charger and the expansion bin), and the net values of the charger and the expansion bin can be added together to obtain the net value of the core materials. Take the opposite values of the original value of the core materials and the net value of the core materials to obtain the original value change of the monotonic outbound and the net value change of the monotonic outbound respectively. And take the original value of the core materials, the net value of the core materials, the original value change of the monotonic outbound, and the net value change of the monotonic outbound as relevant information and fill them into the corresponding form.

[0175] In addition, for other scattered materials except the core materials, a similar scheme can also be adopted. After filling in the relevant material information, calculate the relevant information such as the total amount, original value, and net value, fill them into the corresponding form, and take screenshots.

[0176] S105: Based on the pytest test framework, execute the test task corresponding to the page operation class.

[0177] Similarly, S1005: Based on the pytest test framework and the page operation class, execute the test task corresponding to the operation page of the battery swapping procedure.

[0178] Specifically, this part corresponds to the code in the case layer, imports the pytest testing framework and the page operation class. Under the pytest testing framework, corresponding test tasks are executed based on the operation functions of the page operation class. And a test case class corresponding to the test task is defined (for example, the TestEquipmentRemakePage class); among them, in the test case class, the decorator of pytest is used as a precondition to automatically call and set the scope of action. Among them, the autouse parameter of the decorator is set to True, indicating that this precondition will be automatically called before each test function method is executed, and the scope parameter is set to function, indicating that the scope of action of this precondition is each test function method.

[0179] Determine the environmental test function methods included in the test case class (for example, the test_setup function method), obtain the page instance through the fx_page parameter, and assign it to the corresponding page object (for example, self.page), create an instance object (for example, EquipmentRemakePage), and pass the assignment to this instance object.

[0180] Call the self.equipment_remake_page.enter() function method to enter the page for battery swapping equipment transformation. On the page for battery swapping equipment transformation, based on the other test function methods included in the test case class, execute the test tasks corresponding to the page operation class, and call the corresponding function methods (for example, the self.equipment_remake_page function method) to execute the test operations; among them, the other test function methods (the other test function methods are at least used to test the search function and the project addition function) can skip this test function method or specify test data through different decorators of pytest. For example, skip this test function method through the mark.skip decorator. Specify test data through the mark.xdata decorator.

[0181] Furthermore, when executing the test task and calling the corresponding function method to execute the test operation, first determine the pre-established convention rules. Among them, the convention rules include: each yml file corresponds to a single source code module file in the case layer, and each data key value in the yml file corresponds to a single method name in the source code module file.

[0182] Then, determine the hook function defined in the source code module file, receive the function information included in the class for parameterized call used to dynamically generate test cases through the hook function, and parameterize the function information through a custom tag.

[0183] At this time, for the case layer, the second dictionary containing the parameterized function information is obtained from the yml file, which represents the input data of the test case. The case layer passes it to the api layer in the form of the second dictionary, so that the api layer can use the specified parameters in the second dictionary to process the review logic and pass them to the corresponding request library.

[0184] Based on this, the request body obtained by the case layer from the yml file is a complete dictionary (i.e., the second dictionary). If you want to make some modifications, mocks, increment variables, etc. to the request body, you can also modify the values in the dictionary by yourself and then pass it to the api layer in the form of a dictionary. The api layer can pass the second dictionary to the data layer or json file of the third-party library (such as the requests library) used to receive and send http requests, thus making the code more concise.

[0185] In one embodiment, the overall effect display diagram of the test method is as Figure 5 shown, which can display the automated test process and results.

[0186] Among them, as Figure 6 shown, in the automated test method, when writing test cases, developers do not need to go into too many details. They only need to add a few lines of code to complete the automated test process of a search or new function, achieving a clear architecture and decoupled code.

[0187] As Figure 7 shown, it can automatically identify and associate the files with the same name in the case layer and the data layer, without manually specifying the file name, minimizing the errors that occur during configuration, facilitating parameterization, and greatly enhancing the readability and maintainability of the program code.

[0188] In one embodiment, as Figure 8 shown, during the running process, it can call the inspect function provided by playwright to gradually view the exceptions and logs during the script running. For relatively complex controls, it can also automatically obtain their positioning methods as a reference during debugging to achieve breakpoint debugging.

[0189] As Figure 9 shown, the embodiment of the present application also provides a UI automated test device, including:

[0190] At least one processor; and,

[0191] A memory communicatively connected to the at least one processor; wherein,

[0192] The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the UI automation testing method as described in any of the foregoing embodiments.

[0193] An embodiment of the present application further provides a non-volatile computer storage medium storing computer-executable instructions, and the computer-executable instructions are configured to be the UI automation testing method as described in any of the foregoing embodiments.

[0194] The various embodiments in the present application are described in a progressive manner. For the same or similar parts among the various embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the device and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and reference can be made to the corresponding parts of the method embodiments for the relevant parts.

[0195] The device and medium provided by the embodiments of the present application correspond one by one to the method. Therefore, the device and medium also have beneficial technical effects similar to those of the corresponding method. Since the beneficial technical effects of the method have been described in detail above, the beneficial technical effects of the device and medium will not be elaborated here.

[0196] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can be implemented in the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can be implemented in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0197] The present application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, as well as the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate a device for implementing the specified functions in Figure 1 one or more flows or multiple flows and / or blocks Figure 1 one or more blocks or multiple blocks.

[0198] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including an instruction means that implements the functions specified in one or more of the processes and / or blocks Figure 1 in one or more of the processes and / or blocks Figure 1 specified in the block or blocks.

[0199] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, thereby providing steps for implementing the functions specified in one or more of the processes and / or blocks Figure 1 in one or more of the processes and / or blocks Figure 1 specified in the block or blocks.

[0200] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0201] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.

[0202] Computer-readable media includes both permanent and non-permanent, removable and non-removable media implemented by any method or technology for storing information. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile discs (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.

[0203] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, commodity or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising said element.

[0204] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the scope of the claims of the present application.

Claims

1. A UI automated testing method for the battery swapping procedure, characterized in that, Including: Based on a preset trigger condition, trigger the running of a test program to test the operation page of the battery swapping program; Among them, the step of running the test program to test the operation page of the battery swapping program includes: Simulate the user's login page and save the storage state after login as an authentication credential; Based on the authentication credential, obtain the predefined page elements of the operation page, and determine the operation functions corresponding to the operation page based on the page operation class; Based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page; Based on the pytest test framework and the page operation class, execute the test tasks corresponding to the operation page of the battery swapping program.

2. The method according to claim 1, characterized in that, Simulate the user's login page and save the storage state after login as an authentication credential, specifically including: Start the login page, and after the login page is loaded, determine the input box for login information in the login page, and define the first dictionary corresponding to the login information, where the first dictionary contains the login information; Through the user login method corresponding to the first dictionary, simulate the filling of the login information, determine the login button, click the login button, and after waiting for a preset duration, complete the login; Convert the storage state of the predefined browser context into a JSON string, assign the storage state of the browser context to a specified variable, and save the specified variable as the authentication credential; Preferably, before starting the login page, the method further includes: Define the user management class of the API layer, and make the user management class inherit from the base class for network encapsulation; define the user login method to accept the specified parameters containing the user login information; Create a Playwright instance object according to the user management class, start the browser instance, set the corresponding browser parameters, and create the browser context and the page object.

3. The method according to claim 1, wherein Obtain the predefined page elements of the operation page, and determine the operation functions corresponding to the operation page based on the page operation class, specifically including: Determine the page operation class that inherits from the base asset page class, and based on the page operation class, initialize the operation page through the incoming Page object; Locate each page element in the operation page, and the page elements include but are not limited to at least one of the following: input box based on query conditions, dropdown box, operation button; Based on the page operation class, determine the operation functions corresponding to the operation page, where the step of determining the operation functions corresponding to the operation page based on the page operation class includes but is not limited to at least one of the following: Define the enter method to enter the battery swapping equipment transformation page in the operation page, and locate the page elements in the battery swapping equipment transformation page to implement the page jump function; Define the operate method as a placeholder to implement the corresponding specified operation based on the requirements; Define the search method to perform query operations. By locating the input box and dropdown box for the query conditions, filling in the query parameters, and clicking the corresponding query button, the search function is realized; Define the add method to perform addition operations. By clicking the corresponding add button, enter the add page to realize the project addition function.

4. The method according to claim 3, characterized in that, The page content includes: basic information; based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page, specifically including: Based on the page elements and the operation functions, determine the first sub-test task corresponding to the basic information in the page content; Among them, the execution process of the first sub-test task includes: For the basic information, generate a process name, which is obtained based on a fixed prefix and a random suffix; Determine the corresponding input box through the query conditions, and input the corresponding project name into this input box; Determine the corresponding dropdown box through the query conditions, and select the corresponding option as the selected transformation site; Determine the corresponding input box through the query conditions, and input the corresponding core content into this input box.

5. The method according to claim 3, wherein The page content includes: vehicle model information; based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page, specifically including: Based on the page elements and the operation functions, determine the second sub-test task corresponding to the vehicle model information in the page content; Among them, the execution process of the second sub-test task includes: For the vehicle model information, query whether there is a corresponding vehicle model field in the input data; If it exists, click the operation button on the operation page for upgrading and compatible vehicle models; Loop through each element in the vehicle model field to obtain and display the corresponding vehicle models; Click the corresponding vehicle models on the operation page in sequence. Among them, if you click the operation button for moving the vehicle model to the right, move the corresponding vehicle model to the right and use it as the selected vehicle model list; if you click the operation button for moving the vehicle model to the left, move the corresponding vehicle model to the left and use it as the candidate vehicle model list.

6. The method according to claim 3, wherein The page content includes: charger information and expansion compartment information; based on the page elements and the operation functions, determine the test tasks corresponding to the page content in the operation page, specifically including: Based on the page elements and the operation functions, determine the third sub-test task corresponding to the charger information and expansion compartment information in the page content; Among them, the execution process of the third sub-test task includes: For the charger information or expansion compartment information, query whether there is a corresponding charger field or expansion compartment field in the input data; If it exists, click the operation button for upgrading the charger or upgrading the expansion compartment on the operation page, and click the operation button for adding; Fill in the charger information or the expansion compartment information in the pop-up box, calculate the parameters corresponding to the charger or expansion compartment based on the charger information or the expansion compartment information, and fill in the calculated parameters into the corresponding form; Click the operation button for submission or cancellation to continue adding or stop adding, click the operation button for details or assets, and take screenshots based on requirements; Preferably, the charger information and the expansion bin information respectively include: the original value, net value, quantity, and price corresponding to the charger and the expansion bin; calculating the parameters corresponding to the charger or the expansion bin based on the charger information or the expansion bin information includes: Adding the original values of the charger and the expansion bin to obtain the original value of the core materials, and adding the net values of the charger and the expansion bin to obtain the net value of the core materials; Taking the opposite values of the original value of the core materials and the net value of the core materials respectively to obtain the original value change of the monotonic outbound and the net value change of the monotonic outbound; And / or, if there are fields for purchase, internal transfer, external transfer, or reduction in the charger information or the expansion bin information, loop through each element in the field and calculate the total amount based on the quantity and price of the charger or the expansion bin.

7. The method according to claim 3, wherein Based on the pytest test framework and the page operation class, execute the test tasks corresponding to the operation page of the battery swapping program, specifically including: Import the pytest test framework and the page operation class, Under the pytest test framework, execute the corresponding test tasks based on the operation functions of the page operation class; Define the test case class corresponding to the test task; wherein, the precondition in the test case class is a decorator of pytest, which is used to automatically call and set the scope of action; Based on the environment test function method included in the test case class, obtain the page instance, assign it to the corresponding page object, create an instance object, and pass the assignment to the instance object; Enter the battery swapping equipment transformation page. In the battery swapping equipment transformation page, based on the other test function methods included in the test case class, execute the test tasks corresponding to the page operation class, and call the corresponding function methods to execute the test operations; Among them, the other test function methods are used to skip the test function method or specify test data through different decorators of pytest, and the other test function methods are at least used to test the search function and the project addition function.

8. The method according to claim 7, wherein Execute the test tasks corresponding to the page operation class, and call the corresponding function methods to execute the test operations, specifically including: Determine the pre-established convention rules, where the convention rules include: each yml file corresponds to a single source code module file in the case layer, and each data key value in the yml file corresponds to a single method name in the source code module file; Determine the hook function defined in the source code module file, receive the function information included in the class for parameterized call for dynamically generating test cases through the hook function, and parameterize the function information through a custom tag; For the case layer, obtain the second dictionary containing the parameterized function information from the yml file, which represents the input data of the test case; It is passed to the API layer in the form of a second dictionary through the case layer, so that the API layer uses the specified parameters in the second dictionary to process the review logic and passes it to the corresponding request library.

9. A UI automated test device, characterized in that, It includes: At least one processor; And, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor, so that the at least one processor can execute the UI automation testing method described in any one of claims 1 to 8.

10. A non-volatile computer storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are set to: the UI automation testing method described in any one of claims 1 to 8.