Code generation method and device

The test code for test cases is automatically generated through the code generation device, which solves the problem of low efficiency in the existing technology and realizes an efficient automated testing process.

CN120407391APending Publication Date: 2025-08-01HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410157194.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-31
Publication Date
2025-08-01

AI Technical Summary

Technical Problem

In the prior art, the test code for generating test cases is inefficient, the manual writing cycle is long, and the operation is highly repetitive, so it is impossible to efficiently complete the automated test tasks.

Method used

The controls in the tested page are determined through the code generation device, and the prompt corpus corresponding to the control is generated, and the test code is automatically generated based on the prompt corpus, including the control sorting and image segmentation technology, and the test code is automatically generated in combination with the graphic recognition and conversion rules.

Benefits of technology

It significantly improves the development efficiency of test code, shortens the development cycle, and realizes efficient execution of automated tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120407391A_ABST
    Figure CN120407391A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method and device. The code generation method and device are used for improving the efficiency of generating test codes of test cases. The code generation device determines at least one tested control in a tested page corresponding to the test case of the to-be-generated test code; for each tested control, the code generation device generates a prompt corpus corresponding to the tested control according to the control information of the tested control, and the prompt corpus is used for representing a test operation executed when a user tests the tested control based on the test case; the code generation device generates a test code corresponding to the test case according to the prompt corpus corresponding to each tested control, and the test code is used for testing at least one tested control. On the basis, the code generation device can automatically generate the test code corresponding to the test case, the development period of the test code can be shortened, and the development efficiency of the test code is remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technologies, and in particular, to a code generation method and apparatus. Background Art

[0002] With the development of computer software technologies, their complexity and dynamics have been continuously increasing. To ensure the reliable operation of software, software testing is an essential part of the software development life cycle. Generally, the workload of software testing is very large (for example, in the software development cycle, the software testing duration may occupy 40% of the development time, and for some software with very high reliability requirements, the software testing duration may even occupy 60% of the development time). Although the workload of software testing is very large, many operations in the testing process are repetitive, non-intellectual, and non-creative, and accurate and meticulous testing is required. Computers are most suitable for replacing humans to complete such testing tasks. Therefore, automated testing performed by computers has emerged as the times require.

[0003] Automated testing refers to simulating human testing behaviors through computer software to replace human testing execution work. Automated testing exists relative to manual testing and has characteristics such as good operability, repeatability, and high efficiency. During the software testing process, for each test case, automated testing can be implemented by executing the test code of the test case. Currently, the test code of test cases mainly relies on manual writing by humans according to test cases, and the cycle of manually writing the test code of test cases is long and the efficiency is low. Summary of the Invention

[0004] This application provides a code generation method and apparatus to improve the efficiency of generating test code for test cases.

[0005] In a first aspect, an embodiment of this application provides a code generation method, which can be executed by a code generation apparatus. The code generation apparatus determines at least one tested control in a tested page corresponding to a test case for which test code is to be generated; for each tested control, the code generation apparatus generates a prompt corpus corresponding to the tested control according to the control information of the tested control, and the prompt corpus is used to represent the test operation performed by a user when testing the tested control based on the test case; the code generation apparatus generates test code corresponding to the test case according to the prompt corpus corresponding to each tested control, and the test code is used to test at least one tested control.

[0006] In the above manner, the code generation device can determine at least one tested control from the tested page corresponding to the test case, and determine the prompt corpus corresponding to each tested control. Since the prompt corpus represents the test operations performed by the user on the tested control, the code generation device can generate the test code corresponding to the test case based on the prompt corpus corresponding to each tested control, so as to test at least one tested control in the tested page based on the test code corresponding to the test case. Based on this, the code generation device can automatically generate the test code corresponding to the test case, which can shorten the development cycle of the test code and significantly improve the development efficiency of the test code.

[0007] In a possible implementation manner, the code generation device sorts the prompt corpus corresponding to at least one tested control according to the test order corresponding to at least one tested control, and generates a prompt corpus set including the prompt corpus corresponding to at least one tested control; the code generation device generates the test code corresponding to the test case according to the prompt corpus set.

[0008] In the above manner, the code generation device can sort the prompt corpus corresponding to each tested control according to the order of testing the at least one tested control in the test case to obtain a prompt corpus set, and the code generation device automatically generates test code according to the sorted prompt corpus set. Compared with the method of manually writing test code, the development efficiency of the test code can be significantly improved.

[0009] In a possible implementation manner, the code generation device displays a first test configuration page, and the first test configuration page includes multiple page controls extracted from the tested page; the code generation device determines at least one tested control selected by the user from the multiple page controls in response to a control selection operation triggered by the user on the test configuration page.

[0010] In the above manner, the code generation device can determine at least one tested control in the tested page based on the user's selection, so that the user can flexibly select at least one tested control in the tested page corresponding to the test case from the first test configuration page.

[0011] ]In a possible implementation manner, the code generation device displays a second test configuration page, and the second test configuration page includes at least one tested control; the code generation device determines the test order corresponding to at least one tested control in response to a sorting operation triggered by the user on the second test configuration page for at least one tested control.

[0012] In the above manner, the code generation device can determine the test order corresponding to at least one tested control in the tested page based on the user's operation, so that the user can flexibly set the test order corresponding to at least one tested control from the second test configuration page.

[0013] In a possible implementation, the code generation device performs image segmentation on the page under test to determine multiple control areas in the page under test; the code generation device performs graphic and text recognition on each control area to recognize the page controls in each control area, and obtains multiple page controls.

[0014] Through the above method, the code generation device can accurately extract multiple page controls from the page under test based on image segmentation technology and graphic and text recognition technology.

[0015] In a possible implementation, the code generation device determines at least one control indication information included in the test content text of the test case, and the control indication information is used to indicate the corresponding control; the code generation device determines at least one control under test according to the at least one control indication information.

[0016] Through the above method, the code generation device can accurately extract at least one control under test in the page under test from the test content text of the test case.

[0017] In a possible implementation, the code generation device determines the test order corresponding to at least one control under test according to the position of each control indication information in the test content text.

[0018] Through the above method, the code generation device can accurately determine the test order corresponding to at least one control under test from the test content text of the test case.

[0019] In a possible implementation, the control information of the control under test includes the control indication information of the control under test and the control type of the control under test; the code generation device can determine the conversion rule corresponding to the control under test according to the control type of the control under test; according to the control indication information of the control under test and the conversion rule corresponding to the control under test, generate the prompt corpus corresponding to the control under test.

[0020] Through the above method, the code generation device can determine the corresponding conversion rule according to the control type of the control under test, and based on the determined conversion rule and the control indication information of the control under test, accurately generate the prompt corpus corresponding to the control under test.

[0021] In a possible implementation, the code generation device obtains the page display information configured by the user for the control under test in the second test configuration page; the code generation device generates the prompt corpus corresponding to the control under test according to the control indication information of the control under test, the page display information corresponding to the control under test, and the conversion rule corresponding to the control under test.

[0022] In the above manner, the code generation device can accurately generate the prompt corpus corresponding to the measured control according to the page display information of the measured control configured by the user, the conversion rule corresponding to the measured control, and the control indication information of the measured control.

[0023] In a possible implementation manner, the code generation device corrects the test code according to the set code check rules to obtain the executable code corresponding to the test case.

[0024] In a possible implementation manner, the code check rules include keyword check rules corresponding to multiple control types; the code generation device determines the code segment corresponding to each measured control in the test code; for the code segment corresponding to each measured control, the code generation device performs keyword check on the code segment corresponding to the measured control according to the keyword check rules corresponding to the control type of the measured control; if the check result shows that the code segment corresponding to the measured control is abnormal, the code generation device corrects the code segment corresponding to the measured control.

[0025] In the above manner, the code generation device can correct the test code through the keyword check rules and convert the automatically generated test code into executable code.

[0026] In a possible implementation manner, the code check rules include path check rules; for each measured control, the code generation device determines the executable relative path corresponding to the measured control according to the position of the measured control in the measured page; the code generation device corrects the code segment corresponding to the measured control in the test code according to the executable relative path corresponding to the measured control.

[0027] In the above manner, the code generation device can correct the test code through the path check rules and convert the automatically generated test code into executable code.

[0028] In a second aspect, an embodiment of the present application further provides a code generation device, including a determination module, a corpus generation module, and a code generation module; where:

[0029] The determination module is configured to determine at least one measured control in the measured page corresponding to the test case for which the test code is to be generated;

[0030] The corpus generation module is configured to, for each measured control, generate the prompt corpus corresponding to the measured control according to the control information of the measured control, and the prompt corpus is used to represent the test operation performed by the user when testing the measured control based on the test case;

[0031] The code generation module is configured to generate the test code corresponding to the test case according to the prompt corpus corresponding to each measured control, and the test code is used to test at least one measured control.

[0032] In a possible implementation, the code generation module is configured to: sort the prompt corpora corresponding to at least one control under test according to the test order corresponding to the at least one control under test, and generate a prompt corpus set including the prompt corpora corresponding to the at least one control under test; generate test code corresponding to the test case according to the prompt corpus set.

[0033] In a possible implementation, the determination module is configured to: display a first test configuration page, where the first test configuration page includes a plurality of page controls extracted from the page under test; in response to a control selection operation triggered by the user on the test configuration page, determine at least one control under test selected by the user from the plurality of page controls.

[0034] In a possible implementation, the determination module is further configured to: display a second test configuration page, where the second test configuration page includes at least one control under test; in response to a sorting operation triggered by the user on the second test configuration page for the at least one control under test, determine the test order corresponding to the at least one control under test.

[0035] In a possible implementation, the determination module is further configured to: perform image segmentation on the page under test to determine a plurality of control regions in the page under test; perform text and image recognition on each control region to recognize the page controls in each control region, and obtain a plurality of page controls.

[0036] In a possible implementation, the determination module is configured to: determine at least one control indication information included in the test content text of the test case, where the control indication information is used to indicate the corresponding control; determine at least one control under test according to the at least one control indication information.

[0037] In a possible implementation, the determination module is further configured to: determine the test order corresponding to at least one control under test according to the position of each control indication information in the test content text.

[0038] In a possible implementation, the control information of the control under test includes the control indication information of the control under test and the control type of the control under test; the corpus generation module is configured to: determine the conversion rule corresponding to the control under test according to the control type of the control under test; generate the prompt corpus corresponding to the control under test according to the control indication information of the control under test and the conversion rule corresponding to the control under test.

[0039] In a possible implementation, the corpus generation module is configured to: obtain the page display information configured by the user for the control under test on the second test configuration page; generate the prompt corpus corresponding to the control under test according to the control indication information of the control under test, the page display information corresponding to the control under test, and the conversion rule corresponding to the control under test.

[0040] In a possible implementation, the code generation device further includes a code correction module; the code correction module is configured to: correct the test code according to the set code inspection rules to obtain the executable code corresponding to the test case.

[0041] In a possible implementation, the code inspection rules include keyword inspection rules corresponding to multiple control types; the code correction module is configured to: determine the code segment corresponding to each tested control in the test code; for the code segment corresponding to each tested control, perform keyword inspection on the code segment corresponding to the tested control according to the keyword inspection rule corresponding to the control type of the tested control; if the inspection result shows that the code segment corresponding to the tested control is abnormal, correct the code segment corresponding to the tested control.

[0042] In a possible implementation, the code inspection rules include path inspection rules; the code correction module is configured to: for each tested control, determine the executable relative path corresponding to the tested control according to the position of the tested control on the tested page; correct the code segment corresponding to the tested control in the test code according to the executable relative path corresponding to the tested control.

[0043] In a third aspect, an embodiment of the present application further provides a computing device, which has the behavioral functions of the code generation device in the method example of the first aspect described above. The beneficial effects can be seen in the description of the first aspect and will not be elaborated here. The structure of the computing device includes a processor and a memory. The processor is configured to support the computing device to execute the corresponding functions in the first aspect. The memory is coupled to the processor and stores the necessary computer program instructions and data of the computing device. The structure of the computing device further includes a communication interface for communicating with other devices.

[0044] In a fourth aspect, the present application further provides a computer-readable storage medium, in which computer programs or instructions are stored. When it runs on a computer, it causes the computer to execute the methods in the first aspect and all possible implementation manners of the first aspect.

[0045] In a fifth aspect, the present application further provides a computer program product containing instructions. When it runs on a computer, it causes the computer to execute the methods in the first aspect and all possible implementation manners of the first aspect.

[0046] In a sixth aspect, the present application further provides a computer chip. The chip is connected to the memory. The chip is used to read and execute the software program stored in the memory and execute the methods in the first aspect and all possible implementation manners of the first aspect.

[0047] For the various aspects in the second to sixth aspects above and the possible technical effects that each aspect may achieve, please refer to the description of the possible technical effects that can be achieved by the various possible solutions in the first aspect or each aspect above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] Figure 1 A schematic diagram of a test case provided by an embodiment of the present application;

[0049] Figure 2 A schematic diagram of the system architecture of a code generation scheme provided by an embodiment of the present application;

[0050] Figure 3 A schematic diagram of code generation provided by an embodiment of the present application;

[0051] Figure 4 A flowchart of a code generation method provided by an embodiment of the present application;

[0052] Figure 5 A schematic diagram of a page under test provided by an embodiment of the present application;

[0053] Figure 6 A schematic diagram of a page under test provided by an embodiment of the present application;

[0054] Figure 7 A schematic diagram of a first test configuration page provided by an embodiment of the present application;

[0055] Figure 8 A schematic diagram of the pattern of a page control provided by an embodiment of the present application;

[0056] Figure 9 A schematic diagram of the pattern of a page control provided by an embodiment of the present application;

[0057] Figure 10 A schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0058] Figure 11 A schematic diagram of a first test configuration page provided by an embodiment of the present application;

[0059] Figure 12 A schematic diagram of the pattern of a page control provided by an embodiment of the present application;

[0060] Figure 13 A schematic diagram of the pattern of a page control provided by an embodiment of the present application;

[0061] Figure 14 A schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0062] Figure 15Schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0063] Figure 16 Schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0064] Figure 17 Schematic diagram of a control area after image segmentation provided by an embodiment of the present application;

[0065] Figure 18 Schematic diagram of the process of a code generation device extracting page controls from a page under test provided by an embodiment of the present application;

[0066] Figure 19 Schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0067] Figure 20 Schematic diagram of a second test configuration page provided by an embodiment of the present application;

[0068] Figure 21 Schematic diagram of the structure of a code generation device provided by an embodiment of the present application;

[0069] Figure 22 Schematic diagram of the structure of another code generation device provided by an embodiment of the present application;

[0070] Figure 23 Schematic diagram of the structure of a computing device provided by an embodiment of the present application. Detailed implementation manners

[0071] In order to make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below with reference to the accompanying drawings. The terms used in the implementation manners part of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application.

[0072] In the embodiments of the present application, "a plurality of" means two or more. In view of this, in the embodiments of the present application, "a plurality of" can also be understood as "at least two". "At least one" can be understood as one or more, for example, understood as one, two, or more. For example, including at least one means including one, two, or more, and does not limit which ones are included. For example, including at least one of A, B, and C, then what can be included are A, B, C, A and B, A and C, B and C, or A and B and C. "And / or" describes the association relationship of associated objects and indicates that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / ", unless otherwise specified, generally represents an "or" relationship between the associated objects before and after.

[0073] Unless otherwise stated, the ordinal numbers such as "first" and "second" mentioned in the embodiments of this application are used to distinguish multiple objects, and are not used to limit the order, time sequence, priority or importance of multiple objects.

[0074] During the testing process of the application under test in the embodiments of this application, the application under test can be installed on a terminal device, which can run a test system, and the testing process of the application under test is executed through the test system. During the testing process of the application under test through the test system, a common method is that the user can test the application under test according to the test content included in the test case.

[0075] Among them, the process of testing the application under test may include:

[0076] 1. Obtain the test case of the application under test.

[0077] Among them, the test case of the application under test can be a test process pre-written for a test of the application under test, which is a description of the test tasks of this test. The content of the test case includes preconditions, test steps, expected results, etc.

[0078] Exemplarily, as Figure 1 shown in the test case, for example, this test case is used to test the new item function in the main page of the data management platform.

[0079] Among them: the preconditions of this test case may include that the user has the management (editing) permission of the data management platform and has entered the main page.

[0080] The test steps may include:

[0081] a. On the main page, select "New - Item"; the expected result corresponding to this step is: Jump to the new item page.

[0082] b. Fill in all required fields on the new item page and click "OK"; the expected result corresponding to this step is: Save the new item, return to the main page, and the new item can be seen in the item list.

[0083] c. On the new item page, click "Cancel"; the expected result corresponding to this step is: Do not save the new item, return to the main page, and the new item cannot be seen in the item list; and / or, after entering the new item page, cancel the user's management (editing) permission of the data management platform.

[0084] 2. The user triggers a test operation in the running interface of the application under test according to the content of the test case.

[0085] During the testing process of the application under test according to the test cases, the user can trigger test operations in the running interface of the application under test according to the test steps of the test cases. For example, the user can trigger test operations in the running interface of the application under test according to the test steps included in the test cases (for example, if the test steps included in the test case are to select the "New Project" control on the main page, then the user can click the "New Project" control on the main page of the application under test to trigger the test operation).

[0086] 3. In response to the test operation triggered by the user, the application under test executes the control operation corresponding to the test operation.

[0087] During the running process of the application under test, after detecting the test operation triggered by the user in the running interface, it executes the control operation corresponding to the test operation. For example, if the user clicks the "New Project" control on the main page of the application under test, then the application under test responds to the test operation of clicking the "New Project" control, and the running interface of the application under test jumps to the new project page.

[0088] 4. Determine the test result of the application under test.

[0089] Obtain the execution result after the application under test executes the control operation corresponding to the test operation. The obtained execution result can be compared with the expected result included in the test case. If the execution result of the application under test is consistent with the expected result included in the test case, it is determined that the test of this item of the application under test passes; otherwise, it is determined that the test of this item of the application under test fails.

[0090] The above test process of the application under test can be called a manual test process. It can be understood that the user needs to manually trigger test operations according to the test steps included in the test cases, so as to test the application under test according to the test cases.

[0091] Considering that most of the test operations triggered by the user in the manual test process are repetitive, test code can be generated according to the test cases, and the test corresponding to the test case can be executed on the application under test through the test code.

[0092] The system architecture applicable to the code generation solution provided by the embodiments of the present application can be as Figure 2 shown. In this system architecture, it can include a code generation device 10 and at least one terminal device 20. Among them, the code generation device 10 can be used to generate test code corresponding to the test cases, and a test system can run on the terminal device 20. The test system can call the test code corresponding to the test cases generated by the code generation device 10 to test the application under test installed on the terminal device 20.

[0093] Among them, the code generation device 10 is docked with at least one terminal device 20. When the code generation device 10 is implemented by software, the code generation device 10 can be deployed on the terminal device 20, and the test system running on the terminal device 20 can directly call the test code corresponding to the test case generated by the code generation device 10; the code generation device 10 can also be deployed on a computing device outside the terminal device 20 (such as a server or other terminal device), and the computing device can send the test code corresponding to the test case generated by the code generation device 10 to the terminal device 20. When the code generation device 10 is implemented by hardware, the code generation device 10 can send the test code corresponding to the test case to the terminal device 20.

[0094] The code generation device 10 can generate test code corresponding to test cases according to user requirements. As Figure 3 shown in the code generation schematic diagram, the code generation device 10 obtains the user's requirements. For example, the user's requirements may include testing the controls in the page under test of the application under test according to test case A. After the code generation device 10 obtains the user's requirements, it generates the test code corresponding to test case A; during the process of the code generation device 10 generating the test code corresponding to test case A, it can generate the test code corresponding to test case A based on a third-party support system and a professional knowledge base in the test field. For example, the code generation device 10 performs image processing on the page under test corresponding to the test case through a third-party support system and generates test code according to the processing result; or, for example, the code generation device 10 can obtain prompt corpus from the professional knowledge base in the test field during the process of generating the test code corresponding to test case A, and the code generation device 10 generates test code based on the prompt corpus. For the generated test code, the code generation device 10 can allocate a test environment through an environment management platform for exploratory execution to obtain executable test code.

[0095] Here, only for the convenience of description, each device or component is described as an independent device, and in the actual scenario, the specific deployment form of the devices or components in the system is not limited. As Figure 2 shown in the system architecture, the code generation device 10 included can be deployed on at least one terminal device 20, or the code generation device 10 and at least one terminal device 20 can be separately deployed.

[0096] Regarding the form of the code generation device 10, the code generation device 10 can be implemented by software or by hardware. Exemplarily, the implementation manner of the code generation device 10 will be introduced next.

[0097] As an example of a software functional unit, the code generation device 10 may include code running on a computing instance. Among them, the computing instance may be at least one of computing devices such as a physical host (computing device), a virtual machine, a container, etc. Further, the above computing devices may be one or more. For example, the code generation device 10 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the application under test may be distributed in the same region, or may be distributed in different regions. The multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ), or may be distributed in different AZs, and each AZ includes one data center or multiple geographically proximate data centers. Among them, generally one region may include multiple AZs.

[0098] Similarly, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same virtual private cloud (VPC), or may be distributed in multiple VPCs. Among them, generally one VPC is set within one region. For cross-region communication between two VPCs within the same region and between VPCs in different regions, communication gateways need to be set in each VPC, and the interconnection between VPCs is realized through the communication gateways.

[0099] As an example of a hardware functional unit, the code generation device 10 may include at least one computing device, such as a server, etc. Alternatively, the code generation device 10 may also be a device implemented using an application-specific integrated circuit (ASIC), or a programmable logic device (PLD). Among them, the above PLD may be implemented by a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0100] The multiple computing devices included in the code generation device 10 may be distributed in the same region or in different regions. The multiple computing devices included in the code generation device 10 may be distributed in the same availability zone (AZ) or in different AZs. Similarly, the multiple computing devices included in the code generation device 10 may be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Among them, the multiple computing devices may be any combination of computing devices such as servers, application-specific integrated circuits (ASICs), programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), and generic array logic (GALs).

[0101] Based on the problems of long cycle and low efficiency in the current manual writing of test cases for test code, the embodiments of the present application provide a code generation method, which can automatically generate test scripts according to test cases. The test cases of the embodiments of the present application can be used to test the pages of the application under test. For example, functional tests can be performed on the controls in the pages of the application under test. Among them, the application under test may be an application program (APP), and the page of the application under test is the running page after the APP is started; or the application under test may also be a world wide web (web) application, and the page of the application under test is the web page after the web application is started. The following embodiments will elaborate on the script generation method provided by the embodiments of the present application in conjunction with the accompanying drawings.

[0102] The following will be combined with, for example Figure 4 A code generation method provided by the embodiments of the present application will be described. Taking the code generation device generating the test code corresponding to the test case as an example, the method includes the following steps:

[0103] Step 400: The code generation device determines at least one tested control in the tested page corresponding to the test case for which the test code is to be generated.

[0104] First, the code generation device determines the tested page corresponding to the test case for which the test code is to be generated.

[0105] Among them, the tested page corresponding to one test case may include one or more.

[0106] The user can determine the test case for which the test code is to be generated, for example, the test content included in the test case shown Figure 1 as follows. According to the test steps included in the test case, the user can determine the tested page corresponding to the test case.

[0107] For example Figure 1 in the test case shown, if the test steps include "main page" and "new item page", it can be determined that the test case corresponds to two tested pages, namely the "main page" and the "new item page".

[0108] The way for the code generation device to determine the page under test corresponding to the test case for which the test code is to be generated may be to obtain the page image corresponding to the page under test input by the user. For example, according to the test steps included in the test case, the user opens the "main page" and saves the "main page" as a page image; and opens the "new project page" and saves the "new project page" as a page image; the user inputs the saved page images into the code generation device.

[0109] In the embodiments of the present application, the code generation device may provide a configuration interface through which the user can input the page image corresponding to the page under test.

[0110] In addition, the user can also input the address information corresponding to the page under test into the code generation device. For example, when the application under test is a web application, the user can input the uniform resource locator (URL) address of the application under test into the code generation device.

[0111] After the code generation device determines the page under test corresponding to the test case for which the test code is to be generated, the code generation device can determine at least one control under test in the page under test.

[0112] Among them, when the code generation device determines multiple pages under test corresponding to the test case, the code generation device determines the controls under test in each page under test.

[0113] The code generation device can determine at least one control under test in the page under test according to a variety of different methods, which are introduced separately below.

[0114] Determination method of the control under test 1: The code generation device determines at least one control under test in the page under test according to the user's selection.

[0115] The code generation device extracts multiple page controls from the page under test and stores the multiple page controls extracted from the page under test.

[0116] When the code generation device determines multiple pages under test corresponding to the test case, the code generation device extracts page controls from each page under test respectively.

[0117] When the code generation device determines at least one control under test in the page under test, the code generation device displays a first test configuration page, which includes multiple page controls extracted from the page under test; in response to the control selection operation triggered by the user on the first test configuration page, it determines at least one control under test selected by the user from the multiple page controls.

[0118] Among them, at least one control under test selected by the user from multiple page controls can be the control that needs to be tested for the page under test in the test case. For example, if the test case selects "New - Project" for the main page, then at least one control under test selected by the user from multiple page controls includes the "New" selection box control on the main page and the "Project" control in the list corresponding to the "New" selection box control.

[0119] The user can trigger an operation to display the first test configuration page. The code generation device displays the first test configuration page based on multiple page controls extracted from the page under test. The first test configuration page includes multiple page controls on the page under test. The user can select at least one control under test from the multiple page controls included in the first test configuration page. The code generation device displays the second test configuration page, and the second test configuration page includes at least one control under test corresponding to the page under test selected by the user.

[0120] The following uses an example to introduce the method 1 for determining the control under test.

[0121] Taking the test case corresponding to two pages under test as an example, the two pages under test are respectively as Figure 5 and as Figure 6 shown.

[0122] For the main page as Figure 5 shown:

[0123] The code generation device can extract multiple page controls from the page image of the main page input by the user. The multiple page controls can include a "Reset" control, a "Query" control, an "Enter order number" input box control, a "New" selection box control, a "Regional department" selection box control, a "Attention level" selection box control, etc. The first test configuration page generated by the code generation device can be as Figure 7 shown. Among them, the first test configuration page includes multiple page controls, as well as the type and pattern corresponding to each page control; the pattern corresponding to each page control includes Pattern 1 and Pattern 2. Pattern 1 is the image of the page control, and Pattern 2 is the display screen of the page control relative to the page under test. For example, if the page control is a query control, then when the user clicks Pattern 1 in the first test configuration page, the image of the page control as Figure 8 shown can be displayed. When the user clicks Pattern 2 in the first test configuration page, the display screen of the page control relative to the page under test as Figure 9 shown can be displayed.

[0124] After the code generation device displays the first test configuration page on the display interface, the user can select at least one control under test from multiple page controls included in the first test configuration page. The code generation device can display a second test configuration page on the display interface, and the second test configuration page includes at least one control under test corresponding to the page under test selected by the user.

[0125] For example, the user can, according to the test steps included in the test case, such as the test steps being: on the main page, select "New - Project"; then the user can select the "New" selection box control and the "Project" control in the list corresponding to the "New" selection box control from multiple page controls included in the first test configuration page. The code generation device displays the Figure 10 second test configuration page as shown. The second test configuration page includes the controls under test, the type and pattern corresponding to each control under test; the pattern corresponding to each control under test includes Pattern 1 and Pattern 2. Pattern 1 is the image of the control under test, and Pattern 2 is the display screen of the control under test relative to the page under test.

[0126] For the Figure 6 new project page as shown:

[0127] The code generation device can extract multiple page controls from the page image of the new project page input by the user. The multiple page controls can include an "Enter order number" input box control, a "Regional department" selection box control, a "Attention level" selection box control, a "Project name" input box control, a "Classification" selection box control, a "OK" control, a "Cancel" control, etc. The first test configuration page generated by the code generation device can be as shown in Figure 11 . Among them, the first test configuration page includes multiple page controls, and the type and pattern corresponding to each page control; the pattern corresponding to each page control includes Pattern 1 and Pattern 2. Pattern 1 is the image of the page control, and Pattern 2 is the display screen of the page control relative to the page under test. For example, if the page control is the "OK" control, then when the user clicks Pattern 1 on the first test configuration page, the image of the page control as shown in Figure 12 can be displayed. When the user clicks Pattern 2 on the first test configuration page, the display screen of the page control relative to the page under test as shown in Figure 13 can be displayed.

[0128] After the code generation device displays the first test configuration page on the display interface, the user can select at least one control under test from multiple page controls included in the first test configuration page. The code generation device can display a second test configuration page on the display interface, and the second test configuration page includes at least one control under test corresponding to the page under test selected by the user.

[0129] For example, the user can, according to the test steps included in the test case, such as the test steps being: fill in all the required fields on the new item page and click "OK"; then the user can select, from among the multiple page controls included in the first test configuration page, the "Regional Department" selection box control, the "Attention Level" selection box control, the "Project Name" input box control, the "Category" selection box control, the "Scheduled Date" selection box control, the "Project Members" input box control, and the "OK" control. The code generation device displays the second test configuration page as shown in Figure 14 The second test configuration page includes the tested controls, as well as the type and pattern corresponding to each tested control; the pattern corresponding to each tested control includes Pattern 1 and Pattern 2. Pattern 1 is an image of the tested control, and Pattern 2 is the display screen of the tested control relative to the tested page.

[0130] In the embodiment of the present application, after determining at least one tested control in the tested page, the code generation device can also determine the test order corresponding to the at least one tested control.

[0131] Based on the above method by which the code generation device determines at least one tested control according to the user's selection, the code generation device can determine the test order corresponding to the at least one tested control according to the following method:

[0132] Optionally, the code generation device displays the second test configuration page, which includes at least one tested control; in response to the sorting operation triggered by the user on the at least one tested control in the second test configuration page, the code generation device determines the test order corresponding to the at least one tested control.

[0133] When the code generation device determines at least one tested control based on the above-mentioned tested control determination method 1 and displays the second test configuration page, the user can sort the at least one tested control included in the second test configuration page. For example, the user can select the tested control in the second test configuration page and drag the selected tested control to adjust its order among the at least one tested controls; for example, in the second test configuration page as shown in Figure 10 The user can select the "New" selection box control in the second test configuration page and drag it to adjust the order between the "New" selection box control and the "Project" control. Another example is that the second test configuration page can include a moving control for adjusting the order of the tested controls, and the order of the at least one tested control included in the second test configuration page is adjusted based on this moving control; for example, as shown in Figure 15The second test configuration page shown, which includes an "Up" control and a "Down" control in the second test configuration page. The user can select the "Project Name" input box control in the second test configuration page and click the "Up" control to adjust the order between the "Project Name" input box control and the "Attention Degree" selection box control. The adjusted second test configuration page is as Figure 16 shown.

[0134] The code generation device takes the order of at least one measured control included in the second test configuration page as the test order corresponding to the at least one measured control. For example, when the second test configuration page is as Figure 16 shown, the test order corresponding to the at least one measured control is, in sequence: "Regional Department" selection box control, "Project Name" input box control, "Attention Degree" selection box control, "Classification" selection box control, "Planned Date" selection box control, "Project Members" input box control, "OK" control.

[0135] In the above description, the code generation device extracts multiple page controls from the measured page. The following details the way the code generation device extracts page controls from the measured page.

[0136] Optionally, the code generation device performs image segmentation on the measured page to determine multiple control regions in the measured page; the code generation device performs graphic and text recognition on each control region to recognize the page controls in each control region and obtains multiple page controls.

[0137] In the embodiment of the present application, the code generation device can obtain the page image of the measured page input by the user, perform image segmentation on the page image of the measured page, and recognize multiple control regions in the measured page. For example, the code generation device can use the openCV cutting technology to segment the page image of the measured page based on the edge of the page image of the measured page and recognize multiple control regions in the measured page.

[0138] For example, for the measured page as Figure 6 shown, when the code generation device performs image segmentation on the page image of the measured page, it can obtain multiple control regions marked as Figure 17 (marked with a dashed box in Figure 17 ).

[0139] After the code generation device determines multiple control regions in the measured page, it can, based on the trained neural network model and graphic and text recognition technology, recognize the page controls in the control regions; for example, recognizing the page controls in the control regions includes recognizing the name of the page control and the type of the page control.

[0140] In addition, after the code generation device in the embodiment of the present application determines multiple control regions in the page under test, it can also perform duplicate removal and marking processing on the multiple control regions, and then identify the page controls in the control regions based on the trained neural network model. For example, as Figure 18 The process of the code generation device extracting page controls from the page under test shown: 1. The code generation device obtains the page image of the page under test; 2. The code generation device performs image segmentation on the page image of the page under test to obtain multiple control regions; 3. The code generation device performs duplicate removal processing on the multiple control regions segmented from the page image of the page under test; 4. The code generation device performs marking processing on the control regions after duplicate removal processing; 5. The code generation device identifies the page controls in the control regions through the trained neural network model; 6. The code generation device stores the multiple page controls extracted from the page under test.

[0141] In the page under test in the embodiment of the present application, there may also be text description information for some page controls, such as Figure 6 The page under test shown. For the "Regional Department" selection box control, above the "Regional Department" selection box control, there is the regional department, and this regional department is the text description information of the "Regional Department" selection box control. After the code generation device extracts the page controls from the page under test, it can also associate the page controls with the text description information; for example, the code generation device will Figure 6 The "Regional Department" selection box control in the page under test shown is associated with the text "Regional Department".

[0142] Among them, the types of page controls associated with the text description information in the embodiment of the present application may include input box controls, selection box controls (for example, including radio boxes, check boxes, date selection boxes, etc.).

[0143] The following introduces the method of the code generation device associating page controls with text description information in combination with examples:

[0144] Example 1: The code generation device retrieves the text description information closest to the page control in the page under test and associates it with the page control. For example, for the button-type page control in the page under test, retrieve the closest text description information for association.

[0145] Example 2: The code generation device determines the candidate region corresponding to the page control according to the type of the page control, and selects the text description information closest to the page control in the candidate region for association. For example, if the type of the page control is a radio box or a check box, the candidate region corresponding to the page control is on the right side of the page control, and the Y coordinate of the pixel points in the candidate region differs from the Y coordinate of the page control by no more than 10 pixels, and the X coordinate of the pixel points in the candidate region differs from the X coordinate of the page control by no more than 40 pixels.

[0146] Example 3: The code generation device associates the page controls and text description information in the page under test based on the slice association algorithm. For any page control in the page under test, it is possible to detect around the page control to determine whether there is text description information associated with the page control. For example, in the clockwise order, first detect whether there is text description information in the area of the first preset size above the page control. If there are multiple pieces, select the text description information closest to the page control for association; if there is no text description information, detect whether there is text description information in the area of the second preset size to the right of the page control. If there are multiple pieces, select the text description information closest to the page control for association; if there is no text description information, detect whether there is text description information in the area of the third preset size below the page control. If there are multiple pieces, select the text description information closest to the page control for association; if there is no text description information, detect whether there is text description information in the area of the fourth preset size to the left of the page control. If there are multiple pieces, select the text description information closest to the page control for association. Among them, the areas of the first preset size, the second preset size, the third preset size, and the fourth preset size can be the same or different, and the embodiments of the present application do not limit this.

[0147] Determination method of the control under test 2: The code generation device determines at least one control under test in the page under test according to the test content text of the test case.

[0148] Optionally, the code generation device determines at least one control indication information included in the test content text of the test case, and the control indication information is used to indicate the corresponding control; the code generation device determines at least one control under test according to the at least one control indication information.

[0149] The code generation device can obtain the test content text of the test case input by the user, perform text recognition on the test content text, and recognize at least one control indication information included in the test content text; for example, the test content text can include the test steps in the test case, and the control indication information can be the name of the page control. As Figure 1 shown in the test case, the code generation device performs text recognition on the test content text in the test case, such as recognizing the text of the test steps, and the recognized control indication information includes "New", "Project", "OK", "Cancel", then the code generation device determines that at least one control under test includes a "New" control, a "Project" control, an "OK" control, and a "Cancel" control.

[0150] In addition, after the code generation device determines at least one control under test based on the above-mentioned method 2 for determining controls under test, it determines the test order corresponding to at least one control under test according to the position of each control indication information in the test content text.

[0151] For example, the code generation device can determine the test order corresponding to the control under test according to the order in which the control indication information appears in the test content text. As Figure 1 shown in the test case, the control indication information recognized by the code generation device includes "New", "Project", "OK", "Cancel", and as Figure 1 shown in the order in which each control indication information appears in the test content text of the test case, the code generation device determines the test order as: "New" control, "Project" control, "OK" control, "Cancel" control.

[0152] Step 401: For each control under test, the code generation device generates a prompt corpus corresponding to the control under test according to the control information of the control under test.

[0153] Among them, the prompt corpus is used to represent the test operations performed by the user when testing the control under test based on the test case.

[0154] In the embodiments of the present application, the prompt corpus can also be referred to as the prompt corpus.

[0155] The control information of the control under test includes the control indication information of the control under test and the control type of the control under test. For example, the control indication information can be the control name; the control types of the control under test include but are not limited to buttons, input boxes, selection boxes (such as radio boxes, check boxes, date selection boxes, etc.).

[0156] For each control under test, the code generation device can generate a prompt corpus corresponding to the control under test according to the following method:

[0157] The code generation device determines the conversion rule corresponding to the control under test according to the control type of the control under test; the code generation device generates the prompt corpus corresponding to the control under test according to the control indication information of the control under test and the conversion rule corresponding to the control under test.

[0158] In the embodiments of the present application, the conversion rule corresponding to each control type is preset. Among them, the conversion rule can also be referred to as a conversion template, and different conversion modules are preset for different control types.

[0159] In addition, for some or all of the at least one measured control, the user can configure the page display information for this part or all of the measured controls. For example, for an input box measured control, the page display information configured by the user for this measured control can be the content entered by the user in the input box; for another example, for a selection box measured control, the page display information configured by the user for this measured control can be the content selected by the user in the selection box.

[0160] Optionally, the user can configure the page display information for some or all of the at least one measured control on the second test configuration page.

[0161] For example, for a measured control of the input box type, the user can configure the page display information for this input box control on the second test configuration page, and the page display information is the content entered by the user in this input box; as Figure 19 shown, the user can click on the "Project Name" input box control, and the second test configuration page displays the editing window of this measured control. The user can enter the page display information corresponding to this "Project Name" input box control in this editing window.

[0162] For another example, for a measured control of the selection box type, the user can configure the page display information for this selection box control on the second test configuration page, and the page display information is the content selected by the user in this selection box; as Figure 20 shown, the user can click on the "Regional Department" selection box control, and the second test configuration page displays the editing window of this measured control. The user can click on the display list in this editing window and select content from this display list as the page display information corresponding to this selection box control.

[0163] For some or all of the measured controls for which the page display information is configured among the at least one measured control, when the code generation device generates the prompt corpus, the code generation device obtains the page display information configured by the user for the measured control on the second test configuration page, and generates the prompt corpus corresponding to the measured control according to the control indication information of the measured control, the page display information corresponding to the measured control, and the conversion rule corresponding to the measured control.

[0164] For example, for a measured control of the input box type, the corresponding conversion rule can be: click on "xxx", enter "yyy"; where "xxx" represents the control name of this input box control, and "yyy" represents the page display information of this input box (i.e., the content entered by the user in the input box). When generating the prompt corpus corresponding to this input box measured control, obtain the page display information of this input box measured control configured by the user on the second test configuration page, and fill the page display information and control name of this input box measured control into the corresponding fields in the conversion rule to generate the prompt corpus corresponding to this input box measured control.

[0165] For another example, for a test control of the selection box type, the corresponding conversion rule can be: click on "aaa" and select "bbb"; where "aaa" represents the control name of the selection control, and "bbb" represents the page display information of the selection box (i.e., the content selected by the user for the selection box). When generating the prompt corpus corresponding to the test control of the selection box, obtain the page display information of the test control of the selection box configured by the user in the second test configuration page, and fill the page display information and the control name of the test control of the selection box into the corresponding fields in the conversion rule to generate the prompt corpus corresponding to the test control of the selection box.

[0166] For another example, for a test control of the button type, the corresponding conversion rule can be: click on "ccc"; where "ccc" represents the control name of the button control. When generating the prompt corpus corresponding to the test control of the button, fill the control name of the test control of the button into the corresponding field in the conversion rule to generate the prompt corpus corresponding to the test control of the button.

[0167] Step 402: The code generation device generates test code corresponding to the test case according to the prompt corpus corresponding to each test control.

[0168] Among them, the test code generated based on step 402 can be used to test at least one test control in the web page under test. Exemplarily, when testing based on the test case, the test code corresponding to the test case generated by the code generation device according to the embodiments of the present application can perform automated testing on at least one test control in the web page under test corresponding to the test case.

[0169] After the code generation device obtains the prompt corpus corresponding to at least one test control based on the above step 401, the code generation device sorts the prompt corpus corresponding to at least one test control according to the test order corresponding to at least one test control to generate a prompt corpus set including the prompt corpus corresponding to at least one test control; the code generation device generates test code corresponding to the test case according to the prompt corpus set.

[0170] For example, the test case corresponds to two web pages under test, such as Figure 5 the main page shown, and such as Figure 6 the new project page shown. The test controls included in the main page include an "Add" selection box control and an "Item" control in the list corresponding to the "Add" selection box control; the test controls included in the new project page include a "Regional Department" selection box control, a "Attention" selection box control, a "Project Name" input box control, a "Classification" selection box control, a "Planned Date" selection box control, a "Project Members" input box control, and an "OK" control.

[0171] Among them: The prompt corpus corresponding to the "New" selection box control is: Click "New" and select "Project"; the prompt corpus corresponding to the "Regional Department" selection box control is: Click "Regional Department" and select "Region A"; the prompt corpus corresponding to the "Attention" selection box control is: Click "Attention" and select "Important"; the prompt corpus corresponding to the "Project Name" input box control is: Click "Project Name" and enter "Project B"; the prompt corpus corresponding to the "Classification" selection box control is: Click "Classification" and select "Type C"; the prompt corpus corresponding to the "Planned Date" selection box control is: Click "Planned Date" and select "X year X month X day"; the prompt corpus corresponding to the "Project Members" input box control is: Click "Project Members" and enter "Member a, Member b, and Member c"; the prompt corpus corresponding to the "OK" control is: Click "OK".

[0172] The test order for at least one tested control is: "New" selection box control, "Regional Department" selection box control, "Attention" selection box control, "Project Name" input box control, "Classification" selection box control, "Planned Date" selection box control, "Project Members" input box control, "OK" control; then the set of prompt corpus generated by the code generation device is: {Click "New" and select "Project"; Click "Regional Department" and select "Region A"; Click "Attention" and select "Important"; Click "Project Name" and enter "Project B"; Click "Classification" and select "Type C"; Click "Planned Date" and select "X year X month X day"; Click "Planned Date" and select "X year X month X day"; Click "OK"}.

[0173] When the code generation device generates the test code corresponding to the test case according to the set of prompt corpus, the code generation device can input the prompt corpus included in the set of prompt corpus into the code generation model and generate the test code corresponding to the test case based on the code generation model.

[0174] Among them, the code generation model can be a trained network model for generating code; for example, the code generation model can be a large language model, such as the ChatGLM model.

[0175] After the code generation model of the embodiment of the present application calls the code generation model to generate the test code corresponding to the test case, it can also modify the test code.

[0176] Optionally, the code generation model corrects the test code according to the set code inspection rules to obtain the executable code corresponding to the test case.

[0177] Next, according to the specific code inspection rules, the method for correcting the test code is introduced.

[0178] 1. Check the keywords in the test code.

[0179] Among them, the code inspection rules include keyword inspection rules corresponding to multiple control types.

[0180] In the embodiments of the present application, for each control type, the corresponding keyword inspection rules can be configured separately.

[0181] When the code generation device corrects the test code, it determines the code segment corresponding to each tested control in the test code; for the code segment corresponding to each tested control, it performs keyword inspection on the code segment corresponding to the tested control according to the keyword inspection rules corresponding to the control type of the tested control; if the inspection result is that the code segment corresponding to the tested control is abnormal, it corrects the code segment corresponding to the tested control.

[0182] For example, for the control type of the tested control being an input box control, the keyword inspection rules corresponding to the input box control can be: the code segment corresponding to the tested control contains the keywords findElement and sendKeys, and does not contain Chinese variables. After the code generation device obtains the generated test code, for the input box control, it determines the code segment corresponding to the input box control from the test code; it inspects the code segment based on the keyword inspection rules corresponding to the input box control; if the code segment contains the keywords findElement and sendKeys, and does not contain Chinese variables, it can be determined that the code segment corresponding to the input box control in the test code is normal; if the code segment does not contain the keyword findElement, or does not contain the keyword sendKeys, or contains Chinese variables, it can be determined that the code segment corresponding to the input box control in the test code is abnormal, and the code segment is modified; among them, the way to correct the code segment can be, if the abnormal situation is that the code segment does not contain the keyword findElement, or does not contain the keyword sendKeys, add the corresponding keyword in the code segment, and if the abnormal situation is that it contains Chinese variables, delete the Chinese variables in the code segment.

[0183] For another example, when the control type of the control under test is a checkbox control, the keyword inspection rule corresponding to the checkbox control can be: the code snippet corresponding to the control under test contains the keywords findElement, sendKeys, and click. After the code generation device obtains the generated test code, for the checkbox control, it determines the code snippet corresponding to the checkbox control from the test code; checks the code snippet based on the keyword inspection rule corresponding to the checkbox control; if the code snippet contains the keywords findElement, sendKeys, and click, it can be determined that the code snippet corresponding to the checkbox control in the test code is normal; if the code snippet does not contain the keyword findElement, or does not contain the keyword sendKeys, or does not contain the keyword click, it can be determined that the code snippet corresponding to the checkbox control in the test code is abnormal, and the code snippet is modified; wherein, the way to correct the code snippet can be, if the abnormal situation is that the code snippet does not contain the keyword findElement, or does not contain the keyword sendKeys, or does not contain the keyword click, the corresponding keyword is added to the code snippet.

[0184] For another example, when the control type of the control under test is a button control, the keyword inspection rule corresponding to the button control can be: the code snippet corresponding to the control under test contains the keywords findElement and click. After the code generation device obtains the generated test code, for the button control, it determines the code snippet corresponding to the button control from the test code; checks the code snippet based on the keyword inspection rule corresponding to the button control; if the code snippet contains the keywords findElement and click, it can be determined that the code snippet corresponding to the button control in the test code is normal; if the code snippet does not contain the keyword findElement, or does not contain the keyword click, it can be determined that the code snippet corresponding to the button control in the test code is abnormal, and the code snippet is modified; wherein, the way to correct the code snippet can be, if the abnormal situation is that the code snippet does not contain the keyword findElement or does not contain the keyword click, the corresponding keyword is added to the code snippet.

[0185] 2. Perform path inspection on the test code.

[0186] Among them, the code inspection rules include path inspection rules.

[0187] When the code generation device corrects the test code, it corrects the test code according to the path inspection rules.

[0188] Optionally, for each control under test, the code generation device determines the executable relative path corresponding to the control under test according to the position of the control under test in the page under test; and corrects the code segment corresponding to the control under test in the test code according to the executable relative path corresponding to the control under test.

[0189] In the embodiments of the present application, the position of the control under test in the page under test may be the coordinate information of the control under test in the page under test.

[0190] For each control under test, when the code generation device determines the position of the control under test in the page under test, it may explore and confirm the coordinate information of the control under test in the page under test from the page under test according to the coordinate information of the control under test obtained when performing image segmentation on the page image of the page under test.

[0191] The executable relative path corresponding to the control under test determined by the code generation device according to the position of the control under test in the page under test may be an xpath path; and the code segment corresponding to the control under test in the test code is replaced based on the xpath path corresponding to the control under test.

[0192] The code generation device in the embodiments of the present application may correct the test code corresponding to the generated test case based on at least one of the above code detection rules to obtain executable code. The executable code obtained by the code generation device may be used for automated testing of the web page under test of the application under test.

[0193] Combined with the above method embodiments, the embodiments of the present application further provide a code generation device. In some embodiments, as Figure 21 shown, the code generation device may include a determination module 2101, a corpus generation module 2102, and a code generation module 2103. The determination module 2101, the corpus generation module 2102, and the code generation module 2103 may cooperate to perform the functions of the code generation device in the above method embodiments.

[0194] Optionally, as Figure 22 shown, the code generation device may further include a code correction module 2104, where the code correction module 2104 may cooperate with the determination module 2101, the corpus generation module 2102, and the code generation module 2103 to perform the functions of the code generation device in the above method embodiments.

[0195] The present application further provides a computing device 2300. As Figure 23As shown, the computing device 2300 can be used to implement the functions of the code generation device in the above embodiments, including: a bus 2301, a processor 2302, a memory 2303, and a communication interface 2304. The processor 2302, the memory 2303, and the communication interface 2304 communicate with each other through the bus 2301. The computing device 2300 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 2300.

[0196] The bus 2301 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 23 only one line is shown in the figure, but it does not mean that there is only one bus or one type of bus. The bus 2301 can include a path for transmitting information between various components of the computing device 2300 (for example, the memory 2303, the processor 2302, and the communication interface 2304).

[0197] The processor 2302 can include any one or more of a CPU, a Graphics Processing Unit (GPU), a Micro Processor (MP), or a Digital Signal Processor (DSP), etc.

[0198] The memory 2303 can include a volatile memory, such as a Random Access Memory (RAM). The processor 2302 can also include a non-volatile memory, such as a Read-Only Memory (ROM), a flash memory, a Hard Disk Drive (HDD), or a Solid State Drive (SSD).

[0199] The memory 2303 stores executable program codes, and the processor 2302 executes the executable program codes to respectively implement the functions of the foregoing determination module 2101, corpus generation module 2102, and code generation module 2103, thereby implementing the code generation method. That is, instructions for executing the code generation method are stored on the memory 2303.

[0200] The communication interface 2304 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 2300 and other devices or communication networks.

[0201] Embodiments of the present application also provide a computer program product containing instructions. The computer program product can be software or a program product containing instructions that can run on a computing device or be stored in any available medium. When the computer program product runs on at least one computer, it causes at least one computer to execute the code generation method.

[0202] Embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive), etc. The computer-readable storage medium includes instructions that direct a computer to execute the code generation method.

[0203] 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 take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take 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.

[0204] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of flows and / or blocks in the flowcharts and / or block diagrams, 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, such that the instructions executed by the processor of the computer or other programmable data processing devices generate a means for implementing the specified functions in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0205] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing devices to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including an instruction means, and the instruction means implements the specified functions in the process Figure 1One or more processes and / or blocks Figure 1 The functions specified in one or more blocks.

[0206] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one Figure 1 One or more processes and / or blocks Figure 1 The steps of the functions specified in one or more blocks.

[0207] Obviously, those skilled in the art can make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these changes and modifications.

Claims

1. A code generation method, characterized in that, The method includes: Determining at least one tested control in a tested page corresponding to a test case for which test code is to be generated; For each of the at least one tested control, generating prompt corpus corresponding to the tested control according to the control information of the tested control, where the prompt corpus is used to represent test operations performed by a user when testing the tested control based on the test case; Generating test code corresponding to the test case according to the prompt corpus corresponding to each of the at least one tested control, where the test code is used to test the at least one tested control.

2. The method according to claim 1, characterized in that The generating test code corresponding to the test case according to the prompt corpus corresponding to each of the at least one tested control includes: Sorting the prompt corpus corresponding to the at least one tested control according to the test order corresponding to the at least one tested control to generate a prompt corpus set including the prompt corpus corresponding to the at least one tested control; Generating test code corresponding to the test case according to the prompt corpus set.

3. The method according to claim 1 or 2, characterized in that, The determining at least one tested control in a tested page corresponding to a test case for which test code is to be generated includes: Displaying a first test configuration page, where the first test configuration page includes a plurality of page controls extracted from the tested page; Responding to a control selection operation triggered by the user on the test configuration page, and determining the at least one tested control selected by the user from the plurality of page controls.

4. The method according to claim 2, characterized in that The method further includes: Displaying a second test configuration page, where the second test configuration page includes the at least one tested control; Responding to a sorting operation triggered by the user on the second test configuration page for the at least one tested control, and determining the test order corresponding to the at least one tested control.

5. The method according to claim 3, wherein The method further includes: Performing image segmentation on the tested page to determine a plurality of control regions in the tested page; Performing text and image recognition on each of the control regions to recognize the page controls in each of the control regions, and obtaining the plurality of page controls.

6. The method according to claim 2, wherein The determining at least one tested control in a tested page corresponding to a test case for which test code is to be generated includes: Determining at least one control indication information included in the test content text of the test case, where the control indication information is used to indicate a corresponding control; Determining the at least one tested control according to the at least one control indication information.

7. The method according to claim 6, wherein The method further includes: Determining the test order corresponding to the at least one tested control according to the position of each of the control indication information in the test content text.

8. The method according to any one of claims 1 to 7, characterized in that, The control information of the tested control includes the control indication information of the tested control and the control type of the tested control; The generating prompt corpus corresponding to the tested control according to the control information of the tested control includes: Determining a conversion rule corresponding to the tested control according to the control type of the tested control; Generating prompt corpus corresponding to the tested control according to the control indication information of the tested control and the conversion rule corresponding to the tested control.

9. The method according to claim 8, wherein Generating the prompt corpus corresponding to the control under test according to the control indication information of the control under test and the conversion rule corresponding to the control under test includes: Obtaining the page display information configured by the user for the control under test on the second test configuration page; Generating the prompt corpus corresponding to the control under test according to the control indication information of the control under test, the page display information corresponding to the control under test, and the conversion rule corresponding to the control under test.

10. The method according to any one of claims 1 to 9, characterized in that, The method further includes: Correcting the test code according to the set code inspection rules to obtain the executable code corresponding to the test case.

11. The method according to claim 10, wherein The code inspection rules include keyword inspection rules corresponding to multiple control types; Correcting the test code according to the set code inspection rules includes: Determining the code segment corresponding to each control under test in the test code; For the code segment corresponding to each control under test, performing keyword inspection on the code segment corresponding to the control under test according to the keyword inspection rule corresponding to the control type of the control under test; If the inspection result shows that the code segment corresponding to the control under test is abnormal, correcting the code segment corresponding to the control under test.

12. The method according to claim 10 or 11, characterized in that, The code inspection rules include path inspection rules; Correcting the test code according to the set code inspection rules includes: For each control under test, determining the executable relative path corresponding to the control under test according to the position of the control under test in the page under test; and correcting the code segment corresponding to the control under test in the test code according to the executable relative path corresponding to the control under test.

13. A code generation device, characterized in that, The device includes a module for executing the method according to any one of claims 1 to 12.

14. A computing device, characterized in that, The computing device includes a processor and a memory; The processor is configured to execute the instructions stored in the memory so that the computing device executes the method according to any one of claims 1 to 12.

15. A computer-readable storage medium, characterized in that, A computer program or instruction is stored in the storage medium, and when the computer program or instruction is executed by a computer, the method according to any one of claims 1 to 12 is implemented.

16. A computer program product, characterized in that, When the computer program product runs on a computer, the computer is caused to execute the method according to any one of claims 1 to 12.