Application testing method, device, electronic equipment and storage medium
By automatically generating application test scripts, the problem of high -manpower costs caused by manual writing test scripts in existing technologies has been solved, and more efficient application tests have been achieved.
Patent Information
- Application Number
- CN202211501359.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-28
- Publication Date
- 2025-01-24
- Estimated Expiration
- 2042-11-28
AI Technical Summary
The existing application testing methods require manual writing of test scripts, resulting in high labor costs.
By obtaining the initial interface screenshot of the test application, text recognition and image search, generate the initial test script, and adjust the script according to the results interface screenshot to achieve automatic generation of the target test script.
Reduce the needs of manually writing test scripts, reduce labor costs, and improve the efficiency of application testing.
Smart Images

Figure CN115794632B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of application testing technology, and in particular to an application testing method, device, electronic equipment and storage medium. Background Art
[0002] With the popularization and development of mobile terminals, mobile applications have become an important part of people's lives.
[0003] In the process of mobile application development, testing of mobile applications is an essential part. Traditional testing work is done manually, and there is a lot of repetitive work in some scenarios.
[0004] In order to reduce labor costs, test scripts can be written and executed instead of manual testing, but this process requires programmers or testers to write a large number of test scripts. When product functions are changed, test cases and test scripts often need to be modified a lot. Summary of the invention
[0005] The present invention provides an application testing method, device, electronic device and storage medium, which are used to solve the technical problem that the existing application testing method requires manual writing of test scripts and has high labor costs.
[0006] The present invention provides an application testing method, comprising:
[0007] Get a screenshot of the initial interface of the test application;
[0008] Performing text recognition on the initial interface screenshot to obtain multiple text data sets;
[0009] Performing image search on the initial interface screenshot to obtain multiple image data sets;
[0010] Generate an initial test script using the text data set and the image data set;
[0011] Generate user input based on the text data and the image data set, and obtain a result interface screenshot generated after executing the user input;
[0012] Adjust the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script;
[0013] Run the target test script to obtain application test results.
[0014] Optionally, the step of performing text recognition on the initial interface screenshot to obtain multiple text data sets includes:
[0015] Recognize the text in the initial interface screenshot to obtain a plurality of initial text data sets, wherein the initial text data sets include text position coordinates, text recognition results, and text score values corresponding to the text recognition results;
[0016] The initial text data sets whose text score values are greater than a preset text score threshold are collected as text data sets.
[0017] Optionally, the step of performing image search on the initial interface screenshot to obtain a plurality of image data sets includes:
[0018] Searching for a preset feature map in the initial interface screenshot;
[0019] Obtaining the image position coordinates and image score value of the feature map in the initial interface screenshot;
[0020] The feature map whose image score value is greater than a preset image score threshold is used as the target map;
[0021] The image position coordinates and image score values of each target image are respectively used to generate a corresponding image data set.
[0022] Optionally, the step of generating an initial test script using the text data set and the image data set comprises:
[0023] Finding a function scenario value from the text data set;
[0024] Finding a functional scene from the image data set;
[0025] An initial test script is generated using the functional scenario value and the functional scenario.
[0026] Optionally, the step of adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script includes:
[0027] Comparing the result interface screenshot with the initial interface screenshot for similarity to obtain a difference score;
[0028] Determining the stage information of the result interface screenshot according to the difference score;
[0029] The phase information is added to the initial test script to obtain a target test script.
[0030] Optionally, the step of performing a similarity comparison between the result interface screenshot and the initial interface screenshot to obtain a difference score includes:
[0031] Calculating text similarity between the initial interface screenshot and the result interface screenshot to obtain difference text;
[0032] Calculate the proportion of the different characters to all characters to obtain a character difference score;
[0033] Calculating image similarity between the initial interface screenshot and the result interface screenshot to determine a difference image area;
[0034] Calculate the proportion of the difference image area to the initial interface screenshot to obtain an image difference score;
[0035] The text difference score and the image difference score are weightedly calculated according to preset weights to obtain a difference score.
[0036] Optionally, the step of determining the stage information of the result interface screenshot according to the difference score includes:
[0037] Matching the score interval corresponding to the difference score;
[0038] The stage information corresponding to the score interval is obtained.
[0039] The present invention also provides an application testing device, comprising:
[0040] An initial interface screenshot acquisition module is used to acquire a screenshot of the initial interface of the test application;
[0041] A text data set generation module, used to perform text recognition on the initial interface screenshot to obtain multiple text data sets;
[0042] An image data set generation module, used to perform image search on the initial interface screenshot to obtain multiple image data sets;
[0043] An initial test script generation module, used to generate an initial test script using the text data set and the image data set;
[0044] A result interface screenshot generation module, used to generate a user input based on the text data and the image data set, and obtain a result interface screenshot generated after executing the user input;
[0045] A target test script generating module, used for adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script;
[0046] The test module is used to run the target test script to obtain the application test result.
[0047] The present invention also provides an electronic device, characterized in that the device includes a processor and a memory:
[0048] The memory is used to store program code and transmit the program code to the processor;
[0049] The processor is used to execute the application testing method as described above according to the instructions in the program code.
[0050] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store program code, and the program code is used to execute the application testing method as described in any one of the above items.
[0051] It can be seen from the above technical scheme that the present invention has the following advantages: The present invention provides an application testing method, including: obtaining an initial interface screenshot of a test application; performing text recognition on the initial interface screenshot to obtain multiple text data sets; performing image search on the initial interface screenshot to obtain multiple image data sets; using the text data set and the image data set to generate an initial test script; generating user input based on the text data and the image data set, and obtaining a result interface screenshot generated after executing the user input; adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script; running the target test script to obtain the application test results.
[0052] The present invention generates an initial test script by obtaining a test interface screenshot of a test application, and then generates user input according to text recognition and image recognition, so as to obtain a result interface screenshot after operating the initial interface; and then forms a target test script according to the initial interface screenshot, the result interface screenshot and the corresponding user input. This realizes the automatic generation of the target test script, thereby making it impossible to manually write the test script, and reducing the labor cost. In addition, by running the automatically generated target test script to implement the test of the test application, the efficiency of the application test can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, 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 labor.
[0054] Figure 1 A flowchart of the steps of an application testing method provided by an embodiment of the present invention;
[0055] Figure 2 A flowchart of the steps of an application testing method provided by another embodiment of the present invention;
[0056] Figure 3 A structural block diagram of an application testing device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The embodiments of the present invention provide an application testing method, device, electronic device and storage medium, which are used to solve the technical problem that the existing application testing method requires manual writing of test scripts and has high labor costs.
[0058] In order to make the purpose, features and advantages of the present invention more obvious and easy to understand, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] See also Figure 1 , Figure 1 A flowchart of the steps of an application testing method provided by an embodiment of the present invention.
[0060] An application testing method provided by the present invention may specifically include the following steps:
[0061] Step 101, obtaining a screenshot of the initial interface of the test application;
[0062] In the embodiment of the present invention, the mobile phone can be connected to the computer via a USB cable, the adb connection can be turned on, the test application can be opened, and the interface of the application to be tested can be manually switched to. Then, a screenshot of the mobile phone test application interface can be taken through an external camera or by running an adb command, and the screenshot can be saved in "year-month-day hour-minute-second-sequence number" to obtain a screenshot of the initial interface of the test application.
[0063] Step 102, performing text recognition on the initial interface screenshot to obtain multiple text data sets;
[0064] After obtaining the initial interface screenshot, OpenCV can be used to perform text recognition on the initial interface screenshot to obtain multiple text data sets, wherein each text data set is a set of text recognition results of a character.
[0065] Step 103, performing image search on the initial interface screenshot to obtain multiple image data sets;
[0066] After obtaining the initial interface screenshot, the initial interface screenshot can also be subjected to image recognition through OpenCV to obtain multiple image data sets, wherein each image data set is a set of recognition results of an area in the initial interface screenshot.
[0067] Step 104, using the text data set and the image data set to generate an initial test script;
[0068] The test script is used to perform a series of operations on the operation target in a specific functional scenario. The operation behavior simulates user input, including but not limited to conventional user input operations such as clicking, sliding, long pressing, and text input.
[0069] After obtaining the text data set and the image data set, the scene or functional interface corresponding to the initial interface screenshot can be preliminarily analyzed based on the text data set and the image data set to generate an initial test script.
[0070] Step 105, generating user input based on the text data and the image data set, and obtaining a screenshot of a result interface generated after executing the user input;
[0071] In an embodiment of the present invention, after obtaining a text data set and an image data set, user input suitable for the scenario can be generated according to the scenario reflected by the text data set and the image data set, and the user input can be executed to obtain a result interface screenshot corresponding to the execution result.
[0072] Among them, multiple user inputs can be preset, and each scene can have corresponding several user inputs. After the text data set and the image data set are determined, the preset user inputs can be selected according to a predetermined strategy or randomly.
[0073] Step 106, adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script;
[0074] After obtaining the result interface screenshot, the initial test script can be filled and adjusted according to the result interface screenshot and the initial interface screenshot to obtain a target test script including user input and corresponding operation results.
[0075] Step 107, run the target test script to obtain the application test result.
[0076] After obtaining the target test script, you can run the target test script to obtain the application test results.
[0077] The present invention generates an initial test script by obtaining a test interface screenshot of a test application, and then generates user input according to text recognition and image recognition, so as to obtain a result interface screenshot after operating the initial interface; and then forms a target test script according to the initial interface screenshot, the result interface screenshot and the corresponding user input. This realizes the automatic generation of the target test script, thereby making it impossible to manually write the test script, and reducing the labor cost. In addition, by running the automatically generated target test script to implement the test of the test application, the efficiency of the application test can be improved.
[0078] See also Figure 2 , Figure 2 A flowchart of an application testing method provided by another embodiment of the present invention. The embodiment of the present invention may specifically include the following steps:
[0079] Step 201, obtaining a screenshot of the initial interface of the test application;
[0080] Step 201 is the same as step 101. For details, please refer to the description of step 101, which will not be repeated here.
[0081] Step 202, performing text recognition on the initial interface screenshot to obtain multiple text data sets;
[0082] After obtaining the initial interface screenshot, OpenCV can be used to perform text recognition on the initial interface screenshot to obtain multiple text data sets, wherein each text data set is a set of text recognition results of a character.
[0083] In one example, the step of performing text recognition on the initial interface screenshot to obtain multiple text data sets may include the following sub-steps:
[0084] S21, recognizing text in the initial interface screenshot to obtain multiple initial text data sets, the initial text data sets including text position coordinates, text recognition results, and text score values corresponding to the text recognition results;
[0085] S22, collecting the initial text data sets whose text score values are greater than a preset text score threshold as a text data set.
[0086] In a specific implementation, the OpenCv software library can be used to perform text recognition on the initial interface screenshot to obtain multiple initial text data sets. Each initial text data set includes the text position coordinates, text recognition results, and text score values corresponding to the text recognition results. The text position coordinates include the four point coordinates of the text position, the text recognition result is the text corresponding to the text, and the text score value corresponding to the text recognition result is the probability that the text recognition result is the actual text.
[0087] A text recognition result with a too low text score value indicates that the probability of its recognition error is too high, so the recognition result can be discarded. In a specific implementation, the recognized text can be screened by setting a text score threshold. When the text score value is greater than the text score threshold, it indicates that the text recognition is successful; the initial text set corresponding to the successfully recognized text is used as a text data set and saved.
[0088] In one example, the text data set can be saved in the following format: {text number, [x1, y1] [x2, y2] [x3, y3] [x4, y4], "text recognition result", "text score value", screenshot number}. The text number is used to distinguish different text data sets. The specific format is not required.
[0089] Step 203, performing image search on the initial interface screenshot to obtain multiple image data sets;
[0090] After obtaining the initial interface screenshot, the initial interface screenshot can also be subjected to image recognition through OpenCV to obtain multiple image data sets, wherein each image data set is a set of recognition results of an area in the initial interface screenshot.
[0091] In one example, the step of performing image search on the initial interface screenshot to obtain multiple image data sets may include the following sub-steps:
[0092] S31, searching for a preset feature map in the initial interface screenshot;
[0093] S32, obtaining the image position coordinates and image score value of the feature map in the initial interface screenshot;
[0094] S33, taking a feature graph whose image score value is greater than a preset image score threshold as a target graph;
[0095] S34, using the image position coordinates and image score value of each target image to generate a corresponding image data set.
[0096] In a specific implementation, a preset feature image can be searched in the initial interface screenshot. The feature image can be a logo, a button screenshot, or other identifying images. The feature image can be preset according to actual needs.
[0097] After obtaining one or more identical feature maps from the initial interface screenshot, obtain the image position coordinates and image score values corresponding to each feature map. Then use the feature map whose image score value is greater than the preset image score threshold as the target map. And use the image position coordinates and image score values of each target map to generate an image data set. The image data set can be saved in the following format: {image number, [x5, y5][x6, y6][x7, y7][x8, y8], "image score value", screenshot number}. The image number is used to distinguish different image data sets.
[0098] Step 204, using the text data set and the image data set to generate an initial test script;
[0099] After obtaining the text data set and the image data set, the scene or functional interface corresponding to the initial interface screenshot can be preliminarily analyzed based on the text data set and the image data set to generate an initial test script.
[0100] In one example, the step of generating an initial test script using a text dataset and an image dataset may include the following sub-steps:
[0101] S41, searching for a function scenario value from a text data set;
[0102] S42, searching for a functional scene from the image data set;
[0103] S43, generating an initial test script using the functional scenario value and the functional scenario.
[0104] In the specific implementation, some text recognition results represent specific functional scenario values, such as "login", "my" or "home", etc. Some images may also contain functional scenarios, such as a screenshot of a button containing the word "login" or a screenshot containing the word "home", etc. These images also reflect some specific functional scenarios.
[0105] Therefore, in an embodiment of the present invention, it is possible to find out whether a text data set contains a specific functional scenario value, or whether an image contains a specific functional scenario to preliminarily determine the scene corresponding to the initial interface screenshot, and thereby generate an initial test script.
[0106] Step 205, generating user input based on the text data and the image data set, and obtaining a screenshot of a result interface generated after executing the user input;
[0107] In an embodiment of the present invention, after obtaining a text data set and an image data set, user input suitable for the scenario can be generated according to the scenario reflected by the text data set and the image data set, and the user input can be executed to obtain a result interface screenshot corresponding to the execution result.
[0108] Step 206, performing a similarity comparison between the result interface screenshot and the initial interface screenshot to obtain a difference score;
[0109] In an embodiment of the present invention, by performing a similarity comparison between the result interface screenshot and the initial interface screenshot, it is possible to determine the operation stage of the result interface screenshot relative to the initial interface screenshot, such as the next operation stage of the initial interface, the next operation interface of the initial interface, or still in the initial interface.
[0110] In a specific implementation, the operation stage of the result interface screenshot relative to the initial interface screenshot can be determined by the difference score between the two.
[0111] In one example, the step of performing a similarity comparison between the result interface screenshot and the initial interface screenshot to obtain a difference score may include the following sub-steps:
[0112] S61, calculating text similarity between the initial interface screenshot and the result interface screenshot to obtain difference text;
[0113] S62, calculating the proportion of different characters to all characters to obtain a character difference score;
[0114] S63, performing image similarity calculation on the initial interface screenshot and the result interface screenshot to determine the difference image area;
[0115] S64, calculating the proportion of the difference image area to the initial interface screenshot to obtain an image difference score;
[0116] S65, performing weighted calculation on the text difference score and the image difference score according to a preset weight to obtain a difference score.
[0117] In a specific implementation, first, the text similarity calculation can be performed on the initial interface screenshot and the result interface screenshot to obtain the difference text, and obtain the similarity score value and the difference position coordinates of the difference text. Then, the proportion of the difference text with a similarity score greater than a preset first threshold (which can be set according to actual conditions) in all the texts in the initial interface screenshot is calculated to obtain the overall text difference score.
[0118] Next, the image similarity of the initial interface screenshot and the result interface screenshot can be calculated to determine the difference image areas where differences exist, and obtain the corresponding similarity score values. Then, the proportion of the difference image areas with similarity score values greater than a preset second threshold (which can be set according to actual conditions) in the initial interface screenshot is calculated to obtain the overall image difference score.
[0119] Specifically, the ssim algorithm (image similarity structure algorithm) of OpenCV can be used to grayscale the two first, and then the compare_ssim method of the scikit-image library of Python is called to calculate the image similarity between the initial interface screenshot and the result interface result.
[0120] Finally, the text difference score and the image difference score are weightedly calculated according to the set weights to obtain the overall difference score between the initial interface image and the result interface image.
[0121] In one example, when there are texts in the initial interface screenshot and the result interface screenshot, a weight of 0.2 may be set for the text difference score, and a weight of 0.8 may be set for the image difference score.
[0122] In another example, when there is no text in the initial interface screenshot and the result interface screenshot, the weight of the image difference score can be set to 1.
[0123] Step 207, determining the stage information of the screenshot of the result interface according to the difference score;
[0124] After obtaining the initial interface screenshot and the result interface screenshot, the stage information of the result interface screenshot can be determined.
[0125] In one example, the step of determining the stage information of the result interface screenshot according to the difference score may include the following sub-steps:
[0126] S71, score interval corresponding to the matching difference score;
[0127] S72, obtaining the stage information corresponding to the score interval.
[0128] In an embodiment of the present invention, different difference score intervals can be set for different stages of the result interface screenshot. For example, a difference score in the interval of [95%, 100] indicates that the result interface screenshot is the next operation interface of the initial interface screenshot; a difference score in the interval of [0, 15] indicates that the result interface screenshot is the next operation stage of the initial interface screenshot.
[0129] Step 208, adding the phase information to the initial test script to obtain a target test script;
[0130] After obtaining the result interface screenshot, the initial test script can be filled and adjusted according to the result interface screenshot and the initial interface screenshot to obtain a target test script including user input and corresponding operation results.
[0131] It should be noted that the target test script generated by the above process has a test result after a user operation from the initial interface to the result interface. After obtaining the target test script, the result interface screenshot can be used as the initial interface screenshot, so that the above operation obtains a new target test script.
[0132] In the embodiment of the present invention, the test script generated once can be called a meta-test script, which is a test script of a basic unit. The method of automatically generating a script includes but is not limited to the following methods: First, multiple simple meta-test scripts are combined according to the serial number combination of their script management, and a new test script can be automatically generated; second, given a keyword and an initial interface screenshot, the keyword is searched based on the initial interface screenshot. During this process, the initial interface screenshot can be allowed to enter the next interface and then return; the keyword is searched for multiple times in a loop until the keyword is found. Or the keyword can be extended multiple times. For example, if the keyword is "sort", after finding the keyword, the control containing "sort" can be clicked back and forth multiple times, such as "time sort", "name sort", etc. The meta-test scripts generated by the combination can automatically generate new test scripts; thirdly, given the initial interface screenshot and the result interface screenshot, the initial interface screenshot is used as a benchmark, and multiple meta-test scripts can be obtained by running continuously until the result interface screenshot is found, or until an interface similar to the result interface screenshot is found, or a given time is stopped. The meta-test scripts generated by the combination can automatically generate new test scripts. Based on the meta-test script, the meta-test scripts generated by the combination or arrangement are run with different strategies, and finally a valid test script can be automatically generated.
[0133] Step 209: Run the target test script to obtain the application test result.
[0134] In an embodiment of the present invention, the application test based on the target test script may include the following process:
[0135] a. Connect the computer to the phone with a USB cable, enable adb connection, open the test application, and manually switch to the interface of the application to be tested;
[0136] b. Run the specific python target test script on the computer.
[0137] c. The target test script runs the adb command to take a screenshot of the mobile phone test application interface.
[0138] d. The test script runs the OpenCV software library, performs text recognition or image search on the screenshot, finds the coordinates of the corresponding test operation target, and uses the adb command to perform user input operations on the operation target according to the established code logic. The user input operation causes the test application to respond until the test script is completed or the application is interrupted due to a bug.
[0139] The present invention generates an initial test script by obtaining a test interface screenshot of a test application, and then generates user input according to text recognition and image recognition, so as to obtain a result interface screenshot after operating the initial interface; and then forms a target test script according to the initial interface screenshot, the result interface screenshot and the corresponding user input. This realizes the automatic generation of the target test script, thereby making it impossible to manually write the test script, and reducing the labor cost. In addition, by running the automatically generated target test script to implement the test of the test application, the efficiency of the application test can be improved.
[0140] See also Figure 3 , Figure 3 A structural block diagram of an application testing device provided by an embodiment of the present invention.
[0141] An embodiment of the present invention provides an application testing device, including:
[0142] An initial interface screenshot acquisition module 301 is used to acquire an initial interface screenshot of a test application;
[0143] A text data set generation module 302 is used to perform text recognition on the initial interface screenshot to obtain multiple text data sets;
[0144] An image data set generation module 303 is used to perform image search on the initial interface screenshot to obtain multiple image data sets;
[0145] An initial test script generating module 304, for generating an initial test script using a text data set and an image data set;
[0146] A result interface screenshot generating module 305 is used to generate user input based on the text data and the image data set, and obtain a result interface screenshot generated after executing the user input;
[0147] A target test script generating module 306 is used to adjust the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script;
[0148] The test module 307 is used to run the target test script to obtain the application test result.
[0149] In the embodiment of the present invention, the text data set generation module 302 includes:
[0150] An initial text data set acquisition submodule is used to recognize text in the initial interface screenshot to obtain multiple initial text data sets, wherein the initial text data sets include text position coordinates, text recognition results, and text score values corresponding to the text recognition results;
[0151] The text data set generation submodule is used to collect the initial text data sets whose text score values are greater than a preset text score threshold as a text data set.
[0152] In the embodiment of the present invention, the image data set generating module 303 includes:
[0153] The feature map search submodule is used to search for the preset feature map in the initial interface screenshot;
[0154] An image position coordinate and image score value acquisition submodule is used to obtain the image position coordinate and image score value of the feature map in the initial interface screenshot;
[0155] A target image determination submodule is used to take a feature image whose image score value is greater than a preset image score threshold as a target image;
[0156] The image data set generation submodule is used to generate a corresponding image data set using the image position coordinates and image score values of each target image.
[0157] In the embodiment of the present invention, the initial test script generation module 304 includes:
[0158] A function scenario value search submodule is used to search for function scenario values from a text data set;
[0159] A functional scene search submodule is used to search for functional scenes from an image data set;
[0160] The initial test script generation submodule is used to generate an initial test script using functional scenario values and functional scenarios.
[0161] In the embodiment of the present invention, the target test script generation module 306 includes:
[0162] The difference score acquisition submodule is used to compare the similarity between the result interface screenshot and the initial interface screenshot to obtain the difference score;
[0163] The stage information determination submodule is used to determine the stage information of the result interface screenshot according to the difference score;
[0164] The target test script generation submodule is used to add the phase information to the initial test script to obtain the target test script.
[0165] In the embodiment of the present invention, the difference score acquisition submodule includes:
[0166] A difference text acquisition unit is used to calculate the text similarity between the initial interface screenshot and the result interface screenshot to obtain the difference text;
[0167] A character difference score calculation unit is used to calculate the proportion of different characters to all characters to obtain a character difference score;
[0168] A difference image region determination unit, used to calculate the image similarity between the initial interface screenshot and the result interface screenshot, and determine the difference image region;
[0169] An image difference score calculation unit, used to calculate the proportion of the difference image area to the initial interface screenshot, and obtain the image difference score;
[0170] The difference score generating unit is used to perform weighted calculation on the text difference score and the image difference score according to a preset weight to obtain a difference score.
[0171] In the embodiment of the present invention, the stage information determination submodule includes:
[0172] A score interval matching unit, used for matching the score interval corresponding to the difference score;
[0173] The stage information acquisition unit is used to acquire the stage information corresponding to the score interval.
[0174] An embodiment of the present invention further provides an electronic device, the device comprising a processor and a memory:
[0175] The memory is used to store the program code and transmit the program code to the processor;
[0176] The processor is used to execute the application testing method of the embodiment of the present invention according to the instructions in the program code.
[0177] The embodiment of the present invention further provides a computer-readable storage medium, which is used to store program codes, and the program codes are used to execute the application testing method of the embodiment of the present invention.
[0178] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0179] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0180] It will be appreciated by those skilled in the art that the embodiments of the present invention may be provided as methods, devices, or computer program products. Therefore, the embodiments of the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the embodiments of the present invention may 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 codes.
[0181] The embodiments of the present invention are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0182] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0183] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0184] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0185] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0186] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An application testing method, characterized in that: include: Get a screenshot of the initial interface of the test application; Performing text recognition on the initial interface screenshot to obtain multiple text data sets; Performing image search on the initial interface screenshot to obtain multiple image data sets; Generate an initial test script using the text data set and the image data set; Generate user input based on the text data and the image data set, and obtain a result interface screenshot generated after executing the user input; Adjust the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script; Run the target test script to obtain application test results; The step of adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script includes: Comparing the result interface screenshot with the initial interface screenshot for similarity to obtain a difference score; Determining the stage information of the result interface screenshot according to the difference score; Adding the phase information to the initial test script to obtain a target test script; wherein the adding operation includes filling and adjusting; The step of comparing the similarity between the result interface screenshot and the initial interface screenshot to obtain a difference score includes: Calculating text similarity between the initial interface screenshot and the result interface screenshot to obtain difference text; Calculate the proportion of the different characters to all characters to obtain a character difference score; Calculating image similarity between the initial interface screenshot and the result interface screenshot to determine a difference image area; Calculate the proportion of the difference image area to the initial interface screenshot to obtain an image difference score; The text difference score and the image difference score are weightedly calculated according to preset weights to obtain a difference score.
2. The method according to claim 1, characterized in that The step of performing text recognition on the initial interface screenshot to obtain multiple text data sets includes: Recognize the text in the initial interface screenshot by OpenCV, and obtain multiple initial text data sets, wherein the initial text data sets include text position coordinates, text recognition results, and text score values corresponding to the text recognition results; the text score value is the probability that the text recognition result is the actual text; The initial text data sets whose text score values are greater than a preset text score threshold are collected as text data sets.
3. The method according to claim 1, characterized in that The step of performing image search on the initial interface screenshot to obtain multiple image data sets includes: Searching for a preset feature map in the initial interface screenshot using OpenCV; Obtaining the image position coordinates and image score value of the feature map in the initial interface screenshot; The feature map whose image score value is greater than a preset image score threshold is used as the target map; The image position coordinates and image score values of each target image are respectively used to generate a corresponding image data set.
4. The method according to claim 1, characterized in that: The step of using the text data set and the image data set to generate an initial test script comprises: Finding a function scenario value from the text data set; Finding a functional scene from the image data set; An initial test script is generated using the functional scenario value and the functional scenario.
5. The method according to claim 1, characterized in that The step of determining the stage information of the result interface screenshot according to the difference score includes: Matching the score interval corresponding to the difference score; The stage information corresponding to the score interval is obtained.
6. An application testing device, characterized in that: include: An initial interface screenshot acquisition module is used to acquire a screenshot of the initial interface of the test application; A text data set generation module, used to perform text recognition on the initial interface screenshot to obtain multiple text data sets; An image data set generation module, used to perform image search on the initial interface screenshot to obtain multiple image data sets; An initial test script generation module, used to generate an initial test script using the text data set and the image data set; A result interface screenshot generation module, used to generate a user input based on the text data and the image data set, and obtain a result interface screenshot generated after executing the user input; A target test script generating module, used for adjusting the initial test script according to the result interface screenshot and the initial interface screenshot to obtain a target test script; A test module, used to run the target test script to obtain application test results; Among them, the target test script generation module includes: The difference score acquisition submodule is used to compare the similarity between the result interface screenshot and the initial interface screenshot to obtain the difference score; The stage information determination submodule is used to determine the stage information of the result interface screenshot according to the difference score; The target test script generation submodule is used to add the phase information to the initial test script to obtain the target test script; wherein the adding operation includes filling and adjusting; Among them, the difference score acquisition submodule includes: A difference text acquisition unit is used to calculate the text similarity between the initial interface screenshot and the result interface screenshot to obtain the difference text; A character difference score calculation unit is used to calculate the proportion of different characters to all characters to obtain a character difference score; A difference image region determination unit, used to calculate the image similarity between the initial interface screenshot and the result interface screenshot, and determine the difference image region; An image difference score calculation unit, used to calculate the proportion of the difference image area to the initial interface screenshot, and obtain the image difference score; The difference score generating unit is used to perform weighted calculation on the text difference score and the image difference score according to a preset weight to obtain a difference score.
7. An electronic device, characterized in that: The device comprises a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is used to execute the application testing method according to any one of claims 1 to 5 according to the instructions in the program code.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store program codes, and the program codes are used to execute the application testing method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Script testing method and device, electronic equipment and storage medium
CN112148594A
Method and device for generating test script
CN113835996A