Test case optimization method and device

By dividing rectangular areas in the target desktop and updating mouse click coordinates using image recognition algorithms, the problem of inaccurate clicks in test cases after application migration is solved, and the reliability of the test is improved.

CN119127050APending Publication Date: 2024-12-13JILIN ZHONGKE FANGDE SOFTWARE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411308019.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-19
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

After the application is migrated to different operating systems, the mouse click coordinates are fixed inaccurate clicks due to subtle changes in the control, resulting in low test reliability.

Method used

By dividing rectangular areas in the target desktop, using image recognition algorithms to identify the center coordinates of the rectangular areas, and updating the mouse click coordinates in the test cases to adapt to subtle changes in the operating system.

Benefits of technology

Improve the reliability of the test, avoid mouse click errors caused by operating system changes, and ensure the accuracy of automated tests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127050A_ABST
    Figure CN119127050A_ABST
Patent Text Reader

Abstract

The invention discloses a test case optimization method and device. The method comprises the following steps: acquiring a first coordinate of a mouse clicking in a target desktop according to a test case; the test case is used for testing a function of migrating an application program to an operating system where the target desktop is located; according to the first coordinate, a rectangular area is divided in the target desktop, and the rectangular area comprises a position corresponding to the first coordinate; the rectangular area is recognized to obtain a second coordinate, the second coordinate corresponds to the center position of a character area in the rectangular area, and the character area comprises the position corresponding to the first coordinate; and updating the first coordinate in the test case into the second coordinate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a test case optimization method and device. Background Art

[0002] At present, we are automatically testing the functions of applications when they are migrated to different operating systems by building test cases. The test cases contain the operation parameters of the mouse on the application, such as click interval, button type, click event type, click coordinates, etc.

[0003] However, there may be slight changes in the controls in the operating system to which the application is migrated. For example, there may be slight misalignment of controls between the desktops before and after the migration. The mouse click coordinates in the test case are fixed values, so after the application is migrated to a different operating system, there may be inaccurate mouse clicks on controls, resulting in test errors and low test reliability. Summary of the invention

[0004] In view of the above problems, the present application provides a test case optimization method and device to improve test reliability.

[0005] The specific plan is as follows:

[0006] The first aspect of the present application provides a test case optimization method, the method comprising:

[0007] Obtaining the first coordinate of a mouse click in a target desktop according to a test case; the test case is used to test the function of migrating an application to the operating system where the target desktop is located;

[0008] According to the first coordinate, a rectangular area is divided in the target desktop, and the rectangular area includes a position corresponding to the first coordinate;

[0009] Identify the rectangular area to obtain a second coordinate, where the second coordinate corresponds to the center position of a character area in the rectangular area, and the character area contains a position corresponding to the first coordinate;

[0010] The first coordinate in the test case is updated to the second coordinate.

[0011] In a possible implementation, the first coordinates are coordinates based on a desktop coordinate system of the target desktop; the area size of the rectangular area satisfies a recognition condition corresponding to an image recognition algorithm;

[0012] The step of identifying the rectangular area to obtain the second coordinates includes:

[0013] Using an image recognition algorithm, the rectangular area is identified to obtain the center coordinates of the character area in the rectangular area; the center coordinates are coordinates based on a regional coordinate system of the rectangular area;

[0014] According to the relationship between the desktop coordinate system and the regional coordinate system, coordinate transformation is performed on the center coordinate to obtain the second coordinate.

[0015] In a possible implementation, the rectangular area is identified by using an image recognition algorithm to obtain the center coordinates of the character area in the rectangular area, including:

[0016] Using an image recognition algorithm, the rectangular area is recognized to obtain vertex coordinates of a character area in the rectangular area, wherein the vertex coordinates are coordinates based on a regional coordinate system of the rectangular area;

[0017] According to the vertex coordinates, the center coordinates of the character area are obtained.

[0018] In a possible implementation, obtaining the center coordinates of the character area according to the vertex coordinates includes:

[0019] Obtaining the abscissa of the center coordinate of the character area according to the abscissa of the vertex coordinate and half the width of the character area in the horizontal axis direction;

[0020] The ordinate of the center coordinate is obtained according to the ordinate of the vertex coordinate and half the height of the character area in the ordinate direction.

[0021] In a possible implementation, the image recognition algorithm is: an optical character recognition algorithm.

[0022] In a possible implementation, performing coordinate transformation on the center coordinate according to the relationship between the desktop coordinate system and the regional coordinate system to obtain the second coordinate includes:

[0023] Obtaining the origin coordinates of the regional coordinate system according to the first coordinates and the regional size of the rectangular region, wherein the origin coordinates are the coordinates of the origin of the regional coordinate system based on the desktop coordinate system;

[0024] According to the origin coordinates, coordinate transformation is performed on the center coordinates to obtain the second coordinates.

[0025] In a possible implementation, the rectangular area is centered on the first coordinate;

[0026] Wherein, obtaining the origin coordinates of the regional coordinate system according to the first coordinates and the regional size of the rectangular region includes:

[0027] Subtract half the width of the rectangular area in the horizontal axis direction from the horizontal coordinate of the first coordinate to obtain the horizontal coordinate of the origin coordinate of the regional coordinate system;

[0028] The longitudinal coordinate of the origin coordinate is obtained by subtracting half the height of the rectangular area in the longitudinal axis direction from the longitudinal coordinate of the first coordinate.

[0029] In a possible implementation, performing coordinate transformation on the center coordinate according to the origin coordinate to obtain the second coordinate includes:

[0030] Add the abscissa of the origin coordinate to the abscissa of the center coordinate to obtain the abscissa of the second coordinate;

[0031] The ordinate of the origin coordinate is added to the ordinate of the center coordinate to obtain the ordinate of the second coordinate.

[0032] In a possible implementation, the test desktop corresponding to the test case has the same screen resolution as the target desktop.

[0033] A second aspect of the present application provides a test case optimization device, comprising:

[0034] A first coordinate obtaining unit, used to obtain a first coordinate of a mouse click in a target desktop according to a test case; the test case is used to test a function of migrating an application to an operating system where the target desktop is located;

[0035] A rectangular area division unit, configured to divide a rectangular area in the target desktop according to the first coordinate, wherein the rectangular area includes a position corresponding to the first coordinate;

[0036] A rectangular area recognition unit, used for recognizing the rectangular area to obtain a second coordinate, where the second coordinate is the center coordinate of a character area in the rectangular area, and the character area contains a position corresponding to the first coordinate;

[0037] A coordinate updating unit is used to update the first coordinate in the test case to the second coordinate.

[0038] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the test case optimization method of the above-mentioned first aspect or any implementation method of the first aspect.

[0039] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0040] The memory is used to store computer programs;

[0041] The processor is used to execute the computer program so that the electronic device can implement the test case optimization method of the above-mentioned first aspect or any implementation manner of the first aspect.

[0042] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement an optimization method for test cases of the above-mentioned first aspect or any implementation method of the first aspect.

[0043] By means of the above technical scheme, in a test case optimization method and device provided by the present application, after the application is migrated to the operating system where the target desktop is located, the first coordinate of the mouse clicking in the target desktop according to the corresponding test case is obtained, and then according to the first coordinate, a rectangular area containing the position corresponding to the first coordinate is divided in the target desktop, so that the second coordinate is obtained by identifying the rectangular area, and the second coordinate is the center coordinate of the character area in the rectangular area, thereby updating the first coordinate in the test case to the second coordinate. Therefore, in the present application, a rectangular area containing the mouse click position is divided in the target desktop and the area is identified, so that the center coordinate of the character area containing the mouse click position can be used to replace the coordinate of the mouse click position in the test case to optimize the test case, so that in the target desktop, when the mouse clicks according to the coordinates in the optimized test case, the mouse will click on the center coordinate of the character area, and there will be no mouse click errors due to slight changes in the target desktop after migration, so that there will be no test errors caused by slight changes in the target desktop after migration, thereby improving the reliability of the test. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0045] Figure 1 This is an example of right-clicking on the desktop in the test case;

[0046] Figure 2 This is an example of a drop-down menu that pops up after right-clicking in a test case;

[0047] Figure 3 This is an example diagram of the mouse operation actions in the desktop coordinate system recorded in the test case;

[0048] Figure 4 This is an example diagram of the computer screen coordinate system;

[0049] Figure 5 This is a sample picture of the upper left corner of the computer desktop;

[0050] Figure 6 This is an example of the recognition result of the upper left corner of the computer desktop;

[0051] Figure 7 A flowchart of an implementation method of a test case optimization method provided in an embodiment of the present application;

[0052] Figure 8 This is an example diagram of the first coordinate in the embodiment of the present application;

[0053] Fig. 9 This is an example diagram of a rectangular area in an embodiment of the present application;

[0054] Fig.10 This is an example diagram of coordinate conversion in the embodiment of the present application;

[0055] Fig.11 A partial flow chart of a test case optimization method provided in an embodiment of the present application;

[0056] Fig.12 This is an example diagram of coordinate conversion in the embodiment of the present application;

[0057] Fig.13 A schematic diagram of the structure of a test case optimization device provided in an embodiment of the present application;

[0058] Fig.14 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;

[0059] Fig.15 This is an example diagram of the mouse click position in the scenario of the Linux operating system optimization test case applicable to this application;

[0060] Fig.16 This is an example diagram of an extended rectangular area in a scenario where this application is applicable to a Linux operating system optimization test case;

[0061] Fig.17 This is an example diagram of coordinate transformation in a scenario where this application is applicable to Linux operating system optimization test cases. DETAILED DESCRIPTION

[0062] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0063] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0064] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0065] Test cases can also be understood as automated testing programs for applications. Automated testing programs can be used to test the functions of desktop applications for Windows, Linux, and MacOS operating systems. Regression testing after the software version of the application is upgraded can be completed by recording and testing repeatedly, which greatly reduces labor costs. For example, automated testing programs can be used to test the quality of Windows migration to a certain system software in environments such as software upgrades, different hardware, migration software versions, and system versions.

[0066] The test case records the fixed coordinate points of the mouse operation steps, and exports the test execution record data as a Python script to test the quality of the software in a complex environment with different hardware and software.

[0067] However, there are currently a large number of test cases with click position deviations, which leads to the failure of automated test case execution.

[0068] Take right-clicking to open a desktop computer shortcut as an example to describe the defects in the current test case. All operations record the test process in the desktop coordinate system, and the corresponding attached figure is a partial screenshot. The process is as follows:

[0069] S1: Right click to trigger the "Computer" button. Figure 1 As shown in , right-click "Computer" on the desktop, the mouse is in the desktop coordinate system, and the picture is the desktop picture (that is, the desktop full-screen picture).

[0070] The desktop image refers to the full-screen desktop image, whose width and height are consistent with the desktop resolution. For example, for a monitor with a resolution of 1920x1080, the corresponding desktop image is 1920 wide and 1080 high.

[0071] S2: Click the "Open" option button. Figure 2 As shown in the figure, S1 right-clicks "Computer" to pop up a drop-down menu, and clicks the "Open (O)" option.

[0072] S3: Analyze the data based on the above operation records. Figure 3 As shown in , what is recorded is the operation of the mouse in the desktop coordinate system. The mouse click operation of S1 corresponds to the 9th row of the recorded data ( Figure 3 The first column of numbers in the table represents the row number of the recorded data. The mouse click operation of S2 corresponds to the 13th row of the recorded data. Figure 3 The "Input Data" column shown in the table records the click coordinates of the mouse in the desktop coordinate system.

[0073] Among them, for the desktop coordinate system: the top left corner of the screen is the coordinate origin (0,0); the horizontal direction is the horizontal axis, i.e. the X-axis, and the maximum value of the X-axis (to the right) is the width of the desktop image; the vertical direction is the vertical axis, i.e. the Y-axis, and the maximum value of the Y-axis (downward) is the height of the desktop image; the range of the coordinates is the screen resolution.

[0074] Based on the above test cases, a python script is generated after processing the recorded data, which can be migrated to different environments for automated testing of the same software. Since the click position is continuous, the click position of S1 was originally the location of the "Computer" button; but when migrated to a different environment, the interface may change, resulting in the actual position of the "Computer" button in the desktop coordinate system. If the click coordinates recorded in the above recorded data are still used for testing, the "Computer" button will not be opened correctly during the test, and subsequent test steps will not be able to be executed.

[0075] It can be seen that the change in the button position in the adaptation software will lead to the wrong click position during the execution of the automated test (the test case records the fixed coordinate points of the operation steps), and the test cannot be executed correctly.

[0076] In view of this, the present application can solve this problem through image recognition. The implementation algorithm of image recognition can be optical character recognition algorithm OCR (Optical Character Recognition), but there are some defects. For example, the computer screen is a two-dimensional coordinate system, the upper left corner of the screen is (0,0), the horizontal right is the X axis, and the vertical downward is the Y axis. The range of the coordinates is the resolution of the screen, which is consistent with the desktop picture, such as Figure 4 as shown in .

[0077] In OCR recognition, if you input a desktop image, the correct recognition result may not be output. Figure 5 As shown, Figure 4The upper left corner of the desktop picture shown in Figure 4 When performing OCR recognition on the desktop image shown in Figure 5 The recognition result corresponding to the upper left corner of the desktop picture shown in is used as an example for explanation. Figure 5 The picture shown can be called a region picture, which refers to a small rectangular region picture in the desktop picture.

[0078] Figure 5 The recognition results of the area picture shown in Figure 6 As shown in the figure, the following recognition results are used as an example for explanation:

[0079] [[3.0,6.0],[280.0,7.0],[280.0,24.0],[3.0,23.0]],('Draw (D) Annotate (N) Modify () Espress Window ()',0.829702615737915)];

[0080] Among them, "[[3.0,6.0],[280.0,7.0],[280.0,24.0],[3.0,23.0]]" are the four point coordinates of the rectangular area corresponding to the recognition area text "Drawing (D) Annotation (N) Modify () Espress Window ()". It is obvious that the segmentation of text recognition in the recognition result is inaccurate. "Drawing (D) Annotation (N) Modify (M) Espress Window (W)" is recognized as a piece of regional text, and no regional text segmentation is performed for "Drawing", "Annotation", "Modify", "Espress" and "Window".

[0081] Based on this, it is impossible to obtain the coordinates of the center point of the rectangular area where the individual area text such as "Draw" is located. In the subsequent test process, if the "Draw" button is tested based on the test case obtained by the above OCR recognition result, when the click coordinate position corresponding to the "Draw" button recorded in the test case is clicked, the "Draw" button cannot be opened correctly in the test, and then the subsequent test steps cannot be executed. In addition, according to Figure 6 The recognition results obtained show that Figure 5 The text recognition in the area image shown is not complete. For example, using OCR recognition Figure 4 For the oversized image shown, if the image size exceeds the maximum height of 960 for OCR training, the text in the area with coordinates exceeding 960 in the image cannot be recognized.

[0082] Therefore, when OCR can correctly segment text and the recognition result is correct when recognizing an image, OCR can be used to optimize the test case in this application, that is, to correctly update the click position coordinates recorded in the test case.

[0083] In view of this, the embodiment of the present application provides a test case optimization method. The test case optimization method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0084] Reference Figure 7 , is a flow chart of an implementation of a test case optimization method provided in an embodiment of the present application, which method can be applied to electronic devices capable of data processing, such as electronic devices of an operating system where an application is migrated, such as a computer or server, etc. The technical solution in this embodiment is mainly used to optimize test cases to improve the test reliability of test cases for application programs.

[0085] Specifically, the method in this embodiment may include the following steps:

[0086] Step 701: Obtain the first coordinate of a mouse click on a target desktop according to a test case.

[0087] The test case is used to test the function of migrating the application to the operating system where the target desktop is located. The test desktop corresponding to the test case has the same screen resolution as the target desktop. For example, when recording the user's mouse operation data to obtain the test case, the screen resolution of the operating system used is 1920×1080, and the screen resolution of the operating system to which the application is migrated is also 1920×1080.

[0088] For example, Figure 8 As shown in , the mouse clicks the character "Open Window" on the target desktop, the desktop coordinate system of the target desktop takes the upper left corner as the origin of the coordinate system, and the resolution of the target desktop is 1920×1080. Correspondingly, the first coordinate is the coordinate of the mouse click position, the first coordinate is the coordinate based on the desktop coordinate system of the target desktop, and the first coordinate corresponding to the mouse click position is marked as P(X, Y).

[0089] It should be noted that the method of this embodiment can be executed when a test exception occurs during the test using the test case, or the technical solution of this embodiment can be executed for the test step in which the click position involves a character in the test case. In other words, the click position coordinates in each test step in which the click position involves a character in the test case can be optimized according to the technical solution of this embodiment; or the click position coordinates in the test step in which the click position involves a character and a test exception occurs in the test case can be optimized according to the technical solution of this embodiment.

[0090] Step 702: Divide a rectangular area on the target desktop according to the first coordinates.

[0091] The rectangular area includes the position corresponding to the first coordinate.

[0092] For example, Fig. 9 As shown in , the mouse clicks the characters “Open Window” on the target desktop, and then a rectangular area is divided on the target desktop, and the rectangular area includes the mouse click position P.

[0093] In a specific implementation, the rectangular area is centered at the position corresponding to the first coordinate P (X, Y). Fig. 9 As shown in , a rectangular area is divided in the target desktop with the mouse click position P as the center according to a pre-configured area size such as 64×32.

[0094] Step 703: Identify the rectangular area to obtain the second coordinates.

[0095] The second coordinate corresponds to the center position of the character area in the rectangular area, and the character area includes the position corresponding to the first coordinate.

[0096] For example, Fig.10 As shown in , the character area "Open Window" in the identification rectangular area containing the mouse click position is obtained to obtain the corresponding coordinates of the center position of the character area, and the corresponding second coordinate is marked as P3 (X3, Y3).

[0097] It should be noted that the first coordinate and the second coordinate are both coordinates based on the desktop coordinate system of the target desktop.

[0098] Step 704: Update the first coordinate in the test case to the second coordinate.

[0099] After the coordinates in the test case are updated, the function of migrating the application to the operating system where the target desktop is located can be tested according to the updated coordinates in the test case to obtain updated test results.

[0100] It can be seen from the above technical scheme that in a test case optimization method provided by an embodiment of the present application, after the application is migrated to the operating system where the target desktop is located, the first coordinates of the mouse click in the target desktop according to the corresponding test case are obtained, and then according to the first coordinates, a rectangular area containing the position corresponding to the first coordinates is divided in the target desktop. In this way, the rectangular area is identified to obtain the second coordinates, which are the center coordinates of the character area in the rectangular area, thereby updating the first coordinates in the test case to the second coordinates.

[0101] Therefore, in this embodiment, by dividing a rectangular area containing the mouse click position in the target desktop and performing area recognition, the center coordinates of the character area containing the mouse click position can be used to replace the coordinates of the mouse click position in the test case to optimize the test case. Therefore, in the target desktop, when the mouse clicks according to the coordinates in the optimized test case, the mouse will click on the center coordinates of the character area, and there will be no mouse click errors due to slight changes in the target desktop after migration, so that test errors caused by slight changes in the target desktop after migration will not occur, thereby improving the reliability of the test.

[0102] In one implementation, the first coordinate is a coordinate of a desktop coordinate system based on the target desktop, and the area size of the rectangular area satisfies the recognition condition corresponding to the image recognition algorithm.

[0103] Specifically, the image recognition algorithm may be an optical character recognition algorithm OCR. Accordingly, the recognition condition may be: the area size of the rectangular area is less than or equal to the size threshold, and the size threshold may be determined based on the maximum size that the OCR can accurately recognize, such as the maximum width is 1080 and the maximum height is 960. Accordingly, the width of the rectangular area is less than or equal to 1080, and the height of the rectangular area is less than or equal to 906. Furthermore, the rectangular area may be set to a lower size, thereby reducing the computational effort of the image recognition algorithm by reducing the area size of the rectangular area, thereby improving recognition efficiency. For example, the width of the rectangular area is 64 and the height is 32. This recognition condition enables the OCR to accurately recognize the area content in the rectangular area, such as characters and the coordinates of the characters.

[0104] Based on this, in step 703, when the rectangular area is identified to obtain the second coordinate, it can be implemented in the following manner: Fig.11 As shown in:

[0105] Step 1101: Using an image recognition algorithm, identify the rectangular area to obtain the center coordinates of the character area in the rectangular area.

[0106] The center coordinates are the coordinates of the regional coordinate system based on the rectangular area. The regional coordinate system based on the rectangular area takes the upper left corner vertex of the rectangular area as the coordinate origin (0,0); the horizontal direction (rightward) is the horizontal axis, i.e., the X-axis, and the maximum value of the X-axis is the width of the rectangular area; the vertical direction (downward) is the vertical axis, i.e., the Y-axis, and the maximum value of the Y-axis is the height of the rectangular area.

[0107] For example, Fig.12As shown in , the regional coordinate system based on the rectangular area takes the vertex of the upper left corner of the rectangular area as the origin of the coordinate system. In this embodiment, OCR can be used to recognize the characters in the rectangular area and the coordinates corresponding to the characters, so as to obtain the center position of the character area containing the mouse click position in the rectangular area and the center coordinates of the center position in the regional coordinate system. The coordinates of the center position of the character area in the regional coordinate system are the center coordinates of the character area, which are recorded as P1 (X1, Y1).

[0108] Specifically, in step 1101, an image recognition algorithm can be first used to identify the rectangular area to obtain the vertex coordinates of the character area in the rectangular area. The character area has four vertex coordinates, and the vertex coordinates are coordinates of the regional coordinate system based on the rectangular area; then, according to the vertex coordinates of the character area, the center coordinates P1 (X1, Y1) of the character area are obtained.

[0109] Among them, in step 1101, when obtaining the center coordinates P1 (X1, Y1) of the character area according to the vertex coordinates of the character area, the horizontal coordinate X1 of the center coordinate of the character area can be obtained according to the horizontal coordinate of a vertex coordinate of the character area and half the width of the character area in the horizontal axis direction; and the vertical coordinate Y1 of the center coordinate of the character area can be obtained according to the vertical coordinate of a vertex coordinate of the character area and half the height of the character area in the vertical axis direction.

[0110] The vertex coordinates of the origin of the coordinate system of the region closest to the rectangular region in the character region (such as Fig.12 Taking the vertex of the upper left corner of the character area as an example, the horizontal coordinate of the upper left vertex coordinate is added to half the width of the character area in the horizontal axis direction to obtain the horizontal coordinate of the center coordinate of the character area; and the vertical coordinate of the upper left vertex coordinate is added to half the height of the character area in the vertical axis direction to obtain the vertical coordinate of the center coordinate.

[0111] The vertex coordinates of the origin of the coordinate system of the region farthest from the rectangular region in the character region (such as Fig.12 Taking the vertex of the lower right corner of the character area as an example, the horizontal coordinate of the coordinate of the lower right corner vertex is subtracted from half the width of the character area in the horizontal axis direction to obtain the horizontal coordinate of the center coordinate of the character area; and the vertical coordinate of the coordinate of the lower right corner vertex is subtracted from half the height of the character area in the vertical axis direction to obtain the vertical coordinate of the center coordinate.

[0112] Step 1102: According to the relationship between the desktop coordinate system and the regional coordinate system, coordinate transformation is performed on the center coordinates of the character area in the rectangular area to obtain second coordinates.

[0113] Specifically, in step 1102, the center coordinates can be transformed according to the coordinates of the origin of the coordinate system of the regional coordinate system in the desktop coordinate system of the target desktop to obtain a second coordinate, which is the coordinates of the center position of the character area in the rectangular area in the desktop coordinate system.

[0114] In one implementation, the coordinate conversion in step 1102 can be implemented in the following manner:

[0115] First, according to the first coordinate P(X, Y) and the area size of the rectangular area, the origin coordinates of the regional coordinate system are obtained. The origin coordinates can be recorded as P2(X2, Y2), such as Fig.12 As shown in , the origin coordinates are the coordinates of the origin of the coordinate system of the regional coordinate system based on the desktop coordinate system. Taking the rectangular area centered on the first coordinate P (X, Y) as an example, the horizontal coordinate X of the first coordinate is subtracted from half the width of the rectangular area in the horizontal axis direction to obtain the horizontal coordinate X2 of the origin coordinate of the regional coordinate system; and the vertical coordinate Y of the first coordinate is subtracted from half the height of the rectangular area in the vertical axis direction to obtain the vertical coordinate Y2 of the origin coordinate. For example, X2 is X minus half of W, W is the width of the rectangular area in the horizontal axis direction, and Y2 is Y minus half of H, H is the height of the rectangular area in the vertical axis direction.

[0116] Then, according to the origin coordinates P2 (X2, Y2), the center coordinates P1 (X1, Y1) of the character area are converted to obtain the second coordinates P3 (X3, Y3). For example, the abscissa X2 of the origin coordinates is added to the abscissa X1 of the center coordinates to obtain the abscissa X3 of the second coordinates, and the ordinate Y2 of the origin coordinates is added to the ordinate Y1 of the center coordinates to obtain the ordinate Y3 of the second coordinates. For example, X3 is X2 plus X1, and Y3 is Y2 plus Y1.

[0117] A test case optimization method provided in an embodiment of the present application is introduced above, and a device for executing the above test case optimization method will be introduced below.

[0118] See also Fig.13 , is a schematic diagram of the structure of a test case optimization device provided in an embodiment of the present application. The device can be configured in an electronic device capable of data processing, such as an electronic device of an operating system where an application is migrated, such as a computer or a server. The technical solution in this embodiment is mainly used to optimize the test case to improve the test reliability of the test case of the application.

[0119] Specifically, the device in this embodiment may include the following units:

[0120] The first coordinate obtaining unit 1301 is used to obtain the first coordinate of the mouse clicking in the target desktop according to the test case; the test case is used to test the function of migrating the application to the operating system where the target desktop is located;

[0121] A rectangular area division unit 1302 is used to divide a rectangular area in the target desktop according to the first coordinate, wherein the rectangular area includes a position corresponding to the first coordinate;

[0122] A rectangular area recognition unit 1303 is used to recognize the rectangular area to obtain a second coordinate, where the second coordinate is the center coordinate of a character area in the rectangular area, and the character area contains a position corresponding to the first coordinate;

[0123] The coordinate updating unit 1304 is used to update the first coordinate in the test case to the second coordinate.

[0124] It can be seen from the above technical scheme that in a test case optimization device provided by an embodiment of the present application, after the application is migrated to the operating system where the target desktop is located, the first coordinate of the mouse clicking in the target desktop according to the corresponding test case is obtained, and then according to the first coordinate, a rectangular area containing the position corresponding to the first coordinate is divided in the target desktop, so that the second coordinate is obtained by identifying the rectangular area, and the second coordinate is the center coordinate of the character area in the rectangular area, thereby updating the first coordinate in the test case to the second coordinate. Therefore, in this embodiment, by dividing a rectangular area containing the mouse click position in the target desktop and performing area identification, the center coordinate of the character area containing the mouse click position can be used to replace the coordinate of the mouse click position in the test case to optimize the test case, so that in the target desktop, when the mouse clicks according to the coordinates in the optimized test case, the mouse will click on the center coordinate of the character area, and there will be no mouse click errors due to slight changes in the target desktop after migration, so that there will be no test errors caused by slight changes in the target desktop after migration, thereby improving the reliability of the test.

[0125] In one implementation, the first coordinates are coordinates based on a desktop coordinate system of the target desktop; the area size of the rectangular area satisfies a recognition condition corresponding to an image recognition algorithm;

[0126] Among them, the rectangular area recognition unit 1303 is specifically used to: use an image recognition algorithm to identify the rectangular area to obtain the center coordinates of the character area in the rectangular area; the center coordinates are the coordinates of the regional coordinate system based on the rectangular area; according to the relationship between the desktop coordinate system and the regional coordinate system, the center coordinates are converted to obtain the second coordinates.

[0127] Specifically, when the rectangular area recognition unit 1303 uses an image recognition algorithm to recognize the rectangular area to obtain the center coordinates of the character area in the rectangular area, it is specifically used to: use an image recognition algorithm to recognize the rectangular area to obtain the vertex coordinates of the character area in the rectangular area, the vertex coordinates are coordinates based on the regional coordinate system of the rectangular area; obtain the center coordinates of the character area according to the vertex coordinates. For example, according to the horizontal coordinates in the vertex coordinates and the half width of the character area in the horizontal axis direction, the horizontal coordinates in the center coordinates of the character area are obtained; according to the vertical coordinates in the vertex coordinates and the half height of the character area in the vertical axis direction, the vertical coordinates in the center coordinates are obtained.

[0128] Wherein, the image recognition algorithm is: optical character recognition algorithm.

[0129] In one implementation, when the rectangular area identification unit 1303 performs coordinate transformation on the center coordinate according to the relationship between the desktop coordinate system and the area coordinate system to obtain the second coordinate, it is specifically used to: obtain the origin coordinates of the area coordinate system according to the first coordinates and the area size of the rectangular area, and the origin coordinates are the coordinates of the origin of the coordinate system of the area coordinate system based on the desktop coordinate system; perform coordinate transformation on the center coordinate according to the origin coordinates to obtain the second coordinate, for example, adding the horizontal coordinate in the origin coordinate to the horizontal coordinate in the center coordinate to obtain the horizontal coordinate in the second coordinate; adding the vertical coordinate in the origin coordinate to the vertical coordinate in the center coordinate to obtain the vertical coordinate in the second coordinate.

[0130] Among them, the rectangular area is centered on the first coordinate; when the rectangular area identification unit 1303 obtains the origin coordinates of the area coordinate system according to the first coordinate and the area size of the rectangular area, it is specifically used to: subtract half the width of the rectangular area in the horizontal axis direction from the horizontal coordinate in the first coordinate to obtain the horizontal coordinate in the origin coordinate of the area coordinate system; subtract half the height of the rectangular area in the vertical axis direction from the vertical coordinate in the first coordinate to obtain the vertical coordinate in the origin coordinate.

[0131] Among them, the test desktop corresponding to the test case has the same screen resolution as the target desktop.

[0132] It should be noted that the specific implementation method of each unit in this embodiment can refer to the corresponding content in the previous text and will not be described in detail here.

[0133] An embodiment of the present application further provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0134] The memory is used to store computer programs;

[0135] The processor is used to execute the computer program so that the electronic device can implement the test case optimization method of the above-mentioned first aspect or any implementation manner of the first aspect.

[0136] Specifically, refer to Fig.14 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include but is not limited to fixed terminals such as mobile phones, notebook computers, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Fig.14 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0137] like Fig.14 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 1401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1402 or a program loaded from a storage device 1408 into a random access memory (RAM) 1403, to implement an optimization method for any test case provided in an embodiment of the present application. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in RAM 1403. Processing device 1401, ROM 1402, and RAM 1403 are connected to each other via bus 1404. Input / output (I / O) interface 1405 is also connected to bus 1404.

[0138] Typically, the following devices may be connected to the I / O interface 1405: an input device 1406 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 1407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1408 including, for example, a memory card, a hard disk, etc.; and a communication device 1409. The communication device 1409 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Fig.14 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0139] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements an optimization method for any test case provided in the embodiment of the present application.

[0140] A computer storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement an optimization method for any test case provided in an embodiment of the present application.

[0141] Taking the migration environment of the Linux operating system as an example, the technical solution of this application is described below:

[0142] First, before the test starts, the steps with text will be marked with text. If there are steps with text marks, text recognition will be performed to update the coordinates of the click position. If there are no marks, the original recorded coordinate points will be used. The following case takes the right-click desktop shortcut "Computer" as an example, and the right-click step is marked with text recognition. The recorded data corresponds to this step with a "Computer" description field:

[0143] The specific plan is as follows:

[0144] S01: When a test exception occurs, the click point position coordinates corresponding to the test exception operation are obtained, that is, the first coordinates corresponding to the mouse click position in the previous text.

[0145] Among them, any mouse operation is in the desktop coordinate system. During the execution of the test case, all mouse click positions will be recorded. The coordinate point of the mouse click is the first coordinate, recorded as P(X,Y). The coordinate point P(X,Y) of the mouse click is also called the center point coordinate of the rectangular area, where P(X,Y) is the coordinate based on the desktop coordinate system. The desktop coordinate area is marked as area A. Assume that the location of the click point corresponding to the current test exception is "computer", such as Fig.15 as shown in .

[0146] S02: Get the area image.

[0147] Expand a rectangular area with the click position P(X,Y) as the center point. For example, you can set the width W of the expanded rectangular area to 64 and the height H to 32. W and H can be customized according to actual needs. The expanded rectangular area is marked as area B. Fig.16 shown.

[0148] S03: Get the regional text position.

[0149] Perform OCR recognition on the extended area image B to obtain the coordinates of the four vertices of the recognized text area, that is, the vertex coordinates of the character area in the previous text.

[0150] It should be noted that the coordinates of the four vertices obtained by identification correspond to the regional coordinate system where the regional image B is located. Based on the regional coordinate system, the coordinates of the origin of the upper left corner of the regional image B are (0, 0).

[0151] At this time, based on the vertex coordinates of the four vertices of the recognized text area in the regional coordinate system, the regional coordinates P1 (X1, Y1) of the center point of the recognized text area are calculated. Among them, P1 (X1, Y1) corresponds to the regional coordinate system, and the same is true if multiple characters are recognized in the area. Fig.17 As shown in , after OCR recognition, the center point area coordinates P1 of the "computer" text area can be obtained, and the center point area coordinates P1 are coordinates based on the coordinate system where the area image B is located.

[0152] like Fig.17 As shown, the upper left corner of area image B is the origin. After OCR recognition of area image B, OCR will draw a rectangular box, namely the text area (the character area in the previous text), with the recognized text, and return the coordinates of the four vertices of the recognized text rectangular box (i.e. the vertex coordinates in the previous text). The center point area coordinates P1 of the click position text "Computer" are calculated by the coordinates of the four vertices of the recognized text area.

[0153] S04: Text coordinate mapping.

[0154] In the above steps, the image where the text area is located is based on the regional coordinate system, and the center point regional coordinate P1 is also based on the coordinates of the regional coordinate system. Therefore, the center point regional coordinate P1 needs to be mapped to the desktop coordinate system. Specifically, the following calculations need to be performed:

[0155] By clicking the position coordinates P(X,Y), combined with the width W and height H of area B, calculate the coordinate point P2(X2,Y2) of the upper left corner of area B in the desktop coordinate system, that is, Fig.17 The coordinates of the upper left corner of area B in the desktop coordinate system are calculated as shown in formula (1) and formula (2):

[0156] X2=XW / 2 (1)

[0157] Y2=YH / 2 (2)

[0158] From P2 (X2, Y2) and the coordinates of the center point of the recognized text area P1 (X1, Y1), the position P3 (X3, Y3) of the center point of the recognized text area in the desktop coordinate system is calculated by the offset. The offset is the coordinates of the four points of the rectangular area of ​​the text in the area B coordinate system. The coordinates of the center position of the text, that is, the second coordinate P3 (X3, Y3), are calculated as shown in formula (3) and formula (4):

[0159] X3=X2+X1 (3)

[0160] Y3=Y2+Y1 (4)

[0161] S05: Update the click point coordinates.

[0162] Through S04 calculation, the data recorded in the test case is updated. If the text position is calculated by the above steps for the original click position, the click point position coordinates corresponding to the test abnormal operation in the original record are updated. That is, the first coordinate P (X, Y) originally recorded in the test case is replaced with the second coordinate P3 (X3, Y3) obtained by the above calculation, and then the test is executed again.

[0163] Therefore, the technical solution of the present application can solve the error problems caused by OCR technology when performing text recognition on ultra-high resolution images and the defect of being unable to obtain the coordinates of the text in the desktop coordinate system, and can be applied to projects such as automated testing that require accurate acquisition of click position coordinates to lock the target point.

[0164] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0165] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0166] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0167] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A test case optimization method, characterized in that: The method comprises: Obtaining the first coordinate of a mouse click in a target desktop according to a test case; the test case is used to test the function of migrating an application to the operating system where the target desktop is located; According to the first coordinate, a rectangular area is divided in the target desktop, and the rectangular area includes a position corresponding to the first coordinate; Identify the rectangular area to obtain a second coordinate, where the second coordinate corresponds to the center position of a character area in the rectangular area, and the character area contains a position corresponding to the first coordinate; The first coordinate in the test case is updated to the second coordinate.

2. The method according to claim 1, characterized in that: The first coordinates are coordinates based on the desktop coordinate system of the target desktop; the area size of the rectangular area meets the recognition condition corresponding to the image recognition algorithm; The step of identifying the rectangular area to obtain the second coordinates includes: Using an image recognition algorithm, the rectangular area is identified to obtain the center coordinates of the character area in the rectangular area; the center coordinates are coordinates based on a regional coordinate system of the rectangular area; According to the relationship between the desktop coordinate system and the regional coordinate system, coordinate transformation is performed on the center coordinate to obtain the second coordinate.

3. The method according to claim 2, characterized in that Using an image recognition algorithm to identify the rectangular area to obtain the center coordinates of the character area in the rectangular area includes: Using an image recognition algorithm, the rectangular area is recognized to obtain vertex coordinates of a character area in the rectangular area, wherein the vertex coordinates are coordinates based on a regional coordinate system of the rectangular area; According to the vertex coordinates, the center coordinates of the character area are obtained.

4. The method according to claim 3, characterized in that Obtaining the center coordinates of the character area according to the vertex coordinates includes: Obtaining the abscissa of the center coordinate of the character area according to the abscissa of the vertex coordinate and half the width of the character area in the horizontal axis direction; The ordinate of the center coordinate is obtained according to the ordinate of the vertex coordinate and half the height of the character area in the ordinate direction.

5. The method according to claim 2, characterized in that: According to the relationship between the desktop coordinate system and the regional coordinate system, coordinate transformation is performed on the center coordinate to obtain the second coordinate, including: Obtaining the origin coordinates of the regional coordinate system according to the first coordinates and the regional size of the rectangular region, wherein the origin coordinates are the coordinates of the origin of the regional coordinate system based on the desktop coordinate system; According to the origin coordinates, coordinate transformation is performed on the center coordinates to obtain the second coordinates.

6. The method according to claim 5, characterized in that The rectangular area is centered on the first coordinate; Wherein, obtaining the origin coordinates of the regional coordinate system according to the first coordinates and the regional size of the rectangular region includes: Subtract half the width of the rectangular area in the horizontal axis direction from the horizontal coordinate of the first coordinate to obtain the horizontal coordinate of the origin coordinate of the regional coordinate system; The longitudinal coordinate of the origin coordinate is obtained by subtracting half the height of the rectangular area in the longitudinal direction from the longitudinal coordinate of the first coordinate.

7. The method according to claim 5, characterized in that According to the origin coordinates, the center coordinates are transformed to obtain the second coordinates, including: Add the abscissa of the origin coordinate to the abscissa of the center coordinate to obtain the abscissa of the second coordinate; The ordinate of the origin coordinate is added to the ordinate of the center coordinate to obtain the ordinate of the second coordinate.

8. The method according to claim 1, characterized in that The test desktop corresponding to the test case has the same screen resolution as the target desktop.

9. A test case optimization device, characterized in that: include: A first coordinate obtaining unit, used to obtain a first coordinate of a mouse click on a target desktop according to a test case; The test case is used to test the function of migrating the application to the operating system where the target desktop is located; A rectangular area division unit, configured to divide a rectangular area in the target desktop according to the first coordinate, wherein the rectangular area includes a position corresponding to the first coordinate; A rectangular area recognition unit, used for recognizing the rectangular area to obtain a second coordinate, where the second coordinate is the center coordinate of a character area in the rectangular area, and the character area contains a position corresponding to the first coordinate; A coordinate updating unit is used to update the first coordinate in the test case to the second coordinate.

10. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the test case optimization method described in any one of claims 1 to 8 above.

11. A computer storage medium, wherein the storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the test case optimization method described in any one of claims 1 to 8.