Web application automatic test method, system and server
Through artificial intelligence technology and chromium headless browser, combined with natural language requests and puppeteer components, the problem of difficulty in crawling dynamic page data in the existing technology is solved, and automated testing and data crawling of web applications are realized, and anti-crawlers are avoided interception of mechanism.
Patent Information
- Application Number
- CN202411470954.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-01-14
AI Technical Summary
The prior art is easy to be recognized by the anti-crawler mechanism when performing web automation testing and crawling, and it is difficult to crawl the data of dynamic pages.
Using artificial intelligence technology combined with chromium headless browser, it uses natural language request processing to standardized output, calls corresponding APIs, and uses puppeteer components to simulate user operations to realize automated testing and data crawling of web applications.
It realizes automatic access and data crawling of web applications, avoids interception by anti-crawler mechanisms, and can effectively obtain data from static and dynamic pages.
Smart Images

Figure CN119311592A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of web automated testing and crawler technology, and in particular, relates to a web application automated testing method, system and server. Background Art
[0002] In the web automation testing process and crawler technology, it mainly includes calling the page interface and collecting the data returned by the interface; simulating users to enter usernames and passwords to log in; using user cookies to automatically authorize access; recursively accessing all retrieved accessible pages in the web page; suitable for web applications in SPA single-page rendering and SSR rendering mode; and can also replace the crawler function to obtain all data information on the web site.
[0003] Traditional crawlers or web automation tests use Python's Scrapy framework to obtain data from web applications, or use selenium to configure automated tests. However, many external websites currently have anti-crawler mechanisms, and most existing technologies can only crawl static pages through the backend Python's requests library, while most web applications often use the User-Agent field in headers to reverse crawl, referer field or other fields to reverse crawl. If the crawler written in Python does not add User-Agent, the server type pySpider can be seen on the backend server, which is easy to identify. And it can only crawl static pages, and it is difficult to crawl or automate tests for dynamic pages that need to be loaded through js.
[0004] Therefore, there is an urgent need for a technical solution for automated testing of web applications that can solve the above problems. Summary of the invention
[0005] In order to address the deficiencies of the prior art, the present application provides a web application automated testing method, system and server, which combines the existing AI technology with a headless browser based on Chromium as the core as a medium, and realizes automated testing or crawler functions of web applications by calling corresponding APIs through understanding the user's semantics.
[0006] The technical effects to be achieved by this application are achieved through the following solutions:
[0007] According to a first aspect of the present application, a web application automated testing method is provided, comprising the following steps:
[0008] Step 1: Build an agent and process the natural language request into a standardized output through the prompt function, wherein the standardized output includes the interface call address;
[0009] Step 2: Send the standardized output to the textToAPI service, and the textToAPI service requests the interface call address and obtains a status code indicating a successful request;
[0010] Step 3: The node service calls the corresponding interface according to the status code and the interface call address, executes the corresponding logic, and calls the puppeteer component to implement the required functions;
[0011] Step 4: The puppeteer component simulates user operations, monitors all xhr requests and records the acquired data to complete the automated testing of the web application.
[0012] Preferably, in step 1, the prompt function processes the natural language into standardized output including: interface address, url address and interface call address, inputs the standardized output into the big model, the big model identifies the corresponding parameters, and the big model sends the corresponding parameters to the textToAPI service.
[0013] Preferably, in step 2, after the textToAPI service request for the interface call address fails, the failure result is returned to the user.
[0014] Preferably, in step 3, calling the corresponding interface includes: obtaining the page content interface from the website, obtaining the user name and password automatic login interface, obtaining the cookies login interface, and clicking a button found in the page.
[0015] Preferably, calling the puppeteer component to implement the required functions is: controlling headlessChrome through the DevTools protocol to complete the work done manually in the browser, thereby achieving the purpose of simulating user operations.
[0016] Preferably, in step 4, node.JS in the puppeteer component monitors all xhr requests during execution and records the acquired data, including: when a new page is opened, the xhr request return result of the new page is recorded.
[0017] Preferably, it also includes: for pages that require user name and password login, the login information or valid cookies are input into the big model, and the big model transmits the input information to the back-end execution logic through the corresponding interface.
[0018] Preferably, for natural language requests with unclear purposes, the big model will ask the user questions through several rounds of dialogue, combine the user's questions with the big model's answers as context input, and repeat steps 1 to 4.
[0019] According to a second aspect of the present application, a web application automated testing system using the above web application automated testing method is provided, comprising:
[0020] The input module is the user dialogue entry, which passes the natural language request entered by the user to the prompt module;
[0021] The prompt module processes the natural language request into a standardized output and sends it to the large model module;
[0022] The large model module infers the user's purpose based on the standardized output and outputs the interface that the user needs to call;
[0023] The interface calling module makes an HTTP request based on the interface information that needs to be called output by the large model module;
[0024] The node backend module receives the http request and performs corresponding backend logic processing, and calls the puppeteer module;
[0025] puppeteer module, which directly controls the Chromium module through the Devtools protocol;
[0026] Chromium module, puppeteer module simulates real user operations by calling Chromium using a headless or non-headless browser.
[0027] According to a third aspect of the present application, there is provided a server, comprising: a memory and at least one processor;
[0028] The memory stores a computer program, and the at least one processor executes the computer program stored in the memory to implement the above-mentioned web application automated testing method.
[0029] According to an embodiment of the present application, the beneficial effect of using the web application automated testing method is that the method combines artificial intelligence technology, understands the semantics, judges the user's purpose, and calls the corresponding API to achieve web automated access, click testing, and crawling data functions. It allows users to call the crawler interface in the form of a dialogue to achieve automated testing and data crawling, and simulates real user access in the form of a headless browser, which will not be blocked by the anti-crawler mechanism. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present application or the existing technical solutions, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0031] Figure 1 This is a flow chart of a web application automated testing method in one embodiment of the present application;
[0032] Figure 2 This is a structural block diagram of a web application automation testing system in an embodiment of the present application;
[0033] Figure 3 This is a structural block diagram of a server in an embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the present application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0035] like Figure 1 As shown, the web application automated testing method in an embodiment of the present application includes the following steps:
[0036] Step 1: Build an intelligent agent, and use the prompt function to process natural language requests into standardized outputs and give them to the large model for reasoning. The standardized outputs contain all interface call addresses.
[0037] In this step, the agent is an intelligent processing flow that integrates the big model and other related service components. The big model combines the prompt with the user's input to reason and give a standard format output, which includes the interface address and request parameters that the user needs to call.
[0038] The prompt function can process natural language input into standardized input for the big model, and then the big model infers the output. The prompt function processes natural language into standardized output including: URL address and interface call address, inputs the standardized output into the big model, and the big model identifies the corresponding parameters and sends the corresponding parameters to the textToAPI service.
[0039] For example, the standardized output is: the user inputs "I want to get the content on www.abc.com", and the prompt function processes it and gives the input to the big model as:
[0040] "I want to obtain the content on the website www.abc.com. The interface address for obtaining the page content is http: / / 127.0.0.1:3000 / spidermanurl=params, where params is the URL address provided by the user. After filling in the params parameter, the interface call address is output."
[0041] For natural language requests with unclear purposes, the big model will guide users by asking for more details through multiple rounds of conversations to clearly and accurately understand the user's intentions and required parameters, such as the address of the test page, whether login is required, and what automated testing is required (obtaining data or clicking components). The model guides users to answer more content, obtains the required test content, and combines the user's questions and the model's answers as context input to continue with the following steps.
[0042] Through this step, the prompt word engineering combines the user's input to let the big model understand the user's needs and accurately give the corresponding API interface call. If the user's intention is not clear, multiple rounds of dialogue are conducted, and the context of the multiple rounds of dialogue is combined to give the big model an accurate judgment.
[0043] Step 2: Send the standardized output to the textToAPI service, and the textToAPI service requests the interface call address and obtains a status code indicating a successful request;
[0044] In this step, the status code is used to reflect whether the large model request is successful, such as 404 (address does not exist), 200 (request successful), etc., so that the user can make emergency adjustments based on the status code.
[0045] The output of the large model is sent to the textToAPI service, which requests the interface call address and obtains a status code indicating a successful request. If the request fails, a failure result is returned to the user.
[0046] Step 3: After receiving the call request, the node service executes the corresponding logic and calls the puppeteer component to implement the required functions;
[0047] In this step, the node service starts to execute the backend logic after receiving the request. The service itself provides multiple different interface addresses to implement different execution schemes, such as traversing the website to obtain the page content interface, obtaining the user name and password automatic login interface, obtaining the cookies login interface, clicking the button found on the page, etc. The corresponding logic will be executed according to the interface request address and parameters.
[0048] In order to implement the entire function, you need to call the puppeteer component. The puppeteer component is a Node.js API for controlling headless Chrome. It is a Node.js library that provides an API to control headless Chrome through the DevTools protocol. It can also be configured to use a full (non-headless) Chrome, and the puppeteer component completes the operations that need to be done manually in the browser to simulate manual operations by users, for example:
[0049] Generate screenshots and PDF pages, retrieve SPA and generate pre-rendered content (i.e. "SSR");
[0050] Used in conjunction with professional crawler proxy services to crawl content from websites to improve crawler efficiency and success rate;
[0051] Automatic form submission, UI testing, keyboard input, etc.;
[0052] Simulate user operations in the browser, such as opening web pages, clicking links, entering text, scrolling pages, etc., to dynamically capture web page content;
[0053] Create an up-to-date automated testing environment that uses the latest JavaScript and browser features, running tests directly in the latest version of Chrome;
[0054] Captures a timeline trace of your website to help analyze performance issues with your website.
[0055] Through this step, the Node backend service executes the logic, and the service provides a variety of interfaces corresponding to different functions, which can realize web page screenshots, simulate user login, obtain page content and interface return data, simulate click events, simulate user input, etc.; all execution logic is implemented based on nodeJS code logic, and the open source puppeteer library is used to directly call the browser to simulate user operations, thereby realizing automated testing of the current web application, and the corresponding crawler functions can be implemented as needed.
[0056] Step 4: The puppeteer component simulates user operations, monitors all xhr requests and records the acquired data to complete the automated testing of the web application.
[0057] In this step, the node.JS in the puppeteer component listens to all xhr requests during execution and records the acquired data, including: when a new page is opened, the xhr request return result of the new page is recorded.
[0058] And: For pages that require username and password login, enter the login information or valid cookies into the big model, and the big model will pass the input information to the backend execution logic through the corresponding interface.
[0059] This method adopts a recursive access method. According to the URL address provided by the user, all URL access links are obtained on the current page, and the links are opened one by one to start new page access. When accessing a new page, user needs can be processed, such as obtaining page content, screenshots, clicking buttons, etc.; and the root path is obtained through the URL provided by the user, and the pages with the same root path are recursively processed with the same logical steps to avoid accessing external link addresses, and the pages that have been processed are closed;
[0060] All visited and unvisited URLs are recorded in a cache array and deduplicated until all queried URLs are visited, the recursion ends, and all pages are closed.
[0061] Through the above method, automatic testing tools and automatic testing scripts are used to complete the specified testing tasks. The test startup process does not require human participation. The user is automatically simulated to perform automatic clicking, logging in and obtaining data to complete the automated testing.
[0062] This method can provide web testers with more efficient automated testing capabilities. At the same time, as an automated testing tool, combined with intelligent agents, it gives intelligent agents the ability to automatically test web applications and obtain website content resources, providing a new solution for intelligent agent industry applications.
[0063] like Figure 2 As shown, in one embodiment of the present application, a web application automated testing system using the above web application automated testing method is provided, comprising:
[0064] The input module is the user dialogue entrance, which passes the natural language request input by the user to the prompt module. The input module is, for example, a keyboard and display, a touch screen or a voice input module such as a microphone, etc. It can not only input natural language but also display text content to interact with the user;
[0065] The Prompt module processes the natural language request into a standardized output and sends it to the large model module. Using the Prompt module, the large model can have strong adaptability in different tasks and scenarios. It can better understand and process diverse data inputs, thereby improving its prediction accuracy in new situations.
[0066] The large model module infers the user's purpose based on the standardized output and outputs the interface that the user needs to call;
[0067] The interface call module has a built-in TextToApi service, which makes an http request based on the interface information that needs to be called output by the large model module. The TextToApi service enables the large language model (LLM) to generate the form of tool_name(parameter1=value1, parameter2=values,...) to interact with the external environment, thus improving the efficiency and accuracy of the interaction.
[0068] Moreover, the TextToApi service enables the model to have strong adaptability in different tasks and scenarios, and can better understand and process diverse data inputs, thereby improving its prediction accuracy in new situations.
[0069] The node backend module receives the http request and performs corresponding backend logic processing, and calls the puppeteer module. Node.js adopts an event-driven programming model, which can efficiently respond to events and requests without creating multiple threads or processes for processing, saving system resources and improving performance and stability.
[0070] The puppeteer module directly controls the Chromium module through the Devtools protocol. Puppeteer is based on the Chrome or Chromium browser, has efficient and stable performance and compatibility, and can simulate the operation behavior of real users, making the test results closer to the actual situation.
[0071] Chromium module, puppeteer module simulates real user operations by calling Chromium using a headless or non-headless browser.
[0072] This system uses the architecture of TextToApi, nodejs, puppeteer, and chromium to implement automated, configurable, visual, and user-simulated automated testing, including: calling the page interface and collecting the data returned by the interface; simulating the user to enter the username and password to log in; using user cookies to automatically authorize access; recursively accessing all retrieved accessible pages in the web page; suitable for web applications in SPA single-page rendering and SSR rendering mode; and can also replace the crawler function to obtain all data information on the web site.
[0073] During the use of this system, the user inputs the required automated test requirements through the input module in the form of voice, text, etc.;
[0074] The input module passes the natural language to the prompt module, processes the natural language request into a standardized output through the prompt function, wherein the standardized output includes an interface call address, and sends the standardized output to the large model module;
[0075] The large model module infers the user's purpose based on the interface call address contained in the standardized output and outputs the interface that the user needs to call;
[0076] Send the standardized output to the textToAPI service of the interface call module to generate an http request, and the textToAPI service requests the interface call address and obtains a status code of successful request;
[0077] After the node backend module receives the http request, the node service calls the corresponding interface according to the status code and the interface call address, executes the corresponding logic, and calls the puppeteer module to implement the required function;
[0078] The Devtools protocol directly controls the Chromium module, and the puppeteer module performs simulated user operations, uses a headless or non-headless browser to simulate real user operations, monitors all xhr requests and records the obtained data, and completes the automated testing of web applications.
[0079] like Figure 3 As shown, a server in an embodiment of the present application includes: a memory 301 and at least one processor 302;
[0080] The memory 301 stores computer programs, and the at least one processor 302 executes the computer programs stored in the memory 301 to implement the above-mentioned web application automated testing method.
[0081] According to an embodiment of the present application, the beneficial effect of using the web application automated testing method is that the method combines artificial intelligence technology, understands the semantics, judges the user's purpose, and calls the corresponding API to achieve web automated access, click testing, and crawling data functions. It allows users to call the crawler interface in the form of a dialogue to achieve automated testing and data crawling, and simulates real user access in the form of a headless browser, which will not be blocked by the anti-crawler mechanism.
[0082] It should be noted that the above detailed descriptions are exemplary and are intended to provide further explanation of the present application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the art to which the present application belongs.
[0083] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit the exemplary embodiments according to the present application. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should also be understood that when the terms "comprise" and / or "include" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0084] It should be noted that 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 are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein.
[0085] In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or inherent to these processes, methods, products, or apparatuses.
[0086] For ease of description, spatially relative terms, such as "above", "above", "on the upper surface of", "above", etc., may be used herein to describe the spatial positional relationship between a device or feature and other devices or features as shown in the figure. It should be understood that spatially relative terms are intended to include different orientations of the device in use or operation in addition to the orientation described in the figure. For example, if the device in the accompanying drawings is inverted, the device described as "above other devices or structures" or "above other devices or structures" will be positioned as "below other devices or structures" or "below other devices or structures". Thus, the exemplary term "above" may include both "above" and "below". The device may also be positioned in other different ways, such as rotated 90 degrees or in other orientations, and the spatially relative descriptions used herein are interpreted accordingly.
[0087] In the above detailed description, reference is made to the accompanying drawings, which form a part of this document. In the accompanying drawings, similar symbols typically identify similar components unless the context indicates otherwise. The illustrated embodiments described in the detailed description, drawings, and claims are not meant to be limiting. Other embodiments may be used, and other changes may be made, without departing from the spirit or scope of the subject matter presented herein.
[0088] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A web application automated testing method, characterized in that: The steps include: Step 1: Build an agent and process the natural language request into a standardized output through the prompt function, wherein the standardized output includes the interface call address; Step 2: Send the standardized output to the textToAPI service, and the textToAPI service requests the interface call address and obtains a status code indicating a successful request; Step 3: After receiving the call request, the node service executes the corresponding logic and calls the puppeteer component to implement the required functions; Step 4: The puppeteer component simulates user operations, monitors all xhr requests and records the acquired data to complete the automated testing of the web application.
2. The web application automated testing method according to claim 1, characterized in that: In step 1, the prompt function processes the natural language into standardized output including the URL address and the interface call address, inputs the standardized output into the big model, the big model identifies the corresponding parameters, and the big model sends the corresponding parameters to the textToAPI service.
3. The web application automated testing method according to claim 2, characterized in that: In step 2, after the textToAPI service request for the interface call address fails, the failure result is returned to the big model, which is converted into a natural language expression through the processing of the big model and returned to the user.
4. The web application automated testing method according to claim 1, characterized in that: In step 3, calling corresponding interfaces includes: traversing the website to obtain page content interface, obtaining user name and password automatic login interface, obtaining cookies login interface and clicking buttons found in the page.
5. The web application automated testing method according to claim 1, characterized in that: The puppeteer component is called to achieve the required functions: control headless Chrome through the DevTools protocol, complete the work done manually in the browser, and achieve the purpose of simulating user operations.
6. The web application automated testing method according to claim 1, characterized in that: In step 4, node.JS in the puppeteer component listens to all xhr requests during execution and records the acquired data, including: when a new page is opened, the xhr request return result of the new page is recorded.
7. The web application automated testing method according to claim 6, characterized in that: Also includes: For pages that require a username and password to log in, the login information or valid cookies are entered into the big model, and the big model passes the input information to the node service through the corresponding interface for subsequent execution of the logic.
8. The web application automated testing method according to claim 1, characterized in that: For natural language requests with unclear purposes, the big model will ask the user questions through several rounds of dialogue, combining the user's questions with the big model's answers as context input, and repeat steps 1 to 4.
9. A web application automated testing system using the web application automated testing method according to any one of claims 1 to 8, characterized in that: include: The input module is the user dialogue entry, which passes the natural language request entered by the user to the prompt module; The prompt module processes the natural language request into a standardized output and sends it to the large model module; The large model module infers the user's purpose based on the standardized output and outputs the interface that the user needs to call; The interface calling module makes an HTTP request based on the interface information that needs to be called output by the large model module; The node backend module receives the http request and performs corresponding backend logic processing, and calls the puppeteer module; puppeteer module, which directly controls the Chromium module through the Devtools protocol; Chromium module, puppeteer module simulates real user operations by calling Chromium using a headless or non-headless browser.
10. A server, characterized in that: include: memory and at least one processor; The memory stores a computer program, and the at least one processor executes the computer program stored in the memory to implement the web application automated testing method according to any one of claims 1 to 8.
Citation Information
Cited By
Method and system for tracing source data based on enterprise business application software interface data
CN120821759A
A method and system for tracing source data based on enterprise business application software interface data.
CN120821759B