Screenshot-based test case and test script generation method, system and medium

Through the mapping relationship between screenshot recording and JSON files, automated test scripts are automatically generated, which solves the problems of resource waste and coverage verification in traditional testing methods, and improves the efficiency and credibility of agile testing.

CN114416516BActive Publication Date: 2024-09-13INSPUR QILU SOFTWARE IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111410835.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-25
Publication Date
2024-09-13
Estimated Expiration
2041-11-25

AI Technical Summary

Technical Problem

In agile testing, traditional automated testing methods require use case managers to design test cases and automation specialists to develop automated scripts, resulting in waste of resources and difficulty in verifying coverage.

Method used

Record operation events through screenshots, generate operation files in JSON format, and automatically generate automated test scripts through the mapping relationship between database storage components and operation events.

Benefits of technology

It is possible to write test cases through pictures and automatically generate automated scripts, which reduces development difficulty, improves work efficiency, reduces test omissions, and enhances the credibility of automated test results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114416516B
    Figure CN114416516B
Patent Text Reader

Abstract

The invention discloses a test case and test script generation method, system and medium based on screenshots, belongs to the technical field of test case generation, and the technical problem to be solved is how to write test cases through pictures and automatically generate automated scripts according to the picture test cases. It includes the following steps: for each step of the test case, a script execution statement is configured for each operation event in the step and the corresponding component is encapsulated; for each step of the test case, an operation file corresponding to each operation event is recorded through a web page, an operation file in JSON format is constructed based on the screenshot image and the operation attribute, and a mapping relationship between components, operation events, and operation files is stored in a database; based on the mapping relationship between components, operation events, and operation files, the components and operation files are matched, and the operation files are replaced in the script execution statement to obtain a test script in the form of a string.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of test case generation, and in particular to a test case and test script generation method, system and medium based on screenshots. Background Art

[0002] In the process of agile testing, the need for rapid iteration is very obvious. In order to improve testing efficiency, we often use automated testing. However, in agile testing, the traditional automated testing method usually requires the use case manager to design the test case, and the automation specialist to develop the automation script according to the test case because it takes a certain amount of time to develop the automated test script. However, the logic and steps of the test case and the test script are the same, except that one is a natural language and the other is a script language. Writing twice will cause a certain amount of resource waste. At the same time, in the agile testing mode, the responsibilities of the use case manager and the automation specialist are separated, that is, the use case manager is responsible for designing the test case, and the automation specialist is responsible for developing the automated test script. Whether the test script written by the automation specialist completely covers the test case cannot be known through the running results, but can only be known through manual review or statistics.

[0003] Based on the above problems, the technical problem to be solved by the present invention is how to write test cases through pictures and automatically generate automation scripts based on the picture test cases. Summary of the invention

[0004] The technical task of the present invention is to address the above shortcomings and provide a screenshot-based test case and test script generation method, system and medium to solve the technical problem of how to write test cases through pictures and automatically generate automated scripts based on the picture test cases.

[0005] In a first aspect, the screenshot-based test case and test script generation method of the present invention is applied to a test case generation system including a remote real machine platform, a database and a mobile phone, wherein the remote real machine provides a web page and a mouse, and the generation method includes the following steps:

[0006] For each step of the test case, configure a script execution statement for each operation event in the step and encapsulate the corresponding component, store the preset component in a database, and store the mapping relationship between the component and the operation event in the database;

[0007] For each step of the test case, the operation file corresponding to each operation event is recorded through the web page. For each operation event, the corresponding mouse click event is monitored, and a corresponding screenshot image is formed for the mouse click area on the web page. The operation event is attributed and the operation attributes are obtained through the web page. The operation file in JSON format is constructed based on the screenshot image and the operation attributes, and the mapping relationship between the component, operation event, and operation file is stored in the database;

[0008] After the operation files related to all steps in the test case are recorded, the components and operation files will be matched based on the mapping relationship between components, operation events, and operation files, and the operation files will be replaced in the script execution statement to obtain the test script in string form, and the test script will be displayed through the remote real machine platform.

[0009] Preferably, recording the operation file of each operation event in the steps through a web page includes the following steps:

[0010] Monitor mouse click events by monitoring events;

[0011] Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned;

[0012] The page service provided by the web page configures the attributes of the operation event, including the configuration attribute name and related operation parameters, to obtain the corresponding operation attributes;

[0013] Construct an operation file in JSON format based on the operation name, picture ID and operation parameters, in which the picture ID is recorded as a picture attribute, and a mapping relationship between the component, operation event, picture ID and operation parameters is stored in a database, with the operation name as the keyword;

[0014] After the operation files related to all steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

[0015] Preferably, before monitoring the mouse click event, a picture mode is selected through a page service provided by the web page, and the picture mode includes a real mobile phone screen mode and a UI picture mode.

[0016] Preferably, when monitoring the corresponding mouse click event and forming a corresponding screenshot image for the mouse click area on the web page, two modes are included, namely:

[0017] Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page;

[0018] Mode 2: When the right button of the mouse is clicked to execute a mouse click event, the corresponding operation event type is other events. Based on the click area of ​​the mouse, a screenshot frame centered on the click point is formed on the web page, and a screenshot image of a desired size is formed by selecting the desired area through the screenshot frame; the other events include input, wait, scroll, screenshot, search, slide and assert;

[0019] After selecting the required area through the screenshot box to form a screenshot image of the required size, the properties of the operation event are configured through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering relevant parameters of the operation event through the input box.

[0020] Preferably, for the generated test script, a modified new test script is regenerated by modifying the image or sequential logic;

[0021] Modify the image or sequence logic by the following methods:

[0022] Record the operation file of the operation event to be modified through the web page to obtain a new operation file;

[0023] The new operation file is stored through the remote real machine platform, and the mapping relationship between the component, the operation event, and the new operation file is stored through the database;

[0024] The new operation file is replaced into the script execution statement to obtain a new test script in the form of a string, and the test script is displayed through the remote real machine platform.

[0025] Preferably, the test case is executed by the following method:

[0026] Get real-time screenshots of the mobile phone through the mobile agent node;

[0027] Through the image comparison function of opencv, find the coordinates of the corresponding screenshot in the test script in the real-time screenshot to locate the operation;

[0028] Execute the corresponding test case to perform event operations.

[0029] Preferably, before obtaining the real-time screenshot of the mobile phone through the mobile terminal agent node, the resolution of the mobile phone screen is collected as the real-time resolution, the screenshot in the test script is used as the source image, the resolution of the source image is used as the standard resolution, and the ratio of the real-time resolution to the standard resolution is calculated;

[0030] After obtaining the real-time screenshot of the mobile phone through the mobile agent node, the resolution of the real-time screenshot is converted based on the ratio of the real-time resolution to the standard resolution, so that the resolution of the converted real-time screen image is adapted to the standard resolution.

[0031] In a second aspect, a screenshot-based test case and test script generation system of the present invention is used to execute the screenshot-based test case and test script generation method as described in any one of the first aspects, and the generation system includes:

[0032] A mobile phone, wherein the mobile phone is at least one, and the at least one mobile phone constitutes a device pool;

[0033] A database, wherein the database is used for storage;

[0034] A remote real machine platform, which remotely interacts with the mobile phone and the database to perform the following operations:

[0035] For each step of the test case, configure a script execution statement for each operation event in the step and encapsulate the corresponding component; store the preset component in a database, and store the mapping relationship between the component and the operation event through the database;

[0036] For each step of each test case, the operation file corresponding to each operation event is recorded through the web page. For each operation event, the corresponding mouse click event is monitored, and a corresponding screenshot image is formed for the mouse click area on the web page. The operation event corresponding to the mouse click event is configured with attributes through the web page to obtain the operation attributes, and the operation file in JSON format is constructed based on the screenshot image and the operation attributes.

[0037] After all the operation files related to the steps in the test case are recorded, the components and operation files are matched based on the mapping relationship between the components, operation events, and operation files, and the operation files are replaced into the script execution statements to obtain the test script in string form, and the test script is displayed;

[0038] For the generated test script, regenerate the modified new test script by modifying the image or sequential logic;

[0039] The components and the mapping relationship between the components, operation events and operation files are all stored in the database;

[0040] Before monitoring the mouse click event, the remote real machine platform is also used to select a picture mode through a page service provided by a web page, wherein the picture mode includes a mobile phone real machine screen mode and a UI picture mode;

[0041] In the remote real machine platform, when a web page forms a corresponding screenshot image for the mouse click area, there are two modes, namely:

[0042] Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page;

[0043] Mode 2: When the right button of the mouse is clicked to execute a mouse click event, the corresponding operation event type is other events. Based on the click area of ​​the mouse, a screenshot frame centered on the click point is formed on the web page, and a screenshot image of a desired size is formed by selecting the desired area through the screenshot frame; the other events include input, wait, scroll, screenshot, search, slide and assert; after the desired area is selected through the screenshot frame to form a screenshot image of a desired size, the operation event is configured with properties through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering relevant parameters of the operation event through the input box;

[0044] The remote real machine platform is used to modify images or sequential logic by the following methods:

[0045] Record the operation file of the operation event to be modified through the web page to obtain a new operation file;

[0046] The new operation file is stored through the remote real machine platform, and the mapping relationship between the component, the operation event, and the new operation file is stored through the database;

[0047] The new operation file is replaced into the script execution statement to obtain a new test script in the form of a string, and the test script is displayed through the remote real machine platform.

[0048] Preferably, the remote real machine platform records the operation file of each operation event in the step through a web page, including the following steps:

[0049] Monitor the mouse click event corresponding to the operation event by using the event monitoring method;

[0050] Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned;

[0051] Performing attribute configuration for the operation event through a page service provided by a web page, including selecting an operation name and inputting operation parameters to obtain operation attributes corresponding to the operation event;

[0052] The operation file in JSON format is formed based on the operation name, the picture ID and the operation parameters, the corresponding picture ID is recorded in the operation file in the form of picture attributes, and the mapping relationship between the component, the operation event, the picture ID and the operation parameter is stored in the database, and the mapping relationship uses the operation name as the keyword;

[0053] After the operation files related to all steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

[0054] In a third aspect, the medium of the present invention is a computer-readable medium, on which computer instructions are stored. When the computer instructions are executed by a processor, the processor executes the method as described in any one of the first aspects.

[0055] The screenshot-based test case and test script generation method, system and medium of the present invention have the following advantages:

[0056] 1. Based on the operation attributes of the screenshot configuration, an operation file is formed, and the operation file is replaced into the execution script statement to generate a test script. The screenshot operation makes the operation convenient and simple, reducing the development difficulty;

[0057] 2. The recorded script can also be used to generate readable traditional test cases through the use case generator, which is convenient for viewing. It breaks the original use case to script and converts it into recording to use case, so that one-time recording can be used in multiple places, and the three-way linkage of JSON recording record-Python automation script-test case is realized;

[0058] 3. Graphical test cases and automated test scripts can be generated, which reduces some workload and improves work efficiency. In addition, graphical test cases are more convenient and intuitive, and there is no need to view prototype diagrams when performing manual tests or automated tests;

[0059] 3. No need to wait for the function development to be completed. You can start writing automated test scripts when the UI diagram is completed. After the function development is completed, the script debugging and running can be carried out immediately, which reduces the waiting time between each link and truly realizes the left shift of testing work;

[0060] 4. The test cases set up by use case designers have clear logic and comprehensive coverage. After the use cases are reviewed by multiple people including product developers and R&D personnel, test omissions can be minimized. The quality of the automated test scripts generated in this way is relatively reliable, which improves the credibility of the automated test results. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0062] The present invention is further described below in conjunction with the accompanying drawings.

[0063] Figure 1 This is a flowchart of a method for generating test cases and test scripts based on screenshots in Example 1;

[0064] Figure 2 A schematic diagram showing a screenshot box appearing when double-clicking a device interface in the test case and test script generation method based on screenshots in Example 1;

[0065] Figure 3 A schematic diagram of right-clicking on a screenshot frame and selecting a required operation in the method for generating a test case and a test script based on screenshots in Example 1;

[0066] Figure 4 This is a schematic diagram of the top operation bar in the test case and test script generation method based on screenshots in Example 1;

[0067] Figure 5 A schematic diagram of an input prompt of existence or non-existence appearing in the if condition input box in the test case and test script generation method based on screenshots in Example 1;

[0068] Figure 6 This is a schematic diagram of the pop-up of all installation package names installed on the device when the start app input box is selected in the test case and test script generation method based on screenshots in Example 1;

[0069] Figure 7 A custom schematic diagram of a common method area in a test case and test script generation method based on screenshots in Example 1;

[0070] Figure 8 It is a schematic diagram of recording information in script recording in the test case and test script generation method based on screenshots in Example 1;

[0071] Fig. 9A schematic diagram of recording information indentation in the test case and test script generation method based on screenshots in Example 1;

[0072] Fig.10 This is a schematic diagram of information dragged in the test case and test script generation method based on screenshots in Example 1;

[0073] Fig.11 This is a schematic diagram of a waiting queue for public methods that can be temporarily stored in a test case information area in a test case and test script generation method based on screenshots in Example 1;

[0074] Fig.12 This is a schematic diagram of introducing a use case information area in the test case and test script generation method based on screenshots in Example 1. DETAILED DESCRIPTION

[0075] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.

[0076] The embodiments of the present invention provide a method, system and medium for generating test cases and test scripts based on screenshots, which are used to solve the technical problem of how to write test cases through pictures and automatically generate automation scripts according to the picture test cases.

[0077] Embodiment 1:

[0078] The test case and test script generation method based on screenshots of the present invention is applied to a test case generation system including a remote real machine platform, a database and a mobile phone. The remote real machine provides a web page and a mouse. The generation method includes the following steps:

[0079] S100, for each step of the test case, configure a script execution statement for each operation event in the step and encapsulate it to obtain a corresponding component, store the component in a database, and store a mapping relationship between the component and the operation event in the database;

[0080] S200, for each step of the test case, record the operation file corresponding to each operation event through the web page, for each operation event, listen to the corresponding mouse click event, form a corresponding screenshot image of the mouse click area on the web page, and configure the attributes of the operation event through the web page to obtain the operation attributes, construct an operation file in JSON format based on the screenshot image and the operation attributes, and store the mapping relationship between the component, the operation event, and the operation file through the database;

[0081] S300. After the operation files related to all steps in the test case are recorded, the components and operation files will be matched based on the mapping relationship between components, operation events, and operation files, and the operation files will be replaced into the script execution statements to obtain the test script in string form, and the test script will be displayed through the remote real machine platform.

[0082] In this embodiment, recording the operation file of each operation event in the step through a web page in step S200 includes the following steps:

[0083] (1) Monitor mouse click events by monitoring events;

[0084] (2) Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned;

[0085] (3) Attribute configuration of the operation event is performed through the page service provided by the web page, including configuration attribute name and related operation parameters, to obtain the corresponding operation attribute;

[0086] (4) constructing an operation file in JSON format based on the image ID and operation parameters, wherein the image ID is recorded in the operation file as an image attribute, and a mapping relationship between the component, operation event, image ID, and operation parameter is stored in a database, wherein the mapping relationship uses the operation name as a keyword;

[0087] (5) After all the operation files related to the steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and the corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

[0088] In the above steps, recording is performed through the web page of the remote real machine. Before recording, it is necessary to select the picture mode through the page service provided by the web page. The picture mode includes the mobile phone real machine screen mode and the UI picture mode. That is, during execution, there are two modes on the page service for users to choose, which are to let users choose the real machine mode or the picture mode. The real machine mode is to select an idle device in the device pool for connection, and the picture mode requires uploading the required pictures to the web page for users to take screenshots. After the selection is completed, the uploaded picture or the current screen picture of the real machine will be displayed on the browser page.

[0089] In this embodiment, when the corresponding mouse click event is monitored and a corresponding screenshot image is formed on the web page for the mouse click area, two modes are included, namely:

[0090] Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page;

[0091] Mode 2: When the right button of the mouse is clicked to execute a mouse click event, the corresponding operation event type is other events. Based on the click area of ​​the mouse, a screenshot frame centered on the click point is formed on the web page, and the desired area is selected through the screenshot frame to form a screenshot image of the desired size; the other events referred to in this embodiment include input, waiting, scrolling, screenshot, search, sliding and assertion; after the desired area is selected through the screenshot frame to form a screenshot image of the desired size, the operation event is configured with properties through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering relevant parameters of the operation event through the input box.

[0092] That is, when executing the program, click on the UI image displayed on the web page or the area of ​​the real-time screen of the real machine to start recording. In the front-end js code, the event monitoring method is used to monitor the mouse click event. The recording will automatically record the left-click operation event. When the left mouse button is clicked, a square screenshot of the clicked area with the click point as the center will be taken in a default size. During use, for input, waiting, scrolling, screenshot, search, sliding, assertion and other operation events that need to be performed, click the right mouse button. When our front-end js method monitors the right-click event, a screenshot box will appear with the click point as the center. Select the required area, and a selection box for supported operation events will pop up automatically. Select the operation event to be performed, and an input box for adding the required parameters corresponding to each operation event will pop up and allow the user to enter the relevant parameters.

[0093] The remote real machine platform of this embodiment includes a front-end platform, a back-end platform and a server. The front-end platform interacts with the back-end platform, and the back-end platform interacts with the server. The front-end platform is configured with a browser client, and web pages and page services are provided through the browser client. The mouse interacts with the front-end platform.

[0094] When recording a test instance, for the operation event of each step, the screenshot image formed on the web page will be stored in the back-end platform and the image ID of the screenshot image will be returned. An operation file in JSON format is formed based on the image ID and operation parameters. When the operation files of the operation events of all steps of the test case are recorded, the operation files related to the test case are stored on the back-end platform, where the mapping relationship between components, operation events and image IDs, as well as the mapping relationship between components, operation events, image IDs and operation files are all stored in the database.

[0095] Each operation event such as click, input, wait, scroll, screenshot, search, slide, assertion, etc. in the json sent by the front-end platform corresponds to the corresponding script execution statement that has been pre-made in python and stored in the database. When the json of the front-end is transmitted to the back-end platform, the name of the operation will be taken out from the json first, and the corresponding script execution statement pre-made in the database will be taken out, and the operation parameters and the screenshot image captured by the operation will be replaced in the script execution statement, forming a conversion from json to automated script. After the script is generated, it will be returned to the front-end platform in the form of a string for display.

[0096] When the use case involves modification and adjustment, directly modify the image or sequence logic. Regenerate the automation script for automated testing. The specific operations are:

[0097] (1) Record the operation file of the operation event to be modified through the web page to obtain a new operation file;

[0098] (2) storing new operation files through the remote real machine platform, and storing the mapping relationship between components, operation events, and new operation files through the database;

[0099] (3) Replace the new operation file into the script execution statement to obtain a new test script in the form of a string, and display the test script through the remote real machine platform.

[0100] When executing the use case script, the mobile agent node obtains the current real-time screenshot of the device, and uses the image comparison function of OpenCV to find the coordinates of the screenshot in the real-time image in the script. First, the positioning is performed, and then the event operation is performed to finally achieve accurate execution of the script.

[0101] The parameters of the screenshot image involve the original ratio of the source image, and the situation where different devices have different resolutions. It is necessary to first specify a standard resolution of the source image, and then calculate the ratio of the source image and the standard resolution to obtain the ratio of the source image to the standard resolution, and then convert the resolution of the captured and recorded screenshot according to this ratio. That is, during the execution process, before obtaining the real-time screenshot of the mobile phone through the mobile agent node, the resolution of the mobile phone screen is collected as the real-time resolution, the screenshot in the test script is used as the source image, the resolution of the source image is used as the standard resolution, and the ratio of the real-time resolution to the standard resolution is calculated; after obtaining the real-time screenshot of the mobile phone through the mobile agent node, the resolution of the real-time screenshot is converted based on the ratio of the real-time resolution to the standard resolution, so that the resolution of the converted real-time screen image is adapted to the standard resolution.

[0102] The database stores components and mapping relationships. Components can be stored in a non-relational database, while the mapping relationship between components and operation events, as well as the mapping relationship between components, operation events, and operation files, need to be stored in a relational database. Therefore, it is necessary to select a suitable database according to the storage type.

[0103] In the screenshot-based test case and test script generation method of this embodiment, the case personnel designs the test case, prefabricates the components of each operation event according to the test case, and records the relevant screenshots and operation parameters of the operation event on the web page to obtain the operation file. The development difficulty is reduced by taking screenshots, and the recorded script can also be generated by the case generator to generate a readable traditional test case for easy viewing, breaking the original use case to script and converting it into recording to use case. It realizes one-time recording for multiple uses, and the three linkages of JSON recording record-Python automation script-test case; and the generated graphical test cases and automated test scripts reduce part of the workload and improve work efficiency. In addition, the graphical test case is more convenient and intuitive, and there is no need to view the prototype diagram when performing manual testing or automated testing.

[0104] The examples of the method of this embodiment are as follows:

[0105] Step 1: Double-click the device interface, a screenshot frame will appear, adjust the size and position of the screenshot frame, and select the picture to be operated (e.g. click, wait, determine whether it exists), such as Figure 2 As shown;

[0106] Step 2: Right-click on the screenshot box and select the required operation, including click / long press / existence click / double-click / input / search / slide / assert / wait for appearance / judge existence / screenshot / return / return to home page, etc. If you need to enter parameters, such as the content to be entered, the range and direction of the slide, etc., a pop-up window will pop up to prompt you to enter. If it is not necessary or the input is completed according to the prompt, a recording information will appear in the middle script recording area, showing the operation type, the operated picture, the remarks information, etc. In the synchronous mode, the mobile phone will perform the corresponding operation displayed in the operation information. During the recording process, click Cancel Synchronization to stop the mobile phone from following the defined operation. Double-click the screen again to exit the recording mode. Use the mouse to directly simulate the finger operation on the screen. The next recording is also to switch between recording and non-recording status by double-clicking, such as Figure 3 As shown;

[0107] Step 3: The top operation bar provides some common methods, such as wait, if / else / elif, for, while, app operations (start / clear / stop), etc. Selecting and clicking will also add a message to the script recording information area, and give the correct suggestion content in the corresponding information input box, such as Figure 4 As shown;

[0108] As shown in the if condition input box, an input prompt of existence or non-existence appears. Click the camera button on the right side of the information to replace the image used for judgment. If the image does not exist, the background will generate a judgment script based on the characters in the data input box, such as Figure 5 As shown;

[0109] Select the start app input box and all the installation package names installed on the device will pop up, such as Figure 6 As shown;

[0110] The public method area also supports customization, that is, the information recorded in the current script recording area or the recorded information with the label of public method is saved as a public method. Later, you can directly click to add the public method, and the recorded information contained in the method will be added to the currently recorded script, such as Figure 7 As shown;

[0111] Step 4: In the script, it is often necessary to perform xx operation when xx situation occurs, otherwise perform xx operation logic. In the script recording, it is shown as double-clicking the recording information of the judgment condition. The recording information is selected in light green, such as Figure 8 As shown;

[0112] Then perform normal recording operation. The recorded information will be indented two spaces and added under the selected conditional information. The recorded information supports unlimited nesting and indentation. Click the minus button on the left of the parent information to shrink the child information, and click the plus sign to expand it. Fig. 9 As shown;

[0113] The recording information of the same level can be dragged to adjust the order. When the dragged information contains child information, the child information will be dragged to adjust the position along with the parent information, such as Fig.10 As shown;

[0114] Step 5: The use case information area can temporarily store the public method waiting queue, that is, the use case in the upper left corner - select the project - select the use case included in the project, you can filter to only see the public scripts, click OK after selection, and the imported script information will be displayed in the use case information area. The background color of the public script and the non-public script is different to distinguish them, such as Fig.11 As shown;

[0115] To import a script from the use case information area, you can directly click the arrow to add it to the current script information, or click Edit to replace all current recording information for modification, or remove it from the imported script queue, and open a new window for preview. Fig.12 As shown;

[0116] Step 6: After recording, click Save in the upper left corner, rename according to the prompts, select the project-module to which it belongs, click OK to save, and the recorded use case will appear under the specified project module in the script management menu bar; enter the task list and click Create Task, enter the required information, select the recorded and saved use case and click Submit.

[0117] Embodiment 2:

[0118] The present invention discloses a test case and test script generation system based on screenshots, which is used to execute the generation system, including a mobile phone, a database and a remote real machine platform, wherein the mobile phone comprises at least one device pool, and the database is used for storage.

[0119] The remote real device platform interacts with the mobile phone remotely and with the database to perform the following operations:

[0120] For each step of the test case, configure a script execution statement for each operation event in the step and encapsulate the corresponding component; store the preset component in a database, and store the mapping relationship between the component and the operation event through the database;

[0121] For each step of each test case, the operation file corresponding to each operation event is recorded through the web page. For each operation event, the corresponding mouse click event is monitored, and a corresponding screenshot image is formed for the mouse click area on the web page. The operation event corresponding to the mouse click event is configured with attributes through the web page to obtain the operation attributes, and the operation file in JSON format is constructed based on the screenshot image and the operation attributes.

[0122] After all the operation files related to the steps in the test case are recorded, the components and operation files are matched based on the mapping relationship between the components, operation events, and operation files, and the operation files are replaced into the script execution statements to obtain the test script in string form, and the test script is displayed;

[0123] For the generated test script, a new modified test script is regenerated by modifying the image or sequential logic.

[0124] The components and the mapping relationships among the components, operation events and operation files are all stored in the database.

[0125] Before monitoring the mouse click event, the remote real machine platform is also used to select a picture mode through a page service provided by a web page. The picture mode includes a mobile phone real machine screen mode and a UI picture mode.

[0126] In the remote real machine platform, when the web page forms a corresponding screenshot image for the mouse click area, there are two modes:

[0127] Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page;

[0128] Mode 2: When you right-click the mouse to execute a mouse click event, the corresponding operation event type is other events. Based on the mouse click area, a screenshot frame centered on the click point is formed on the web page. The required area is selected through the screenshot frame to form a screenshot image of the required size. Other events include input, wait, scroll, screenshot, search, slide and assert. After the required area is selected through the screenshot frame to form a screenshot image of the required size, the operation event is configured through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering the relevant parameters of the operation event through the input box.

[0129] The remote real machine platform is used to modify images or sequential logic through the following methods: record the operation file of the operation event to be modified through a web page to obtain a new operation file; store the new operation file through the remote real machine platform, and store the mapping relationship between components, operation events, and new operation files through a database; replace the new operation file with the script execution statement to obtain a new test script in the form of a string, and display the test script through the remote real machine platform.

[0130] In this embodiment, the operation file of each operation event in the steps is recorded through a web page in the remote real machine platform, including the following steps:

[0131] (1) Monitor the mouse click event corresponding to the operation event by using the event monitoring method;

[0132] (2) Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned;

[0133] (3) configuring attributes for the operation event through a page service provided by a web page, including selecting an operation name and inputting operation parameters to obtain operation attributes corresponding to the operation event;

[0134] (4) forming the operation file in JSON format based on the operation name, the picture ID and the operation parameters, recording the corresponding picture ID in the form of picture attributes in the operation file, and storing the mapping relationship between the component, the operation event, the picture ID and the operation parameters in a database, wherein the mapping relationship uses the operation name as a keyword;

[0135] (5) After all the operation files related to the steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and the corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

[0136] The system of this embodiment can execute the screenshot-based test case and test script generation method disclosed in Example 1, and generate a test script through this method.

[0137] Embodiment 3:

[0138] The medium is a computer-readable medium, on which computer instructions are stored, and when the computer instructions are executed by the processor, the processor executes the method disclosed in Embodiment 1. Specifically, a system or device equipped with a storage medium can be provided, on which the software program code implementing the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.

[0139] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.

[0140] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.

[0141] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.

[0142] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.

[0143] It should be noted that not all steps and modules in the above-mentioned processes and system structure diagrams are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.

[0144] In the above embodiments, the hardware unit can be realized by mechanical means or electrical means. For example, a hardware unit can include permanent dedicated circuits or logic (such as special processors, FPGA or ASIC) to complete the corresponding operation. The hardware unit can also include programmable logic or circuits (such as general-purpose processors or other programmable processors), which can be temporarily set by software to complete the corresponding operation. Concrete implementation (mechanical means or dedicated permanent circuits or temporarily set circuits) can be determined based on cost and time considerations.

[0145] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.

Claims

1. Test case and test script generation method based on screenshots, Features The invention is applied to a test case generation system including a remote real machine platform, a database and a mobile phone, wherein the remote real machine provides a web page and a mouse, and the generation method includes the following steps: For each step of the test case, configure a script execution statement for each operation event in the step and encapsulate the corresponding component, store the preset component in a database, and store the mapping relationship between the component and the operation event in the database; For each step of the test case, the operation file corresponding to each operation event is recorded through the web page. For each operation event, the corresponding mouse click event is monitored, and a corresponding screenshot image is formed for the mouse click area on the web page. The operation event is attributed and the operation attributes are obtained through the web page. The operation file in JSON format is constructed based on the screenshot image and the operation attributes, and the mapping relationship between the component, operation event, and operation file is stored in the database; After the operation files related to all steps in the test case are recorded, the components and operation files will be matched based on the mapping relationship between components, operation events, and operation files, and the operation files will be replaced in the script execution statement to obtain the test script in string form, and the test script will be displayed through the remote real machine platform.

2. The method for generating test cases and test scripts based on screenshots according to claim 1, Features Recording the operation file of each operation event in the steps through the web page includes the following steps: Monitor mouse click events by monitoring events; Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned; The page service provided by the web page configures the attributes of the operation event, including the configuration attribute name and related operation parameters, to obtain the corresponding operation attributes; Construct an operation file in JSON format based on the operation name, picture ID and operation parameters, in which the picture ID is recorded as a picture attribute, and a mapping relationship between the component, operation event, picture ID and operation parameters is stored in a database, with the operation name as the keyword; After the operation files related to all steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

3. The method for generating test cases and test scripts based on screenshots according to claim 1 or 2, Features Before monitoring the mouse click event, a picture mode is selected through a page service provided by the web page, wherein the picture mode includes a mobile phone real screen mode and a UI picture mode.

4. The method for generating test cases and test scripts based on screenshots according to claim 1 or 2, Features Listen to the corresponding mouse click event, and when the web page forms a corresponding screenshot of the mouse click area, there are two modes: Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page; Mode 2: When the right button of the mouse is clicked to execute a mouse click event, the corresponding operation event type is other events. Based on the click area of ​​the mouse, a screenshot frame centered on the click point is formed on the web page, and a screenshot image of a desired size is formed by selecting the desired area through the screenshot frame; the other events include input, wait, scroll, screenshot, search, slide and assert; After selecting the required area through the screenshot box to form a screenshot image of the required size, the properties of the operation event are configured through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering relevant parameters of the operation event through the input box.

5. The method for generating test cases and test scripts based on screenshots according to claim 1 or 2, Features For the generated test script, regenerate the modified new test script by modifying the image or sequential logic; Modify the image or sequence logic by the following methods: Record the operation file of the operation event to be modified through the web page to obtain a new operation file; The new operation file is stored through the remote real machine platform, and the mapping relationship between the component, the operation event, and the new operation file is stored through the database; The new operation file is replaced into the script execution statement to obtain a new test script in the form of a string, and the test script is displayed through the remote real machine platform.

6. The method for generating test cases and test scripts based on screenshots according to claim 1 or 2, Features The test case is executed by the following method: Get real-time screenshots of the mobile phone through the mobile agent node; Through the image comparison function of opencv, find the coordinates of the corresponding screenshot in the test script in the real-time screenshot to locate the operation; Execute the corresponding test case to perform event operations.

7. The method for generating test cases and test scripts based on screenshots according to claim 6, Features Before obtaining a real-time screenshot of the mobile phone through the mobile agent node, the resolution of the mobile phone screen is collected as the real-time resolution, the screenshot in the test script is used as the source image, the resolution of the source image is used as the standard resolution, and the ratio of the real-time resolution to the standard resolution is calculated; After obtaining the real-time screenshot of the mobile phone through the mobile agent node, the resolution of the real-time screenshot is converted based on the ratio of the real-time resolution to the standard resolution, so that the resolution of the converted real-time screen image is adapted to the standard resolution.

8. Screenshot-based test case and test script generation system, Features Used to execute the screenshot-based test case and test script generation method according to any one of claims 1 to 7, the generation system comprises: A mobile phone, wherein the mobile phone is at least one, and the at least one mobile phone constitutes a device pool; A database, wherein the database is used for storage; A remote real machine platform, which remotely interacts with the mobile phone and the database to perform the following operations: For each step of the test case, configure a script execution statement for each operation event in the step and encapsulate the corresponding component; store the preset component in a database, and store the mapping relationship between the component and the operation event through the database; For each step of each test case, the operation file corresponding to each operation event is recorded through the web page. For each operation event, the corresponding mouse click event is monitored, and a corresponding screenshot image is formed for the mouse click area on the web page. The operation event corresponding to the mouse click event is configured with attributes through the web page to obtain the operation attributes, and the operation file in JSON format is constructed based on the screenshot image and the operation attributes. After all the operation files related to the steps in the test case are recorded, the components and operation files are matched based on the mapping relationship between the components, operation events, and operation files, and the operation files are replaced into the script execution statements to obtain the test script in string form, and the test script is displayed; For the generated test script, regenerate the modified new test script by modifying the image or sequential logic; The components and the mapping relationship between the components, operation events and operation files are all stored in the database; Before monitoring the mouse click event, the remote real machine platform is also used to select a picture mode through a page service provided by a web page, wherein the picture mode includes a mobile phone real machine screen mode and a UI picture mode; In the remote real machine platform, when a web page forms a corresponding screenshot image for the mouse click area, there are two modes, namely: Mode 1: When the left mouse button is clicked to execute a mouse click event, the corresponding operation event type is a click event. Based on the click area of ​​the mouse, a square screenshot image of a predetermined size centered on the click point is formed on the web page; Mode 2: When the right button of the mouse is clicked to execute a mouse click event, the corresponding operation event type is other events. Based on the click area of ​​the mouse, a screenshot frame centered on the click point is formed on the web page, and a screenshot image of a desired size is formed by selecting the desired area through the screenshot frame; the other events include input, wait, scroll, screenshot, search, slide and assert; after the desired area is selected through the screenshot frame to form a screenshot image of a desired size, the operation event is configured with properties through the toolbar that pops up on the web page, including selecting the name of the operation event through the selection box and entering relevant parameters of the operation event through the input box; The remote real machine platform is used to modify images or sequential logic by the following methods: Record the operation file of the operation event to be modified through the web page to obtain a new operation file; The new operation file is stored through the remote real machine platform, and the mapping relationship between the component, the operation event, and the new operation file is stored through the database; The new operation file is replaced into the script execution statement to obtain a new test script in the form of a string, and the test script is displayed through the remote real machine platform.

9. The screenshot-based test case and test script generation system according to claim 8, Features The remote real machine platform records the operation file of each operation event in the steps through a web page, including the following steps: Monitor the mouse click event corresponding to the operation event by using the event monitoring method; Based on the click area of ​​the mouse, a screenshot image corresponding to the operation event is formed on the web page, the screenshot image is saved on the remote real machine and the image ID of the screenshot image is returned; Performing attribute configuration for the operation event through a page service provided by a web page, including selecting an operation name and inputting operation parameters to obtain operation attributes corresponding to the operation event; The operation file in JSON format is formed based on the operation name, the picture ID and the operation parameters, the corresponding picture ID is recorded in the operation file in the form of picture attributes, and the mapping relationship between the component, the operation event, the picture ID and the operation parameter is stored in the database, and the mapping relationship uses the operation name as the keyword; After the operation files related to all steps in the test case are recorded, based on the mapping relationship between the components, operation events, picture IDs and operation parameters, the components and corresponding operation files are matched by the operation names, and the picture IDs and operation parameters are replaced in the corresponding script execution statements to obtain the test script in string form.

10. A medium, which is a computer-readable medium, Features The computer readable medium stores computer instructions, and when the computer instructions are executed by a processor, the processor executes the method according to any one of claims 1 to 7.