Page automation testing methods, apparatus, computer equipment, and storage media
By identifying and processing CAPTCHA types and using image processing technology to obtain CAPTCHA content, the inaccuracy problem caused by CAPTCHAs in automated page testing is solved, ensuring the accuracy and consistency of test results.
Patent Information
- Application Number
- CN202210224743.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-07
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-03-07
AI Technical Summary
In existing technologies for automated page testing, the presence of CAPTCHAs leads to inaccurate testing, and modifying the page program code can cause test results to differ from actual results.
By identifying the CAPTCHA type and calling the corresponding CAPTCHA address to download the image or crop the CAPTCHA area, optical character recognition is performed using an image processing library to obtain the CAPTCHA content, which is then used as a test input parameter to avoid modifying the page program code.
This ensures the accuracy of automated page testing and the clarity of CAPTCHA content without altering the page's program logic structure, thus avoiding discrepancies between test results and actual results.
Smart Images

Figure CN114610611B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method, apparatus, computer device, and storage medium for automated page testing. Background Technology
[0002] With the development of computer technology, more and more websites are using CAPTCHAs to distinguish between bots and users. While CAPTCHAs prevent malicious bots from automatically registering, logging in, and spamming, they also pose challenges to automated testing of website pages.
[0003] Traditionally, automated website page testing is achieved by having website developers remove CAPTCHAs from the pages or add a universal CAPTCHA. However, this method requires modifying the code logic structure of the page program itself, which can lead to inconsistencies between the tested page program and the actual live page program, thus compromising the accuracy of automated page testing. Summary of the Invention
[0004] Therefore, it is necessary to provide a page automated testing and processing method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can guarantee accuracy in addressing the aforementioned technical problems.
[0005] Firstly, this application provides a method for automated page testing. The method includes:
[0006] Identify CAPTCHA elements in the target page based on automated page testing scripts;
[0007] Identify the verification code type corresponding to the verification code element;
[0008] If the verification code type is a non-same-origin verification code, then the verification code address corresponding to the verification code element is called to download the verification code image; the non-same-origin verification code is used to indicate that the verification code address uniquely corresponds to a verification code image;
[0009] The verification code image is recognized to obtain the verification code content;
[0010] The verification code content is used as input parameter, and corresponding page automated tests are performed based on the page automated test script.
[0011] In one embodiment, the method further includes:
[0012] If the verification code type is a same-origin verification code, then crop the area where the verification code element is located on the target page to obtain a screenshot of the verification code;
[0013] The screenshot of the verification code is recognized to obtain the content of the verification code.
[0014] In one embodiment, the method further includes:
[0015] Take a full-screen screenshot of the target page to obtain a page image;
[0016] If the verification code type is a same-origin verification code, then cropping the area where the verification code element is located on the target page to obtain the verification code screenshot includes:
[0017] If the verification code type is a same-origin verification code, then call the image processing library to crop the area where the verification code element is located on the target page to obtain a screenshot of the verification code;
[0018] The process of recognizing the screenshot of the verification code to obtain the verification code content includes:
[0019] The image verification code recognition library is called to recognize the screenshot of the verification code and obtain the verification code content.
[0020] In one embodiment, if the verification code type is a same-origin verification code, then cropping the area where the verification code element is located on the target page to obtain a verification code screenshot includes:
[0021] Take a full-screen screenshot of the target page to obtain a page image;
[0022] If the verification code type is a same-origin verification code, then the page position attribute information of the verification code element is extracted from the attribute information of the verification code element;
[0023] The page image area where the verification code element is located is determined based on the page location attribute information;
[0024] A screenshot of the verification code is obtained by cropping a region of the page image from the page image.
[0025] In one embodiment, the method further includes:
[0026] Determine the operating system executing the page automation test script to obtain the interface scaling factor of the operating system;
[0027] The step of determining the page image area where the verification code element is located based on the page position attribute information includes:
[0028] The page image area where the verification code element is located is determined according to the interface scaling factor and the page position attribute information.
[0029] In one embodiment, the page automation test script runs in a browser; the method further includes:
[0030] Obtain browser type parameters from the page automation test script;
[0031] If the browser type parameter indicates a browser with a user interface, then control the browser to run the page automated test script with a user interface.
[0032] If the browser type parameter indicates a headless browser, then control the browser to run the page automated test script without a user interface.
[0033] In one embodiment, the verification code type corresponding to the verification code element includes:
[0034] Extract the verification code address from the attribute information of the verification code element;
[0035] Repeatedly call the verification code address to download the verification code image to obtain multiple verification code images;
[0036] If the multiple verification code images are identical, it indicates that the verification code type corresponding to the verification code element is a non-same-source verification code;
[0037] If the multiple CAPTCHA images are inconsistent, it indicates that the CAPTCHA type corresponding to the CAPTCHA elements is a common-source CAPTCHA.
[0038] In one embodiment, the step of using the verification code content as an input parameter and performing corresponding page automated testing based on the page automated testing script includes:
[0039] The verification code content is input into the target page as an input parameter based on the page automation test script;
[0040] After receiving information from the target page indicating an error in the verification code content, a retry mechanism is triggered to re-execute the step of calling the verification code address corresponding to the verification code element to download the verification code image if the verification code type is a non-same-origin verification code, until the target page returns information indicating that the verification code content is correct or the retry stop condition is met, and then the retry stops.
[0041] Secondly, this application also provides an automated page testing processing device. The device includes:
[0042] The determination module is used to identify CAPTCHA elements in a target page based on page automation test scripts.
[0043] The identification module is used to identify the type of verification code corresponding to the verification code element; if the verification code type is a non-same-origin verification code, the verification code address corresponding to the verification code element is called to download the verification code image; the non-same-origin verification code is used to indicate that the verification code address uniquely corresponds to a verification code image; the verification code image is identified to obtain the verification code content;
[0044] The testing module is used to take the verification code content as input parameters and perform corresponding page automated tests based on the page automated test script.
[0045] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the steps of the methods described in the embodiments of this application.
[0046] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, implements the steps of the methods described in the embodiments of this application.
[0047] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, implements the steps of the methods described in the embodiments of this application.
[0048] The aforementioned automated page testing method, apparatus, computer equipment, storage medium, and computer program product determine the CAPTCHA element in the target page based on the automated page testing script; identify the CAPTCHA type corresponding to the CAPTCHA element; if the CAPTCHA type is a non-same-origin CAPTCHA, call the CAPTCHA address corresponding to the CAPTCHA element to download the CAPTCHA image; the non-same-origin CAPTCHA is used to indicate that the CAPTCHA address uniquely corresponds to a CAPTCHA image; the CAPTCHA image is recognized to obtain the CAPTCHA content; the CAPTCHA content is used as input parameters, and corresponding automated page testing is performed based on the automated page testing script. Using the automatically recognized CAPTCHA content for automated page testing eliminates the need to modify the code logic structure of the page program itself, avoiding inconsistencies between the tested and deployed page programs and ensuring the accuracy of automated page testing. Furthermore, the downloaded non-same-origin CAPTCHA image has high clarity, ensuring the accuracy of the recognized CAPTCHA content. Attached Figure Description
[0049] Figure 1 This is a diagram illustrating the application environment of a page automation testing method in one embodiment.
[0050] Figure 2 This is a flowchart illustrating a page automation testing method in one embodiment;
[0051] Figure 3 This is a schematic diagram of the target page in one embodiment;
[0052] Figure 4 This is a flowchart illustrating the automated page testing process in another embodiment;
[0053] Figure 5 This is a structural block diagram of a page automated testing processing device in one embodiment;
[0054] Figure 6 This is an internal structural diagram of a computer device in one embodiment;
[0055] Figure 7 This is a diagram of the internal structure of a computer device in another embodiment. Detailed Implementation
[0056] In order to make the purpose, technical solutions and advantages of this application more clear, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain this application and are not intended to limit this application.
[0057] The page automated testing method provided in this application embodiment can be applied to, for example, Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. A data storage system can store the data that server 104 needs to process. The data storage system can be integrated onto server 104 or placed on a cloud or other network server. Terminal 102 can trigger server 104 to execute a page automation test script. Server 104 can determine the CAPTCHA element in the target page based on the page automation test script and identify the CAPTCHA type corresponding to the CAPTCHA element. If the CAPTCHA type is a non-same-origin CAPTCHA, server 104 can call the CAPTCHA address corresponding to the CAPTCHA element to download the CAPTCHA image. Server 104 can recognize the CAPTCHA image to obtain the CAPTCHA content. Server 104 can use the CAPTCHA content as input parameters and perform corresponding page automation tests based on the page automation test script. The page automation test script can also be executed locally by terminal 102. Terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices can include smart speakers, smart TVs, smart air conditioners, smart vehicle devices, etc. Portable wearable devices can include smartwatches, smart bracelets, and head-mounted devices. Server 104 can be implemented using a standalone server or a server cluster consisting of multiple servers.
[0058] In one embodiment, such as Figure 2As shown, a method for automated page testing is provided, which can be applied to... Figure 1 Taking the terminal in the example, the explanation includes the following steps:
[0059] Step 202: Determine the CAPTCHA element in the target page based on the page automation test script; identify the CAPTCHA type corresponding to the CAPTCHA element.
[0060] Among them, page automation test scripts are program scripts used to perform automated testing on pages. The CAPTCHA element is an element within the target page. Page automation testing is an automated testing method that simulates manual user interface operations and uses code to automate operations and verifications.
[0061] Specifically, the page automation test script contains predefined locators for CAPTCHA elements and the target URL of the target page. The terminal can access the target page by calling the target URL and locate the CAPTCHA element within the target page according to the locator. The terminal can identify the CAPTCHA type corresponding to the CAPTCHA element. It can be understood that the CAPTCHA type corresponding to the CAPTCHA element can be predefined in the page automation test script.
[0062] In one embodiment, the page automation test script is written using the browser automation testing framework (Selenium). Selenium tests run directly in the browser, just like a real user, and support multiple browser types.
[0063] In one embodiment, the terminal can identify the verification code type corresponding to the verification code element by calling the verification code address corresponding to the verification code element.
[0064] In one embodiment, the page automation test script has predefined automated action elements and locators for performing these automated actions. It can be understood that the automated action element is the page element that is automatically operated on when the terminal executes the page automation script. The element locator is used to locate page elements within the page.
[0065] In one embodiment, such as Figure 3 The target page shown can be a login page. Automated operation elements can include username, password, verification code, and login button elements. The page automation test script includes locators for username, password, verification code, and login button elements.
[0066] In one embodiment, the target page can be the page under test. The page under test is the page that undergoes automated testing using a page automation testing script.
[0067] In one embodiment, the target page can be the login page of the page under test. It is understood that only after verifying the information using the CAPTCHA on the target page can the terminal access the page under test for automated testing.
[0068] Step 204: If the verification code type is a non-same-origin verification code, then call the verification code address corresponding to the verification code element to download the verification code image.
[0069] Among them, non-same-origin CAPTCHAs are used to ensure that a CAPTCHA address uniquely corresponds to a CAPTCHA image. In essence, a CAPTCHA is an image generated from a string of randomly generated numbers or symbols, with some added noise to distinguish whether the user is a computer or a human. The CAPTCHA image is the source image corresponding to the CAPTCHA element on the target page. In essence, the image displayed on the target page is an image adjusted according to the target page's operating environment and the page attribute information of the CAPTCHA element.
[0070] Specifically, if the verification code type recognized by the terminal is a non-same-origin verification code, the terminal calls the verification code address corresponding to the verification code element to download the verification code image. It can be understood that the attribute information of the verification code element includes the verification code address, and the terminal can extract the verification code address from the attribute information of the verification code element.
[0071] In one embodiment, a terminal can invoke a request library to initiate a request to download a verification code image from a verification code address. This means the terminal can retrieve the verification code image resource from the verification code address. The request library is an open-source library used to send requests. The request library could be the Python programming language's Requests library. Requests is used for network request processing and Uniform Resource Locator (URL) resource retrieval.
[0072] Step 206: Recognize the CAPTCHA image to obtain the CAPTCHA content; use the CAPTCHA content as input parameters and perform corresponding page automation tests based on the page automation test script. In one embodiment, the terminal can use image recognition technology to recognize the CAPTCHA image. For example, the terminal can perform optical character recognition (OCR) on the CAPTCHA image. OCR refers to the process of determining the shape by detecting dark and light patterns, and then translating the shape into computer text using character recognition methods. In simple terms, it is recognizing the text on an image and then extracting it.
[0073] Specifically, the terminal can use optical character recognition (OCR) technology to recognize the CAPTCHA image and obtain the CAPTCHA content contained within it. The terminal can then use this CAPTCHA content as a parameter for an automated page testing script and execute the script to perform corresponding automated page tests. In essence, the CAPTCHA content is the CAPTCHA information recognized by the terminal.
[0074] The above-described automated page testing method determines the CAPTCHA element in the target page based on the automated page testing script; identifies the CAPTCHA type corresponding to the CAPTCHA element; if the CAPTCHA type is a non-same-origin CAPTCHA, it calls the CAPTCHA address corresponding to the CAPTCHA element to download the CAPTCHA image; the non-same-origin CAPTCHA is used to indicate that the CAPTCHA address uniquely corresponds to a CAPTCHA image; the CAPTCHA image is recognized to obtain the CAPTCHA content; the CAPTCHA content is used as input parameters, and corresponding automated page testing is performed based on the automated page testing script. Using the automatically recognized CAPTCHA content for automated page testing eliminates the need to modify the code logic structure of the page program itself, avoiding inconsistencies between the tested and deployed page programs and ensuring the accuracy of automated page testing. Furthermore, the downloaded non-same-origin CAPTCHA image has high clarity, ensuring the accuracy of the recognized CAPTCHA content.
[0075] In one embodiment, the method further includes: if the verification code type is a same-source verification code, cropping the area where the verification code element is located on the target page to obtain a screenshot of the verification code; and performing optical character recognition on the screenshot of the verification code to obtain the verification code content.
[0076] Among them, the same-origin CAPTCHA is used to indicate that a CAPTCHA address corresponds to multiple CAPTCHA images. It can be understood that for the same-origin CAPTCHA type, calling the same CAPTCHA address multiple times will result in different CAPTCHA images.
[0077] Specifically, if the verification code identified by the terminal is a same-source verification code, the terminal can determine the area where the verification code element is located on the target page based on the attribute information of the verification code element, and crop that area to obtain a screenshot of the verification code. The terminal can then perform optical character recognition on the screenshot of the verification code to obtain the verification code content.
[0078] In this embodiment, the terminal can obtain a screenshot of the verification code for verification code elements of the same type as the original verification code, and recognize the screenshot of the verification code. This can avoid the problem of inconsistency between the downloaded verification code image and the verification code image on the target page, and ensure the accuracy of verification code recognition.
[0079] In one embodiment, if the verification code type is a same-origin verification code, cropping the area where the verification code element is located on the target page to obtain a verification code screenshot includes: if the verification code type is a same-origin verification code, calling an image processing library to crop the area where the verification code element is located on the target page to obtain a verification code screenshot; performing optical character recognition on the verification code screenshot to obtain the verification code content includes: calling an image verification code recognition library to perform optical character recognition on the verification code screenshot to obtain the verification code content.
[0080] The image processing library is an open-source library for image processing. The image CAPTCHA recognition library is an open-source library that uses optical character recognition technology to recognize image CAPTCHAs.
[0081] Specifically, if the CAPTCHA type is a same-origin CAPTCHA, the location information of the CAPTCHA element is extracted from its attribute information. Based on the location information, the region where the CAPTCHA element is located on the target page is determined, and the region is cropped using an image processing library to obtain a screenshot of the CAPTCHA. The terminal can then input the CAPTCHA screenshot into an image CAPTCHA recognition library for optical character recognition to obtain the CAPTCHA content. If the CAPTCHA type is a different-origin CAPTCHA, the CAPTCHA address corresponding to the CAPTCHA element is called to download the CAPTCHA image, and the CAPTCHA image is then input into an image CAPTCHA recognition library for optical character recognition to obtain the CAPTCHA content.
[0082] In one embodiment, the image processing library can be a third-party image processing library (PIL, Python Image Library) for the Python programming language. The image CAPTCHA recognition library can be the Python image CAPTCHA recognition library (Ddddocr). Ddddocr can recognize the image and obtain a string containing operators.
[0083] In this embodiment, if the verification code type is a same-source verification code, the verification code screenshot is obtained by cropping through an image processing library, and the verification code content in the verification code screenshot is identified through an image verification code recognition library. Using an open-source library for verification code recognition is simpler and more convenient.
[0084] In one embodiment, if the CAPTCHA type is a same-origin CAPTCHA, cropping the area where the CAPTCHA element is located on the target page to obtain a CAPTCHA screenshot includes: taking a full-screen screenshot of the target page to obtain a page image; if the CAPTCHA type is a same-origin CAPTCHA, extracting the page position attribute information of the CAPTCHA element from the attribute information of the CAPTCHA element; determining the page image area where the CAPTCHA element is located based on the page position attribute information; and cropping the page image area from the page image to obtain a CAPTCHA screenshot.
[0085] The page location attribute information refers to the information in the attribute information of the CAPTCHA element used to represent its location. The CAPTCHA screenshot is an image cropped from the page image.
[0086] In one embodiment, the page position attribute information may include the position coordinates and size of the CAPTCHA element. It can be understood that the size of the CAPTCHA element may include its height and width.
[0087] Specifically, the terminal can take a full-screen screenshot of the target page to obtain a page image. This page image can be understood as a screenshot including the area where the CAPTCHA element is located. If the CAPTCHA type is a same-origin CAPTCHA, the terminal can extract the position coordinates and size of the CAPTCHA element from its attribute information. Based on the position coordinates and size, the terminal can determine the page image area where the CAPTCHA element is located and use an image processing library to crop the page image area to obtain the CAPTCHA screenshot.
[0088] In one embodiment, the terminal can save the page image to a specified directory and obtain the image and window size information of the page image. It can be understood that the terminal can subsequently retrieve the page image from the specified directory and determine the position and size of the page image area where the CAPTCHA element is located based on the image and window size information of the page image, as well as the position coordinates and size of the CAPTCHA element.
[0089] In this embodiment, a full-screen screenshot of the target page is taken to obtain a page image. If the verification code type is a same-origin verification code, the page position attribute information of the verification code element is extracted from the attribute information of the verification code element so as to crop the page image area from the page image to obtain a verification code screenshot. Cropping the verification code screenshot from the page image can avoid the problem of inaccurate screenshots on the target page due to the page being too large or having different resolutions.
[0090] In one embodiment, the method further includes: determining the operating system executing the page automated test script to obtain the interface scaling factor of the operating system; determining the page image area where the CAPTCHA element is located based on the page position attribute information includes: determining the page image area where the CAPTCHA element is located according to the interface scaling factor and the page position attribute information.
[0091] The interface scaling factor is used to indicate the scaling ratio of the page.
[0092] Specifically, the terminal can determine the operating system executing the page automation test script to obtain the interface scaling factor for that operating system. The terminal can then multiply the position coordinates and element size extracted from the attribute information of the CAPTCHA element by the interface scaling factor to obtain the position coordinates and element size of the CAPTCHA element within the page image, thereby determining the area of the page image where the CAPTCHA element is located. For example, the interface scaling factor for the first operating system can be set to 1.25, and the interface scaling factor for the second operating system can be set to 2. The first operating system can be a Microsoft operating system (Windows), and the second operating system can be an Apple operating system (Mac).
[0093] In this embodiment, the page image area where the verification code is located is determined according to the interface scaling factor of different operating systems. This can adapt to different operating systems, eliminate the differences in resolution and page layout between different operating systems, and obtain an accurate verification code screenshot.
[0094] In one embodiment, the page automation test script runs in a browser; the method further includes: obtaining a browser type parameter from the page automation test script; if the browser type parameter indicates a browser with a user interface, then controlling the browser to run the page automation test script with a user interface; if the browser type parameter indicates a headless browser, then controlling the browser to run the page automation test script without a user interface.
[0095] A headless browser is a browser without a user interface. It can be programmatically controlled during runtime, performing tasks such as testing and taking screenshots without displaying a visual interface. A browser with a user interface (or a web browser) is one that has a visual interface. The browser type parameter indicates the browser type.
[0096] Specifically, the terminal can obtain the browser type parameter from the page automation test script. If the browser type parameter indicates a browser with a graphical interface, the terminal can initialize the browser with a graphical interface and control it to run the page automation test script with a graphical interface. If the browser type parameter indicates a headless browser, the terminal can control the browser to run the page automation test script without a graphical interface. It can be understood that testers can add browser type parameters to the terminal to accommodate various browser types.
[0097] In one embodiment, testers can use the terminal to import the necessary Selenium libraries, define automated test classes, and instantiate browser objects to write automated test scripts for the page. It is understood that testers can customize the browser type parameter passed in when instantiating the browser object.
[0098] In this embodiment, if the browser type parameter indicates a browser with a user interface, the browser is controlled to run the page automation test script with a user interface; if the browser type parameter indicates a headless browser, the browser is controlled to run the page automation test script without a user interface, which can adapt to the needs of different page automation testing scenarios.
[0099] In one embodiment, identifying the verification code type corresponding to a verification code element includes: extracting the verification code address from the attribute information of the verification code element; repeatedly calling the verification code address to download the verification code image to obtain multiple verification code images; if the multiple verification code images are consistent, it indicates that the verification code type corresponding to the verification code element is a non-same-source verification code; if the multiple verification code images are inconsistent, it indicates that the verification code type corresponding to the verification code element is a same-source verification code.
[0100] Specifically, the terminal can extract the verification code address from the attribute information of the verification code element, and repeatedly call the verification code address to download the verification code image, obtaining multiple verification code images. The terminal can call an image verification code recognition library to perform optical character recognition on the multiple verification code images to obtain the verification code content of the multiple verification code images. If the verification code content of the multiple verification code images is the same, it indicates that the verification code type corresponding to the verification code element is a non-same-origin verification code; if the verification code content of the multiple verification code images is different, it indicates that the verification code type corresponding to the verification code element is a same-origin verification code.
[0101] In one embodiment, the terminal can perform similarity comparison on multiple CAPTCHA images to determine whether the multiple CAPTCHA images are consistent.
[0102] In one embodiment, if the verification code type is a non-same-origin verification code, the verification code address corresponding to the verification code element will be updated during the repeated calls to the verification code address to download the verification code image. If the verification code type is a non-same-origin verification code, calling the verification code address corresponding to the verification code element to download the verification code image includes: if the verification code type is a non-same-origin verification code, downloading the corresponding verification code image based on the updated verification code address corresponding to the verification code element. It can be understood that during the automatic verification code type recognition process on the terminal, the verification code on the target page may refresh, therefore it is necessary to obtain the updated verification code address corresponding to the verification code element.
[0103] In this embodiment, multiple verification code images are downloaded by repeatedly calling the verification code address to determine the verification code type corresponding to the verification code element. For verification codes on different pages, testers do not need to manually define the verification code type for the corresponding page. The verification code type can be automatically identified, which is more convenient.
[0104] In one embodiment, using the verification code content as an input parameter and performing corresponding page automation testing based on the page automation test script includes: inputting the verification code content as an input parameter into the target page based on the page automation test script; after obtaining information from the target page indicating that the verification code content is incorrect, triggering a retry mechanism to re-execute the step of calling the verification code address corresponding to the verification code element to download the verification code image if the verification code type is a non-same-origin verification code, until the target page returns information indicating that the verification code content is correct or the retry stop condition is met, and then stopping the retry.
[0105] Specifically, the terminal can use the CAPTCHA content as a parameter for an automated page testing script, and input the CAPTCHA content into the target page by executing the script. After receiving information from the target page indicating an error in the CAPTCHA content, the terminal can trigger a retry mechanism to re-execute the step of calling the CAPTCHA address corresponding to the CAPTCHA element to download the CAPTCHA image if the CAPTCHA type is a non-same-origin CAPTCHA, until the target page returns information indicating the CAPTCHA content is correct or the retry stop condition is met. It can be understood that when the retry mechanism is triggered, the CAPTCHA on the target page will refresh, and the terminal can re-acquire a screenshot of the CAPTCHA or download the CAPTCHA image to recognize the CAPTCHA content. If the target website interface does not return information indicating the CAPTCHA information is correct, and the retry stop condition is not met, the terminal can return information indicating CAPTCHA recognition failure.
[0106] In one embodiment, the terminal can invoke a retry library to implement a retry mechanism. A retry library is an open-source library used to implement retry functionality. For example, Tenacity is a general-purpose retry library for the Python programming language. Tenacity allows for custom retry scenarios and mechanisms. In essence, testers can use Tenacity to define retry mechanisms, including retry conditions, retry intervals, and the number of retries. If the retry conditions are met, multiple retries are performed according to the retry interval. After the maximum number of retries is reached, indicating that the retry stop condition has been met, the retries cease.
[0107] In this embodiment, after receiving information indicating an error in the verification code content returned by the target page, a retry mechanism is triggered to perform optical character recognition again to obtain the verification code content, which can further improve the accuracy of verification code recognition.
[0108] In one embodiment, such as Figure 4The diagram illustrates the process flow of automated page testing. Testers can instantiate a browser object using the browser automation testing framework on the terminal. The browser object's information includes a browser type parameter. The terminal can initialize the browser according to this parameter and open the target page by calling its address. The terminal can take a full-screen screenshot of the target page, obtaining an image, and extract the position coordinates and size of the CAPTCHA element from its attribute information. If the CAPTCHA type is a same-origin CAPTCHA, the terminal crops the CAPTCHA screenshot from the page image; if it's a different-origin CAPTCHA image, the terminal downloads the image from the CAPTCHA address. The terminal can use an image CAPTCHA recognition library to perform optical character recognition on the screenshot or image to obtain the CAPTCHA content. The terminal can pass the CAPTCHA content as a parameter to the automated page testing script and execute the script to input the CAPTCHA content on the target page. The terminal can trigger a retry mechanism after receiving information indicating an error in the CAPTCHA content from the target page. The terminal can stop retrying after receiving information indicating a correct CAPTCHA content from the target page.
[0109] In one embodiment, the terminal can display the execution log of the automated page test script, or, when the server executes the automated page test script, the server can send the execution log of the automated page test script to the terminal for display. When the CAPTCHA type is a same-origin CAPTCHA, the execution log may include the width, height, and format of the page image obtained from a full-screen screenshot of the target page; the height and width of the browser window executing the automated page test script; the width and height coefficients corresponding to the operating system; the position coordinates and size of the CAPTCHA element extracted from the CAPTCHA attribute information; the position coordinates of the page image area where the CAPTCHA element is located; the identified CAPTCHA content; and the CAPTCHA verification result. The size of the CAPTCHA element includes its width and height.
[0110] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0111] Based on the same inventive concept, this application also provides a page automation testing apparatus for implementing the page automation testing method described above. The solution provided by this apparatus is similar to the implementation described in the above method; therefore, the specific limitations in one or more embodiments of the page automation testing apparatus provided below can be found in the limitations of the page automation testing method described above, and will not be repeated here.
[0112] In one embodiment, such as Figure 5 As shown, a page automated testing processing device 500 is provided, including: a determination module 502, an identification module 504, and a testing module 506, wherein:
[0113] Module 502 is used to determine the CAPTCHA element in the target page based on the page automation test script;
[0114] The identification module 504 is used to identify the verification code type corresponding to the verification code element; if the verification code type is a non-same-origin verification code, the verification code address corresponding to the verification code element is called to download the verification code image; the non-same-origin verification code is used to indicate that the verification code address uniquely corresponds to a verification code image; the verification code image is identified to obtain the verification code content;
[0115] The test module 506 is used to take the verification code content as input parameter and perform corresponding page automated tests based on the page automated test script.
[0116] In one embodiment, the recognition module 504 is further configured to, if the verification code type is a same-source verification code, crop the area where the verification code element is located on the target page to obtain a screenshot of the verification code; and recognize the screenshot of the verification code to obtain the verification code content.
[0117] In one embodiment, the recognition module 504 is further configured to, if the verification code type is a same-source verification code, call an image processing library to crop the area where the verification code element is located on the target page to obtain a screenshot of the verification code; and call an image verification code recognition library to recognize the screenshot of the verification code to obtain the verification code content.
[0118] In one embodiment, the identification module 504 is further configured to take a full-screen screenshot of the target page to obtain a page image; if the verification code type is a same-origin verification code, then extract the page position attribute information of the verification code element from the attribute information of the verification code element; determine the page image area where the verification code element is located based on the page position attribute information; and crop the page image area from the page image to obtain a verification code screenshot.
[0119] In one embodiment, the identification module 504 is further configured to determine the operating system executing the page automated test script, so as to obtain the interface scaling factor of the operating system; determining the page image area where the CAPTCHA element is located based on the page position attribute information includes: determining the page image area where the CAPTCHA element is located according to the interface scaling factor and the page position attribute information.
[0120] In one embodiment, the page automation test script runs in a browser; the determining module 502 is further configured to obtain a browser type parameter from the page automation test script; if the browser type parameter indicates a browser with a user interface, then the browser is controlled to run the page automation test script with a user interface; if the browser type parameter indicates a headless browser, then the browser is controlled to run the page automation test script without a user interface.
[0121] In one embodiment, the identification module 504 is further configured to extract the verification code address from the attribute information of the verification code element; repeatedly call the verification code address to download the verification code image to obtain multiple verification code images; if the multiple verification code images are consistent, it indicates that the verification code type corresponding to the verification code element is a non-same-source verification code; if the multiple verification code images are inconsistent, it indicates that the verification code type corresponding to the verification code element is a same-source verification code.
[0122] In one embodiment, the test module 506 is further configured to input the verification code content as an input parameter into the target page based on the page automated test script; after obtaining information from the target page indicating that the verification code content is incorrect, a retry mechanism is triggered to re-execute the step of calling the verification code address corresponding to the verification code element to download the verification code image if the verification code type is a non-same-origin verification code, until the target page returns information indicating that the verification code content is correct or the retry stop condition is met and the retry stops.
[0123] Each module in the aforementioned automated page testing and processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of a computer device in software form, so that the processor can call and execute the corresponding operations of each module.
[0124] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 6As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data related to automated page testing. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communicating with external terminals via a network connection. When the computer program is executed by the processor, it implements an automated page testing method.
[0125] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 7 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements an automated page testing method. The display unit of the computer device is used to form a visually visible image. It can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0126] Those skilled in the art will understand that Figure 6 and Figure 7The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0127] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above-described method embodiments.
[0128] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps in the above method embodiments.
[0129] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0130] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data shall comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0131] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0132] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0133] The above-described embodiments merely represent several implementation methods of the present application. While the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the present application. It should be noted that a person of ordinary skill in the art may make various modifications and improvements without departing from the spirit of the present application, and these modifications and improvements fall within the scope of protection of the present application. Therefore, the scope of protection of the present application shall be determined by the appended claims.
Claims
1. A method for automated page testing, characterized in that, The method includes: Based on the locators of the CAPTCHA elements predefined in the page automation test script, determine the CAPTCHA elements in the target page; Take a full-screen screenshot of the target page to obtain a page image; Calling the verification code address corresponding to the verification code element and identifying the verification code type corresponding to the verification code element includes: extracting the verification code address from the attribute information of the verification code element, repeatedly calling the verification code address to download the verification code image to obtain multiple verification code images; if the multiple verification code images are consistent, it indicates that the verification code type corresponding to the verification code element is a non-same-origin verification code; if the multiple verification code images are inconsistent, it indicates that the verification code type corresponding to the verification code element is a same-origin verification code. If the verification code type is a non-same-origin verification code, then the verification code address corresponding to the verification code element is called to download the verification code image; the non-same-origin verification code is used to indicate that the verification code address uniquely corresponds to a verification code image; or, If the verification code type is a same-origin verification code, a screenshot of the verification code is taken from the page image; the same-origin verification code is used to indicate that the verification code address corresponds to multiple verification code images, and calling the same verification code address multiple times will result in different verification code images; Optical character recognition is performed on the verification code image or the screenshot of the verification code to obtain the verification code content; wherein, the optical character recognition refers to the process of determining the shape by detecting dark and light patterns, and translating the shape into computer text using character recognition methods; The verification code content is used as input parameter, and corresponding page automated tests are performed based on the page automated test script.
2. The method according to claim 1, characterized in that, The method further includes: If the verification code type is a same-origin verification code, then crop the area where the verification code element is located on the target page to obtain a screenshot of the verification code; The screenshot of the verification code is recognized to obtain the content of the verification code.
3. The method according to claim 2, characterized in that, The method further includes: If the verification code type is a same-origin verification code, then cropping the area where the verification code element is located on the target page to obtain the verification code screenshot includes: If the verification code type is a same-origin verification code, then the page position attribute information of the verification code element is extracted from the attribute information of the verification code element; The page image area where the verification code element is located is determined based on the page location attribute information; A screenshot of the verification code is obtained by cropping a region of the page image from the page image.
4. The method according to claim 3, characterized in that, The method further includes: Determine the operating system executing the page automation test script to obtain the interface scaling factor of the operating system; The step of determining the page image area where the verification code element is located based on the page position attribute information includes: The page image area where the verification code element is located is determined according to the interface scaling factor and the page position attribute information.
5. The method according to claim 1, characterized in that, The page automation test script runs in a browser; the method also includes: Obtain browser type parameters from the page automation test script; If the browser type parameter indicates a browser with a user interface, then control the browser to run the page automated test script with a user interface. If the browser type parameter indicates a headless browser, then control the browser to run the page automated test script without a user interface.
6. The method according to any one of claims 1 to 5, characterized in that, The step of using the verification code content as input parameter and performing corresponding page automated testing based on the page automated testing script includes: The verification code content is input into the target page as an input parameter based on the page automation test script; After receiving information from the target page indicating an error in the verification code content, a retry mechanism is triggered to re-execute the step of calling the verification code address corresponding to the verification code element to download the verification code image if the verification code type is a non-same-origin verification code, until the target page returns information indicating that the verification code content is correct or the retry stop condition is met, and then the retry stops.
7. A page automated testing and processing device, characterized in that, The device comprises: The determination module is used to determine the CAPTCHA element in the target page based on the locator of the CAPTCHA element predefined in the page automation test script; The recognition module is used to take a full-screen screenshot of the target page to obtain a page image; call the verification code address corresponding to the verification code element, and identify the verification code type corresponding to the verification code element, including: extracting the verification code address from the attribute information of the verification code element, repeatedly calling the verification code address to download the verification code image, and obtaining multiple verification code images; if the multiple verification code images are the same, it indicates that the verification code type corresponding to the verification code element is a non-same-origin verification code; if the multiple verification code images are not the same, it indicates that the verification code type corresponding to the verification code element is a same-origin verification code; if the verification code type is a non-same-origin verification code, then call the verification code element... The corresponding verification code address is used to download the verification code image; the non-same-origin verification code is used to indicate that the verification code address uniquely corresponds to one verification code image; or, if the verification code type is same-origin verification code, a screenshot of the verification code is captured from the page image; the same-origin verification code is used to indicate that the verification code address corresponds to multiple verification code images, and calling the same verification code address multiple times will result in different verification code images; optical character recognition is performed on the verification code image or the verification code screenshot to obtain the verification code content; wherein, optical character recognition refers to the process of determining the shape by detecting dark and light patterns, and translating the shape into computer text using character recognition methods; The testing module is used to take the verification code content as input parameters and perform corresponding page automated tests based on the page automated test script.
8. The automated page testing and processing device according to claim 7, characterized in that, The recognition module is further configured to, if the verification code type is a same-source verification code, crop the area where the verification code element is located on the target page to obtain a verification code screenshot; and recognize the verification code screenshot to obtain the verification code content.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Verification code test method and apparatus, terminal device and storage medium
CN108563559A
Front-end automatic testing method and device
CN113568794A