User interface script file processing methods, apparatus and computer equipment

By intercepting and replacing the iframe parent jump instruction in the Cypress framework, the problem of Cypress framework's incompatibility with iframe parent jump was solved, and the automated testing was successfully carried out.

CN115237806BActive Publication Date: 2026-11-10GUANGZHOU PINWEI SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210961399.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-11
Publication Date
2026-11-10
Estimated Expiration
2042-08-11

AI Technical Summary

Technical Problem

In existing technologies, the Cypress framework is incompatible with iframe parent jump instructions, making it difficult to perform automated tests smoothly.

Method used

In the Cypress framework, intercept the script file sent by the server to the browser, find and replace the iframe parent's jump instruction, replace it with the appropriate instruction, generate a new script file, and send it to the browser for execution.

Benefits of technology

This solves the problem of incompatibility between iframe parent jump directives under the Cypress framework, increases framework compatibility, and ensures smooth automated testing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237806B_ABST
    Figure CN115237806B_ABST
Patent Text Reader

Abstract

This application provides a user interface script file processing method, apparatus, and computer device. When performing UI automation testing on a page to be tested based on the Cypress framework, the method intercepts a first script file sent by the server to the browser; the first script file is the script file of the page to be tested; it locates a first instruction in the first script file; the first instruction instructs the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe; it replaces the first instruction with a second instruction to obtain a second script file; the second instruction instructs the browser to display the content of the second page on the first page; and it sends the second script file to the browser. This method solves the problem of incompatibility between the Cypress framework and the parent iframe jump instruction, increases the compatibility when using the Cypress framework, and ensures that automation testing under the new framework is not affected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of Internet technology, and in particular to a method, apparatus and computer device for processing user interface script files. Background Technology

[0002] In the practice of implementing UI (User Interface) automated testing for web applications based on a browser / server architecture, automated testing is achieved by simulating user operations on the UI interface in the browser within a certain automated testing framework. With the development of web applications, new automated testing frameworks have emerged. However, to display the UI interface, the server needs to transmit the corresponding script files to the browser for execution. But because new automated testing frameworks are not yet fully developed, they are incompatible with certain instructions in the scripts, leading to difficulties in successfully performing automated testing. Summary of the Invention

[0003] The purpose of this application is to at least solve one of the aforementioned technical defects, particularly the technical defect in the prior art that is incompatible with iframe parent jump instructions.

[0004] In a first aspect, embodiments of this application provide a user interface script file processing method, including: When performing UI automation testing on the page to be tested based on the Cypress framework, intercept the first script file sent by the server to the browser; the first script file is the script file of the page to be tested. Locate the first instruction in the first script file; the first instruction is used to instruct the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe; Replace the first instruction with the second instruction to obtain the second script file; the second instruction is used to instruct the browser to display the content of the second page on the first page. Send the second script file to the browser.

[0005] In one embodiment, locating the first instruction in the first script file includes: Determine whether each instruction in the first script file contains the first string; The instruction containing the first string in the first script file is taken as the first instruction.

[0006] In one embodiment, determining whether each instruction in the first script file contains the first string includes: Construct a regular expression based on the first string; Regular expressions are used to match each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0007] In one embodiment, the first script file intercepting the server from sending to the browser includes: Configure the whistle tool between the browser and the server; Configure the first blocking rule within the whistle tool to block the first script file sent by the server to the browser.

[0008] Secondly, embodiments of this application provide a user interface script file processing apparatus, including: The interception module is used to intercept the first script file sent by the server to the browser; the first script file is the script file of the page to be tested, and the page to be tested is based on the Cypress framework for UI automation testing; The search module is used to find the first instruction in the first script file; the first instruction is used to jump from the child page corresponding to the current iframe to the parent page corresponding to the parent iframe of the current iframe. The replacement module is used to replace the first instruction with the second instruction to obtain a second script file; the second instruction is used to display the content of the parent page on the child page; The sending module is used to send the second script file to the browser.

[0009] In one embodiment, the search module includes a judgment subunit and a determination subunit; the judgment subunit is used to determine whether each instruction in the first script file contains a first string; the determination subunit is used to determine whether the instruction in the first script file containing the first string is a first instruction.

[0010] In one embodiment, the judgment subunit is used to construct a regular expression based on the first string; and to match the regular expression with each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0011] In one embodiment, the interception module includes a tool configuration subunit and an interception rule setting subunit; the tool configuration subunit is used to configure the whistle tool between the browser and the server; the interception rule setting subunit is used to set a first interception rule within the whistle tool to intercept the first script file sent by the server to the browser.

[0012] Thirdly, embodiments of this application provide a storage medium, characterized in that: the storage medium stores computer-readable instructions, which, when executed by one or more processors, cause one or more processors to perform the steps of the user interface script file processing method as described in any of the above embodiments.

[0013] Fourthly, embodiments of this application provide a computer device, including: one or more processors, and a memory; The memory stores computer-readable instructions, which, when executed by one or more processors, perform the steps of the user interface script file processing method as described in any of the above embodiments.

[0014] As can be seen from the above technical solutions, the embodiments of this application have the following advantages: Based on any of the above embodiments, when performing UI automation testing in the Cypress framework, the first script file is intercepted before the browser executes it. The first instruction, which is incompatible with the Cypress framework, is replaced with a second instruction that is compatible with the Cypress framework, resulting in a second script file. The browser executes the second script file, allowing instructions related to parent iframe navigation to run smoothly within the Cypress framework. This method solves the problem of incompatibility between the new Cypress UI automation testing framework and parent iframe navigation instructions, increasing compatibility when using the Cypress framework and ensuring that automation testing under the new framework is not affected. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 An application environment diagram of a user interface script file processing method provided in one embodiment of this application; Figure 2 A flowchart illustrating a user interface script file processing method provided in one embodiment of this application; Figure 3 This is a flowchart illustrating the process of finding the first instruction in one embodiment of this application; Figure 4 This is a flowchart illustrating an embodiment of the present application in determining whether an instruction is a first instruction; Figure 5 This is a flowchart illustrating the process of intercepting the first script file in one embodiment of this application; Figure 6 This is an internal structural diagram of a computer device in one embodiment of this application. Detailed Implementation

[0017] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0018] Firstly, embodiments of this application provide a user interface script file processing method, the application environment of which can be as follows: Figure 1 As shown. Server 104 can communicate with at least one browser 102. The automated testing framework targeted in this application is the Cypress framework. The Cypress framework can run test cases within the browser, enabling it to monitor and modify browser behavior at runtime by manipulating the DOM (Document Object Model) and dynamically modifying network requests and responses, thereby testing the UI of the web application rendered in the browser.

[0019] Please see Figure 2 The user interface script file processing method includes steps S202 to S208.

[0020] S202, when performing UI automation testing on the page to be tested using the Cypress framework, intercept the first script file sent by the server to the browser. The first script file is the script file of the page to be tested.

[0021] When running test cases for a web page within the Cypress framework, the page will be displayed in a browser. The web page serves as the user interface for a web application. During testing, the HTML (Hypertext Markup Language) document and script file (the first script file) of the web page are sent to the browser for execution. The HTML document provides the static content of the web page, while the first script file provides the dynamic content; it is typically a file with the .js extension.

[0022] The Cypress framework is a next-generation front-end automation testing tool built for modern web applications. As web application development technologies evolve, some older directives are gradually being replaced by newer ones, causing the Cypress framework to no longer support certain older directives. Therefore, it is necessary to modify some directives in the first script file, that is, to intercept them before the browser executes the first script file, in order to ensure that automated testing under the Cypress framework can proceed smoothly.

[0023] S204, Locate the first instruction in the first script file.

[0024] The first instruction is used to instruct the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe.

[0025] Specifically, this application addresses instructions related to iframe parent-level navigation. An iframe is an HTML element used to nest web pages within web pages. Multiple levels of iframes can be nested within an iframe; if an iframe is the parent iframe, then the iframes within that parent iframe are its child iframes. When interacting with a webpage, it's often necessary to display the content of a child iframe of a parent iframe. After entering the desired child iframe, further action may require displaying the content of another child iframe of the same parent iframe, necessitating a navigation back to the parent iframe. To facilitate this navigation from a child iframe back to its parent iframe, a first instruction is added to the first script file. Before executing the first instruction, the browser should display the content of the current iframe (the first page) in the current tab. When the browser executes the first instruction, a new tab is created, displaying the content of the parent iframe of the current iframe (the second page), and the browser switches from the current tab to the new tab, thus navigating from the first page to the second page.

[0026] In traditional web application development, iframes are heavily used for the process described above. However, with technological advancements, their use has decreased, and many newly developed web applications, even when needing to navigate to a parent iframe, do not open a new page but instead display the parent iframe's content on the current page. The Cypress framework, designed for newer web applications, has compatibility issues with this process. Currently, Cypress only supports UI automation testing within the same page. When a page switch occurs, test cases running in Cypress will stop. Therefore, if the first directive in the first script file exists, the automated test will stop, requiring modification of that directive.

[0027] S206, replace the first instruction with the second instruction to obtain the second script file.

[0028] The second instruction directs the browser to display the content of the second page on the first page. In other words, during testing, the effect of redirecting from the first page to the second page is transformed into displaying the content of the second page on the first page, thus showing the content of the second page without opening a new tab, ensuring smooth automated testing within the Cypress framework.

[0029] S208, send the second script file to the browser.

[0030] After changing the first script file to the second script file, executing the second script file in the browser within the Cypress framework will not cause the automated tests to stop, and the test results will be the same as when executing the first script file in other frameworks.

[0031] Based on the user interface script file processing method in this embodiment, when performing UI automation testing in the Cypress framework, the first script file is intercepted before the browser executes it. The first instruction, which is incompatible with the Cypress framework, is replaced with a second instruction that is compatible with the Cypress framework, resulting in a second script file. The browser then executes the second script file, allowing instructions related to parent iframe navigation to run smoothly within the Cypress framework. This method solves the problem of incompatibility between the new Cypress UI automation testing framework and parent iframe navigation instructions, increasing compatibility when using the Cypress framework and ensuring that automation testing under the new framework is not affected.

[0032] In one embodiment, please refer to Figure 3 The process of finding the first instruction in the first script file includes steps S302 and S304.

[0033] S302, determine whether each instruction in the first script file contains the first string.

[0034] S304, the instruction containing the first string in the first script file is the first instruction.

[0035] It can be understood that the first script file contains many instructions, each corresponding to a string, and the first string is the string corresponding to the first instruction. By checking each instruction in the first script file, it can be determined whether the instruction is the first instruction. At this point, the checked first instruction can be directly replaced with the second instruction, for example, using the `replace` command in JavaScript. After checking all instructions, the replacement work is also completed. Alternatively, after checking a first instruction, the position of each first instruction can be output, and after traversing all instructions in the first script file, the replacement can be performed according to the position of each first instruction. Furthermore, some programming languages ​​have built-in instructions that can simultaneously implement steps S204 and S206. In one embodiment, please refer to Figure 4 Determining whether each instruction in the first script file contains the first string includes steps S402 and S404.

[0036] S402, construct a regular expression based on the first string.

[0037] S404: Use regular expressions to match each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0038] Since the first script file can be considered as text consisting of multiple strings, and regular expressions are logical formulas for string manipulation, text can be filtered using preset strings to select text that matches the preset strings. Because the first instruction corresponds to the first string, the first string is used as the matching target of the regular expression. This regular expression is then matched against the character combinations corresponding to each instruction in the first script file to determine whether the instruction is the first instruction.

[0039] In one embodiment, please refer to Figure 5 The interception of the first script file sent by the server to the browser includes steps S502 and S504.

[0040] S502 configures the whistle tool between the browser and the server.

[0041] Whistle is a packet sniffing tool. Browsers access services by sending requests to servers, and servers respond with the data requested by the browser. Whistle can intercept both these requests and the data the server sends back. Essentially, Whistle acts as both a server and a client for the browser. Before using it, Whistle needs to be configured between the browser and the server. The configuration process is as follows: If Whistle is not already installed in the test environment for automated testing, install it first. After confirming successful installation, set the address of the proxy server in the test environment to the port address of Whistle. This completes the configuration of Whistle between the browser and the server. If you need to intercept data with higher security levels in certain transmission protocols, you will also need to install the corresponding certificates.

[0042] S504 sets the first blocking rule within the whistle tool to block the first script file sent by the server to the browser.

[0043] The Whistle tool allows you to configure interception rules as needed to filter out the required data from the large amounts of data transmitted between the server and the browser. The first interception rule can filter out the first script file. For the browser, after modifying the first script file, the Whistle tool can send the second script file to the browser for execution. Adding the Whistle tool does not affect the original browser / server architecture, maintaining consistency with the actual business environment.

[0044] Secondly, embodiments of this application provide a user interface script file processing apparatus, including an interception module, a search module, a replacement module, and a sending module. The interception module intercepts a first script file sent by a server to a browser. The first script file is the script file of a page to be tested, which performs UI automation testing based on the Cypress framework. The search module searches for a first instruction in the first script file. The first instruction is used to jump from the child page corresponding to the current iframe to the parent page corresponding to the parent iframe of the current iframe. The replacement module replaces the first instruction with a second instruction to obtain a second script file. The second instruction is used to display the content of the parent page on the child page. The sending module sends the second script file to the browser.

[0045] In one embodiment, the search module includes a judgment subunit and a determination subunit. The judgment subunit is used to determine whether each instruction in the first script file contains a first string. The determination subunit is used to determine whether the instruction in the first script file containing the first string is a first instruction.

[0046] In one embodiment, the judgment subunit is used to construct a regular expression based on the first string; and to match the regular expression with each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0047] In one embodiment, the interception module includes a tool configuration subunit and an interception rule setting subunit. The tool configuration subunit is used to configure the whistle tool between the browser and the server; the interception rule setting subunit is used to set a first interception rule within the whistle tool to intercept a first script file sent by the server to the browser.

[0048] Specific limitations regarding the user interface script file processing device can be found in the above-described limitations of the user interface script file processing method, and will not be repeated here. Each module in the user interface script file processing device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in the computer device in hardware form, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module. It should be noted that the module division in this embodiment is illustrative and only represents a logical functional division; other division methods may be used in actual implementation.

[0049] Thirdly, embodiments of this application provide a storage medium, characterized in that: the storage medium stores computer-readable instructions, which, when executed by one or more processors, cause the one or more processors to perform: When performing UI automation testing on the page to be tested based on the Cypress framework, intercept the first script file sent by the server to the browser; the first script file is the script file of the page to be tested. Locate the first instruction in the first script file; the first instruction is used to instruct the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe; Replace the first instruction with the second instruction to obtain the second script file; the second instruction is used to instruct the browser to display the content of the second page on the first page. Send the second script file to the browser.

[0050] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Determine whether each instruction in the first script file contains the first string; The instruction containing the first string in the first script file is taken as the first instruction.

[0051] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Construct a regular expression based on the first string; Regular expressions are used to match each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0052] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Configure the whistle tool between the browser and the server; Configure the first blocking rule within the whistle tool to block the first script file sent by the server to the browser.

[0053] In some embodiments, when computer-readable instructions are executed by one or more processors, the one or more processors cause the one or more processors to perform the steps of the user interface script file processing method as described in any of the above embodiments.

[0054] Fourthly, embodiments of this application provide a computer device, including: one or more processors, and a memory; The memory stores computer-readable instructions, which, when executed by one or more processors, perform the following: When performing UI automation testing on the page to be tested based on the Cypress framework, intercept the first script file sent by the server to the browser; the first script file is the script file of the page to be tested. Locate the first instruction in the first script file; the first instruction is used to instruct the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe; Replace the first instruction with the second instruction to obtain the second script file; the second instruction is used to instruct the browser to display the content of the second page on the first page. Send the second script file to the browser.

[0055] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Determine whether each instruction in the first script file contains the first string; The instruction containing the first string in the first script file is taken as the first instruction.

[0056] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Construct a regular expression based on the first string; Regular expressions are used to match each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

[0057] In one embodiment, when computer-readable instructions are executed by one or more processors, they cause one or more processors to perform the following: Configure the whistle tool between the browser and the server; Configure the first blocking rule within the whistle tool to block the first script file sent by the server to the browser.

[0058] In some embodiments, when computer-readable instructions are executed by one or more processors, the one or more processors cause the one or more processors to perform the steps of the user interface script file processing method as described in any of the above embodiments.

[0059] Indicatively, such as Figure 6 As shown, Figure 6 This is a schematic diagram of the internal structure of a computer device 300 provided in an embodiment of this application. The computer device 300 can be provided as a server. (Refer to...) Figure 6 The computer device 300 includes a processing component 302, which further includes one or more processors, and memory resources represented by memory 301 for storing instructions, such as application programs, that can be executed by the processing component 302. The application programs stored in memory 301 may include one or more modules, each corresponding to a set of instructions. Furthermore, the processing component 302 is configured to execute instructions to perform the user interface script file processing method of any of the above embodiments.

[0060] The computer device 300 may also include a power supply component 303 configured to perform power management of the computer device 300, a wired or wireless network interface 304 configured to connect the computer device 300 to a network, and an input / output (I / O) interface 305. The computer device 300 may operate on an operating system stored in memory 301, such as Windows Server™, Mac OS X™, Unix™, Linux™, Free BSD™, or similar.

[0061] Those skilled in the art will understand that Figure 6 The 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.

[0062] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.

[0063] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0064] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for processing user interface script files, characterized in that, include: When performing UI automation testing on the page to be tested based on the Cypress framework, intercept the first script file sent by the server to the browser; The first script file is the script file of the page to be tested; Locate the first instruction in the first script file; the first instruction is used to instruct the browser to jump from the first page corresponding to the current iframe to the second page corresponding to the parent iframe of the current iframe; The first instruction is replaced with the second instruction to obtain a second script file; the second instruction is used to instruct the browser to display the content of the second page on the first page. Send the second script file to the browser.

2. The method according to claim 1, characterized in that, The first instruction in the first script file includes: Determine whether each instruction in the first script file contains the first string; The instruction containing the first string in the first script file shall be the first instruction.

3. The method according to claim 2, characterized in that, Determining whether each instruction in the first script file contains the first string includes: Construct a regular expression based on the first string; The regular expression is used to match each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

4. The method according to claim 1, characterized in that, The first script file sent by the intercepting server to the browser includes: Configure the whistle tool between the browser and the server; A first blocking rule is set within the whistle tool to block the first script file sent by the server to the browser.

5. A user interface script file processing device, characterized in that, include: The interception module is used to intercept the first script file sent by the server to the browser; The first script file is the script file for the page to be tested, and the page to be tested is based on the Cypress framework for UI automation testing; The search module is used to search for the first instruction in the first script file; the first instruction is used to jump from the child page corresponding to the current iframe to the parent page corresponding to the parent iframe of the current iframe. A replacement module is used to replace the first instruction with a second instruction to obtain a second script file; the second instruction is used to display the content of the parent page on the child page. The sending module is used to send the second script file to the browser.

6. The apparatus according to claim 5, characterized in that, The search module includes a judgment subunit and a determination subunit; The judgment subunit is used to determine whether each instruction in the first script file contains the first string; The determination subunit is used to determine that the instruction containing the first string in the first script file is the first instruction.

7. The apparatus according to claim 6, characterized in that, The judgment subunit is used to construct a regular expression based on the first string; and to match the regular expression with each instruction in the first script file to determine whether each instruction in the first script file contains the first string.

8. The apparatus according to claim 5, characterized in that, The interception module includes a tool configuration subunit and an interception rule setting subunit; the tool configuration subunit is used to configure the whistle tool between the browser and the server; the interception rule setting subunit is used to set a first interception rule in the whistle tool to intercept the first script file sent by the server to the browser.

9. A storage medium, characterized in that: The storage medium stores computer-readable instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of the user interface script file processing method as described in any one of claims 1 to 4.

10. A computer device, characterized in that, include: One or more processors, and memory; The memory stores computer-readable instructions that, when executed by the one or more processors, perform the steps of the user interface script file processing method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Automatic testing method and device for user interface

    CN113704110A

  • Page processing method and apparatus, computer device and storage medium

    WO2022142312A1