An automated testing method based on image comparison
By using an automated testing method based on image comparison, the problem of existing tools being unable to handle complex image elements is solved, enabling efficient and accurate generation and reporting of test results, thus improving testing efficiency and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SSE INFORMATION NETWORK LTD
- Filing Date
- 2024-08-08
- Publication Date
- 2026-04-28
AI Technical Summary
Existing automated testing tools struggle to effectively identify and compare complex image elements, resulting in limited test coverage and accuracy, and failing to meet the needs of diverse testing scenarios.
Design an automated testing method based on image comparison. Obtain webpage links through depth-first traversal, use Selenium to obtain webpage screenshots, convert them into grayscale images, calculate the structural similarity index, identify differences, and generate reports, reducing manual intervention.
It achieves automated and accurate image comparison, generates clear reports, improves testing efficiency and accuracy, reduces error rates, and saves manpower and resources.
Smart Images

Figure CN119088679B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automated testing, specifically an automated testing method based on image comparison. Background Technology
[0002] In today's rapidly evolving testing field, automated testing has become a key means to improve testing efficiency and accuracy. However, existing automated testing solutions mainly focus on interface testing, that is, verifying whether the interaction between systems meets expectations through well-defined interface specifications. In contrast, automated solutions for image comparison testing are relatively few, indicating that development in this area is significantly lagging behind.
[0003] Existing automated testing tools often have limited functionality and struggle to meet the diverse testing scenarios faced by testers. These tools frequently fail to effectively identify and compare complex image elements, resulting in limited test coverage and accuracy. As software applications become increasingly diverse and user demands for better experience grow, testing teams urgently need more intelligent, flexible, and comprehensive automated testing tools to address the increasing testing needs. These tools should be able to handle various complex image comparison tasks, reduce manual intervention, and provide more accurate and reliable test results, thereby improving software quality and shortening time-to-market. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of existing technologies and provide an automated testing method based on image comparison. This method automates the comparison of differences in the front-end display of new and old web pages, automatically generates detailed reports, reduces manual operation, significantly lowers the error rate, and saves manpower and resources. Users can easily analyze the comparison results, optimize the testing process, and improve accuracy and efficiency.
[0005] To achieve the above objectives, an automated testing method based on image comparison is designed. The steps of the method are as follows: S1 Generate test cases: Access the target website through depth-first traversal and obtain data from the front end of the target website. Extract sublinks and backlinks from the website using tagging or regular expression matching. Choose the traversal depth based on business needs and repeat the above steps to obtain deeper sublinks. S2 Matching and Comparison Parameters: Organize the parameter data required for image comparison and maintain it in two Excel files of a specified template in a one-to-one correspondence order. S3 Collecting and Comparison Data: Access the webpage links maintained in the table, adjust the browser's width and height to the maximum webpage size. Figure 1 S3: Obtain two sets of webpage screenshots and save them to a specified path; S4: Process comparison data: Obtain two images to be compared according to the specified path in step S3 and convert the images into grayscale images. Calculate the structural similarity index between the two grayscale images, identify the contours of different points between the two grayscale images and mark them with rectangles, and save the marked images to an HTML file; S5: Generate report: Write the relevant details of the image comparison into an Excel file, compress it together with the difference file finally generated in step S4 to generate an image comparison report file; S6: Send report: Configure the recipient's email address and send the image comparison report file from step S5 to relevant business personnel.
[0006] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S1 specifically includes: S1.1 Accessing the target website through Selenium, retrieving the complete page source code of the website, and performing regular expression matching or obtaining... S1.1 Retrieves all sublinks and backlinks of the website using tags; S1.2 Removes PDF, PPT, RAR, ZIP, DOC, and XLS format files from the website's sublinks and backlinks, and performs deduplication. After deduplication, the website's sublinks and backlinks are added to a list; S1.3 Selects the required traversal depth according to business needs, iterates through the sublinks obtained in step S1.2, visits these sublinks in turn, extracts the complete page source code of the sublinks, and performs regular expression matching or extraction... S1.4 Extract all sublinks and backlinks contained in the website using the tag placement method; S1.5 Remove PDF, PPT, RAR, ZIP, DOC, and XLS format files from the website's sublinks and backlinks, and put all the obtained sublinks and backlinks into a single list for deduplication; S1.6 Write the sublinks and backlinks in the list into an Excel file.
[0007] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S2 specifically includes: S2.1 filling in the data task number ID, task name and corresponding website column URL corresponding to a set of test cases in the first specified template Excel file. If network fluctuations cause the final generated image to be incompletely displayed, the waiting time is filled in the table, the time is in seconds, and the comparison path in the configuration file is modified.
[0008] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S3 specifically includes: S3.1 Opening the second specified template Excel file, and filling in the relevant data of another set of test cases to be compared with the first specified template Excel file in the same way as step S2.1. When maintaining the two sets of data, ensure that the URL sequence numbers of the website columns to be compared are applied one-to-one to reduce errors that occur during comparison; S3.2 Looping through the corresponding website column URLs in the specified template Excel file, accessing them sequentially using Google Chrome through the Selenium framework, and calculating the maximum webpage screenshot of Google Chrome. Setting the browser's width and height to the width and height of the maximum webpage screenshot, and saving the image after taking the screenshot.
[0009] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S4 specifically includes: S4.1 Reading two images to be compared, the read image format is BGR, and converting the two BGR format images into grayscale images; S4.2 Calculating the structural similarity index between the two grayscale images, and classifying the comparison results according to the structural similarity and size, the classification results include: matching, inconsistency, comparison failure - size difference, and comparison failure - unknown anomaly; S4.3 If the comparison result is: inconsistency, then identifying the contours of the different points between the two grayscale images and marking them with rectangles, and storing the inconsistent comparison results, the identified images, and other comparison results together in the report; S4.4 Saving the comparison images marked with differences to an HTML file.
[0010] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S5 specifically includes: S5.1 saving all comparison files in a specified path, creating an Excel spreadsheet in the specified path and writing the comparison name and comparison result of each test case after comparison for business personnel to review, setting a jump link for each test case, and clicking the link will jump to an HTML page that marks the image differences corresponding to that test case.
[0011] Preferably, the automated testing method based on image comparison provided by the present invention also has other technical features, wherein step S6 specifically includes: S6.1 configuring the recipient's email address, compressing the above-mentioned comparison report file and sending it to the relevant business personnel.
[0012] Compared with the prior art, the advantages of this invention are:
[0013] A. Compared with the existing manual comparison, it eliminates complicated processes, saves time and manpower, and facilitates management and maintenance.
[0014] B. This invention uses the automated testing tool Selenium to write scripts to traverse and generate sub-links, then writes these sub-links into a test case table, captures a screenshot of the webpage for each sub-link, compares and analyzes the two sets of images, generates a comparison report, and sends it to relevant business personnel. On the one hand, using scripts to traverse website links significantly reduces the cost of manual test case maintenance.
[0015] C. Precise image comparison ensures the reliability of test case execution results and solves the problem of defects not being exposed due to comparison of a single interface. Clear comparison reports also facilitate understanding and analysis by business personnel. Attached Figure Description
[0016] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0017] To make the purpose, principle and structure of the present invention clearer, the following description is provided in conjunction with the accompanying drawings and specific embodiments.
[0018] This invention addresses increasingly diverse testing needs by disclosing an automated testing method based on image comparison. Specifically, it includes the following steps: deeply traversing the sub-links of the target website and maintaining the required comparison links in an Excel file with a specified template; obtaining two sets of images based on the links maintained in the table; comparing the two sets of images one by one; marking the differences between the two sets of images; generating a comparison report and sending the report via email. This application enables faster image comparison, while automating and accurately performing difference comparison and report generation, saving manpower and resources, significantly reducing the error rate, and facilitating easier analysis of the comparison results.
[0019] See Figure 1 To achieve the above objectives, an automated testing method based on image comparison is designed, and the method is as follows:
[0020] A. Access the target website, through the front end... Extract the sublinks and backlinks contained in the website using tags or regular expression matching. Select the depth to traverse based on business needs, and repeat the above operation to obtain deeper sublinks of the webpage.
[0021] B. Organize the required webpage links, task names, waiting times, and other data for comparison, and maintain them in two Excel files of the specified template in a one-to-one correspondence order;
[0022] C. Access the webpage links maintained in the table, and set the browser's width and height to match the maximum page view. Figure 1 This allows us to obtain two sets of webpage screenshots and place them in a specified path.
[0023] D. Obtain two images to be compared according to the specified path in step three, convert them to grayscale, calculate the structural similarity index between the two grayscale images, find the contours of the different points so that we can place rectangles around the areas marked as "different", and finally save the images with difference markers to an HTML file.
[0024] E. Write the relevant comparison details into an Excel file, and compress it together with the difference file generated in step four to generate a comparison report file;
[0025] F. Configure the recipient's email address and send the comparison report file from step five to the relevant business personnel.
[0026] Example 1:
[0027] According to this embodiment, an automated testing method based on image comparison is provided. This method is used to compare the differences in data and style displayed on the front end of new and old pages, and generates a comparison report for testers to analyze after the comparison is completed.
[0028] The method includes:
[0029] S1: Generate test cases;
[0030] Configure the website to be tested in the depth-first traversal script, set the traversal depth according to the requirements, and run the depth-first traversal script. The script will generate a table of child links and backlinks obtained after traversal.
[0031] The depth-first search script uses the Selenium automated testing tool to access the target website, retrieves the website's page source code, and then uses regular expressions to match or extract the data. The system retrieves all links contained on the current page using tags, removes all links to PDF, PPT, RAR, ZIP, DOC, and XLS files, and deduplicates the remaining links. Finally, it stores these links in a table categorized by sublinks and external links. If multiple levels need to be traversed, the above process is repeated to generate new sublinks based on existing ones.
[0032] When maintaining the test case table, write the sub-links and external links obtained in the previous step into the template file of the comparison test cases as needed. At the same time, write the task name, waiting time and other data for each test case. Make a copy and replace its domain name with the domain name of the webpage to be compared. Modify the file name of the comparison test case file and place these two files in the specified location of the script.
[0033] S2: Image comparison;
[0034] Modify the required parameters of the image alignment script and run the shell file containing the image alignment script.
[0035] The internal logic of the image comparison script is as follows: Iterate through the corresponding website category URLs in the Excel file, open Google Chrome through the Selenium automated testing tool to visit them one by one, calculate the maximum webpage screenshot size of Google Chrome, set the browser's width and height to the width and height of the maximum webpage screenshot, and save the image after taking the screenshot.
[0036] The `cv2.imread()` interface is used to read two images to be compared. The images read by this method are in BGR format. The `cv2.cvtColor()` interface is used to convert the two BGR format images into grayscale images. The `compare_ssim` interface is used to calculate the structural similarity index between the two grayscale images. Based on the structural similarity and size, the comparison results are divided into four types: "matching", "inconsistent", "comparison failed (size difference)", and "comparison failed (unknown anomaly)". If the comparison result is "inconsistent", the contours of the different points are found so that rectangles can be placed around the areas marked as "different". Other cases will also be presented in the final report. Finally, the comparison images marked with differences are saved to an HTML file.
[0037] S3: Generate and send reports;
[0038] Save all comparison files in the specified path. Create an Excel spreadsheet in this path and write the comparison name and result of each test case for business personnel to review. Set a jump link for each test case. Clicking the link will jump to the HTML page that marks the image differences corresponding to that test case. Configure the recipient's email address, compress the above comparison report file and send it to the relevant business personnel.
[0039] The above description is merely a specific embodiment of the invention, but the scope of protection of the invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in this invention, based on the technical solutions and novel concepts of the invention, should be covered within the scope of protection of this invention.
Claims
1. An automated testing method based on image comparison, characterized in that, The steps of the method are as follows: S1 generates test cases: It accesses the target website through depth-first traversal and obtains data from the target website's front end. Extract the sublinks and backlinks contained in the website using tagging or regular expression matching. Select the depth of traversal required according to business needs, repeat the above operation to obtain deeper sublinks of the webpage, and write the obtained sublinks and backlinks into an Excel file with a specified template. S2 Matching and Comparison Parameters: Organize the parameter data required for image comparison, and maintain the links obtained in step S1 in a one-to-one correspondence order in two Excel files of the specified template; S3 Data Collection and Comparison: Access the webpage links maintained in the table of step S2, adjust the browser width and height to match the maximum webpage screenshot, obtain two sets of webpage screenshot images, and save the images in the specified path; S4 Processing comparison data: According to the specified path in step S3, two images to be compared are obtained and converted into grayscale images. The structural similarity index between the two grayscale images is calculated, the contours of the different points between the two grayscale images are identified and marked with rectangles, and the images marked with differences are saved to an HTML file. S5 Report Generation: Write the relevant details of image comparison into an Excel file, and compress it together with the difference file finally generated in step S4 to generate an image comparison report file; S6 Report Sending: Configure the recipient's email address and send the image comparison report file from step S5 to the relevant business personnel.
2. The automated testing method based on image comparison as described in claim 1, characterized in that, Step S1 specifically includes: S1.1 Accesses the target website via Selenium, extracts the complete page source code of the website, and uses regular expressions to match or retrieve... Retrieve all child links and external links contained in the website using tags; S1.2 Remove PDF, PPT, RAR, ZIP, DOC, and XLS format files from the website's sublinks and external links, and perform deduplication. After deduplication, add the website's sublinks and external links to a list. S1.3 Select the required traversal depth based on business needs, iterate through the sub-links obtained in step S1.2, visit each sub-link sequentially, extract the complete page source code of the sub-links, and then use regular expressions to match or obtain... The tag-based method retrieves all child links and external links contained in the website; S1.4 Remove PDF, PPT, RAR, ZIP, DOC, and XLS format files from the website's sublinks and backlinks, and put all the resulting sublinks and backlinks into the same list for deduplication; S1.5 writes the sub-links and external links in the list to an Excel file.
3. The automated testing method based on image comparison as described in claim 2, characterized in that, Step S2 specifically includes: S2.1 In the first specified template Excel file, fill in the data task number ID, task name and corresponding website column URL corresponding to a set of test cases. If network fluctuations cause the final generated image to be incomplete, fill in the waiting time in the table. The time is in seconds. Also, modify the comparison path in the configuration file.
4. The automated testing method based on image comparison as described in claim 3, characterized in that, Step S3 specifically includes: S3.1 Open the second specified template Excel file, and fill in the relevant data of another set of test cases to be compared with the first specified template Excel file in the same way as step S2.
1. When maintaining the two sets of data, ensure that the URL sequence numbers of the website columns to be compared are one-to-one to reduce the errors that occur during the comparison. S3.
2. Loop through the corresponding website category URLs in the Excel file of the specified template, access them one by one using Google Chrome through the Selenium framework, calculate the maximum page screenshot size of Google Chrome, set the browser's width and height to the width and height of the maximum page screenshot, and save the image after taking the screenshot.
5. The automated testing method based on image comparison as described in claim 1, characterized in that, Step S4 specifically includes: S4.1 reads two images that need to be compared. The images are in BGR format. The two BGR images are then converted to grayscale images. S4.2 Calculate the structural similarity index between two grayscale images, and classify the comparison results according to the structural similarity and size. The classification results include: matching, inconsistency, comparison failure - size difference, and comparison failure - unknown anomaly. S4.3 If the comparison result is: there is inconsistency, then identify the contours of the different points between the two grayscale images and mark them with rectangles, and store the inconsistent comparison result, the identified image and other comparison results together in the report; S4.4 saves the comparison images marked with differences to an HTML file.
6. The automated testing method based on image comparison as described in claim 1, characterized in that, Step S5 specifically includes: S5.1 Saves all comparison files in a specified path. Create an Excel spreadsheet in this path and write the comparison name and comparison result of each test case for business personnel to review. Set a jump link for each test case. Clicking the link will jump to an HTML page that marks the image differences corresponding to that test case.
7. The automated testing method based on image comparison as described in claim 1, characterized in that, Step S6 specifically includes: S6.1 Configure the recipient's email address, compress the above comparison report file, and send it to the relevant business personnel.
Citation Information
Patent Citations
Automatic difference detection method and device based on crawler
CN103365967A
Website vulnerability test method, server and system
CN108667770A