Methods, apparatus, devices, and storage media for implementing Selenium session sticking

By configuring a session sticky module in Nginx to obtain and set session identifiers, establish routing files and shared caches, the issue of Selenium clients not supporting cookies was resolved, enabling session sticky connections in the Selenium cluster and improving testing efficiency.

CN119030961BActive Publication Date: 2025-11-14CCB FINTECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411249134.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-06
Publication Date
2025-11-14
Estimated Expiration
2044-09-06

AI Technical Summary

Technical Problem

The existing Selenium client does not support receiving and sending cookies returned by the server, which makes it difficult to maintain session connections, affects testing efficiency, and requires a huge amount of work to modify due to the large number of client versions.

Method used

By configuring a session sticking module in Nginx, session identifiers can be obtained and set, routing files and shared caches can be established, enabling session sticking in Selenium cluster scenarios without modifying client code.

Benefits of technology

It enables session sticking in Selenium cluster scenarios, supports the normal operation of existing UI automation cases in the cluster, reduces case migration and resource waste, and improves testing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119030961B_ABST
    Figure CN119030961B_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, device, and storage medium for implementing Selenium session sticking. It relates to the field of big data processing technology. The method includes: receiving an HTTP request; when the HTTP request is a Selenium hub-related request and a request to create a new Selenium session, obtaining a first session identifier; determining the corresponding routing information based on the first session identifier and setting a routing file; processing the HTTP request by reading the routing file through the Selenium hub; receiving an HTTP response; when the HTTP response is a Selenium hub-related response and a response to create a new Selenium session, obtaining a second session identifier; determining the corresponding routing information based on the second session identifier and adding a mapping relationship to a shared cache; and sending an HTTP response to the client. This method improves the testing efficiency of using Selenium.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data processing technology, and in particular to a method, apparatus, device and storage medium for implementing Selenium session sticking. Background Technology

[0002] Selenium is a free and open-source tool for automating web application testing. It supports multiple browsers and operating system languages, and runs directly within the browser, simulating real user interactions with web pages. Its main functions include testing browser compatibility and web system functionality, making it one of the most widely used web application automation testing tools.

[0003] Selenium Grid is a framework used to execute Selenium tests. It allows tests to run in parallel across multiple platforms, centrally managing different browser versions and configurations. These platforms are controlled by a central point called a Hub, while the different platforms are called Nodes. During testing, the client program communicates with the Hub, which forwards the test commands to the browsers on the corresponding Nodes. The browsers then execute the commands and return the results to the client program. To build a Selenium Hub cluster, Nginx is needed as a reverse proxy. Nginx is a high-performance HTTP and reverse proxy web server. Selenium requests are stateful; the same test session needs to be routed to the same backend Selenium Hub server, requiring session concatenation to achieve this functionality.

[0004] Current session persistence relies on setting routing information in a file (cookie) and returning it to the requesting client. The client then sends the corresponding cookie to Nginx on subsequent requests to maintain session persistence. However, the Selenium client currently does not support receiving or sending cookies returned by the server, requiring modifications to the client-side code. Selenium clients support multiple languages ​​and have numerous versions, with different projects using different versions. This represents a significant workload for client-side modifications and necessitates continuous updates with Selenium version upgrades, impacting testing efficiency. Summary of the Invention

[0005] This application provides a method, apparatus, device, and storage medium for implementing Selenium session sticking, which can improve the testing efficiency of Selenium.

[0006] Firstly, this application provides a method for implementing Selenium session stickiness, including:

[0007] Receive HTTP requests sent by the client;

[0008] When the HTTP request is a Selenium hub-related request and is not a request to create a new Selenium session, obtain the first session identifier of the HTTP request.

[0009] Determine the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and set the routing file;

[0010] HTTP requests are processed by reading the routing file through the Selenium hub;

[0011] Receive HTTP responses sent by the Selenium hub;

[0012] When the HTTP response is a Selenium hub-related response and a response indicating a new Selenium session, obtain the second session identifier of the HTTP response.

[0013] The Selenium hub routing information corresponding to the HTTP response is determined based on the second session identifier, and the mapping relationship between the second session identifier and the Selenium hub routing information is added to the shared cache;

[0014] Send an HTTP response to the client.

[0015] Secondly, this application provides an apparatus for implementing Selenium session sticking, comprising:

[0016] The receiving module is used to receive HTTP requests sent by the client;

[0017] The parsing module is used to obtain the first session identifier of an HTTP request when the HTTP request is related to Selenium Hub and is not a request to create a new Selenium session; it determines the Selenium Hub routing information corresponding to the HTTP request based on the first session identifier and sets the routing file accordingly.

[0018] The processing module is used to process HTTP requests by reading the routing file through the Selenium hub.

[0019] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;

[0020] The memory stores instructions that the computer executes;

[0021] The processor executes computer-executable instructions stored in memory to implement a method as described in any of the first aspects.

[0022] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement a method as described in any of the implementations of the first aspect.

[0023] Fifthly, this application provides a computer program product, including a computer program that, when executed by a processor, implements a method as described in any of the implementations of the first aspect.

[0024] The method, apparatus, device, and storage medium for implementing Selenium session sticking provided in this application, upon receiving an HTTP request from a client, if the HTTP request is a Selenium hub-related request and not a request to create a new Selenium session, obtains the first session identifier of the HTTP request, then determines the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and sets the routing file, and finally processes the HTTP request by reading the routing file through the Selenium hub. Upon receiving an HTTP response from the Selenium hub, if the HTTP response is a Selenium hub-related response and is a request to create a new Selenium session... When the Selenium session responds, it obtains the second session identifier of the HTTP response, then determines the Selenium hub routing information corresponding to the HTTP response based on the second session identifier, adds the mapping relationship between the second session identifier and the Selenium hub routing information to the shared cache, and finally sends the HTTP response to the client. This achieves session stickiness in the Selenium hub cluster scenario without modifying any Selenium client code. It supports the normal operation of existing Selenium-based UI automation cases in the Selenium service cluster, reduces the duplication of case porting and the construction of separate test execution environments, and improves testing efficiency. Attached Figure Description

[0025] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0026] Figure 1 The flowchart of the method for implementing Selenium session sticking provided in the embodiments of this application Figure 1 ;

[0027] Figure 2 The flowchart of the method for implementing Selenium session sticking provided in the embodiments of this application Figure 2 ;

[0028] Figure 3This is a schematic diagram of the device for implementing Selenium session adhesion provided in an embodiment of this application;

[0029] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.

[0030] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0031] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims. The acquisition, storage, use, and processing of data in the technical solutions of this application all comply with the relevant provisions of national laws and regulations.

[0032] It should be noted that in the embodiments of this application, certain software, components, models and other existing solutions in the industry may be mentioned. These should be regarded as exemplary and are only intended to illustrate the feasibility of implementing the technical solution of this application. However, it does not mean that the applicant has used or necessarily used the solution.

[0033] Figure 1 The flow of the method for implementing Selenium session sticking provided in the embodiments of this application Figure 1 .like Figure 1 As shown, the method for implementing Selenium session stickiness includes:

[0034] Step S110: Receive the HTTP request sent by the client.

[0035] The method for implementing Selenium session sticking in this embodiment can be applied to session sticking in a Selenium cluster scenario. A Selenium scenario includes a hub and nodes, each located on a different terminal. These terminals interact with the Selenium Hub hosted on the server via Selenium clients. Clients on each node forward test commands sent by the hub to the browser on the node, and the browser returns the execution results to the client program. In a Selenium cluster, Nginx acts as a reverse proxy, and the same test session is routed to the same backend Selenium Hub server. Therefore, it is necessary to stick sessions on the same node to achieve the same routing.

[0036] The method provided in this application, combining nginx and Selenium Hub technologies, offers a way to create and maintain a unified Selenium Hub cluster. The method is applied to the server side. First, during the access phase of each Selenium client, a Hypertext Transfer Protocol (HTTP) request is received from the client. This HTTP request is sent by the browser of the node where the Selenium client resides.

[0037] Step S120: When the HTTP request is a Selenium hub-related request and not a request to create a new Selenium session, obtain the first session identifier of the HTTP request.

[0038] Upon receiving an HTTP request, it is determined whether the request is related to Selenium Hub, as information in the Selenium Hub cluster contains Selenium Hub-related attributes. Specifically, this can be done by parsing the Uniform Resource Locator (URL) of the HTTP request and then using regular expressions to determine if the URL begins with " / wd / hub," thus identifying whether the HTTP request is related to Selenium Hub.

[0039] If the HTTP request is related to Selenium Hub, the next step is to determine whether it's a request to create a new Selenium session. Requests to create a new Selenium session have specific characteristics, which can be determined by analyzing the HTTP request. Specifically, the URL of the HTTP request can be parsed, and a regular expression can be used to determine if the URL begins with " / wd / hub / session". If the HTTP request is not a request to create a new Selenium session, the first session identifier (session ID) is obtained. The first session identifier is used to identify the session to which the HTTP request belongs. For example, the first session identifier can be obtained by using a regular expression to extract the string after " / wd / hub / session" from the HTTP request URL.

[0040] Step S130: Determine the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and set the routing file.

[0041] After determining the first session identifier corresponding to the HTTP request, the Selenium Hub routing information corresponding to the HTTP request is determined based on the first session identifier. This means determining the routing information of the session on the backend Selenium Hub server when it was created. A separate cache can be set up to store the mapping between session identifiers and routing information. The corresponding Selenium Hub routing information can be obtained by querying the cache based on the first session identifier. Then, the routing file (cookie) is set based on the retrieved routing information. A cookie is a text file associated with a specific World Wide Web (web) document, storing information about when a client accesses that web document. When the client accesses the web document again, the information in this file can be used by the web document. The information set in the routing cookie can be determined by the glue module configured in Nginx.

[0042] Specifically, the process of determining routing information based on the first session identifier may include: querying the shared cache for matching Selenium Hub routing information based on the first session identifier and setting a routing file cookie. The shared cache is a cache configured within the Nginx functionality; it means that it is shared for HTTP requests and HTTP responses, and the mapping relationship between the session ID and routing information corresponding to the same session is stored in the shared cache.

[0043] Step S140: Process HTTP requests by reading the routing file through the Selenium hub.

[0044] After setting the corresponding information in the route cookie of the received HTTP request, the HTTP request can be processed by reading the route cookie through Selenium Hub. This includes forwarding the HTTP request according to the information set in the route cookie. Since the route cookie is set after determining the first session identifier and the corresponding route information for the HTTP request, HTTP requests corresponding to the same session will be configured with the same route information, which means that session sticking is achieved. HTTP requests in the same session will be forwarded to the same route destination, which is the same as the traditional session sticking processing method in Selenium Hub.

[0045] It should be noted that in this embodiment, the Nginx configured with the session sticking module receives the HTTP request, obtains the first session identifier, and sets the route cookie. That is, steps S110-S130 can all be implemented by Nginx functionality. For example, an Nginx that supports Lua, such as Tengine or OpenResty (which requires the session sticking module to be configured), can be used.

[0046] Step S150: Receive the HTTP response sent by the Selenium hub.

[0047] The method provided in this embodiment is used in scenarios involving Selenium session stickiness, where Selenium Hub forwards the processed HTTP response to the client. After the client node forwards the HTTP request through Selenium Hub, Selenium Hub will also send the HTTP response processed by the backend server to the client node.

[0048] Step S160: When the HTTP response is a Selenium hub-related response and a response to create a new Selenium session, obtain the second session identifier of the HTTP response.

[0049] After receiving the HTTP response, determine if it is a Selenium Hub-related response, as information in the Selenium Hub cluster has Selenium Hub-related attributes. Specifically, this can be done by parsing the HTTP response URL and then using regular expressions to determine if the URL starts with " / wd / hub", thus identifying whether the HTTP response is related to Selenium Hub.

[0050] If the HTTP response is related to Selenium Hub, the next step is to determine if it's a response indicating a new Selenium session. Responses indicating a new Selenium session have specific characteristics, which can be analyzed to determine if the HTTP response is for a new Selenium session. Specifically, the URL of the HTTP response can be parsed, and a regular expression can be used to determine if the URL begins with " / wd / hub / session". If the HTTP response is for a new Selenium session, the second session identifier (session ID) is obtained. This second session identifier represents the session to which the new Selenium session belongs. The second session identifier can be obtained from the HTTP response header's set-cookie file. Selenium Hub processes HTTP requests indicating a new Selenium session by adding a cookie setting in the set-cookie header of the corresponding HTTP response. Therefore, the set-cookie header of the HTTP response can be iterated to obtain cookies with predefined names, from which the second session identifier can be retrieved.

[0051] Step S170: Determine the Selenium hub routing information corresponding to the HTTP response based on the second session identifier and add the mapping relationship between the second session identifier and the Selenium hub routing information to the shared cache.

[0052] After determining the second session identifier corresponding to the HTTP response, the Selenium Hub routing information corresponding to the HTTP response is determined based on the second session identifier. This means determining the routing information of the session on the backend Selenium Hub server at the time of its creation. This routing information can be obtained from the `set-cookie` header of the HTTP response. The `set-cookie` header of the HTTP response can be traversed to obtain cookies with predefined names, and the routing cookie for the session sticky module can be retrieved from it, along with the routing string inside the session sticky module. Then, the mapping relationship between the second session identifier and the Selenium Hub routing information is stored in a shared cache. The shared cache stores the mapping relationship between the session identifier and routing information for each session. In step S130, the Selenium Hub routing information determined based on the first session identifier can be retrieved from this shared cache.

[0053] Step S180: Send an HTTP response to the client.

[0054] After completing the above processing, the client can be sent an HTTP response to complete the forwarding of the HTTP response.

[0055] It should be noted that in this embodiment, after receiving the HTTP response, Nginx, which is configured with a session sticking module, processes it and sends it to the client. That is, steps S150-S180 can all be implemented by nginx functionality.

[0056] The method for implementing Selenium session sticking provided in this embodiment, after receiving an HTTP request sent by a client, obtains the first session identifier of the HTTP request when the HTTP request is a Selenium hub-related request and not a request to create a new Selenium session. Then, based on the first session identifier, it determines the Selenium hub routing information corresponding to the HTTP request and sets the routing file. Finally, it processes the HTTP request by reading the routing file through the Selenium hub. After receiving an HTTP response sent by the Selenium hub, if the HTTP response is a Selenium hub-related response and a response to create a new Selenium session, it obtains the second session identifier of the HTTP response. Then, based on the second session identifier, it determines the Selenium hub routing information corresponding to the HTTP response and adds the mapping relationship between the second session identifier and the Selenium hub routing information to the shared cache. Finally, it sends the HTTP response to the client. This achieves session sticking in a Selenium hub cluster scenario without modifying any Selenium client code. It supports the normal operation of existing Selenium-based UI automation cases in the Selenium service cluster, reduces the duplication of case porting and the construction of separate test execution environments, and improves testing efficiency.

[0057] After receiving an HTTP request from the client, if the HTTP request is for establishing a new Selenium session, Selenium Hub processes the HTTP request and then stores the first session identifier in a predefined cookie in the `set-cookie` header of the HTTP response corresponding to the HTTP request. In other words, after receiving an HTTP request from the client, if it is determined to be a request to establish a new Selenium session, Selenium Hub adds the obtained first session identifier of the new session at the end of the new Selenium session processing, and adds a new cookie with a predefined name (e.g., `wdsessionid`) to the `set-cookie` header of the HTTP response corresponding to the HTTP request. Thus, when the next HTTP request is sent from the session corresponding to this HTTP request, after receiving the HTTP request, the process described in steps S110-S140 can be executed.

[0058] Furthermore, after receiving the HTTP response sent by Selenium Hub, if the HTTP response is a Selenium Hub-related response and is a Selenium session deletion response, the second session identifier of the HTTP response is obtained; the mapping relationship between the second session identifier and the Selenium Hub routing information in the shared cache is deleted.

[0059] In other words, after receiving an HTTP response and determining if it's a Selenium Hub-related response, the system further determines if the HTTP response is a Selenium session deletion response. This can be done by parsing the HTTP response to obtain the HTTP response method name. If the HTTP response method name is "delete," the second session identifier of the HTTP response is obtained. The second session identifier can be obtained by parsing the HTTP response URL. Specifically, by parsing the HTTP response URL and then using a regular expression to extract the string after " / wd / hub / session," the second session identifier is obtained. After determining the second session identifier, the mapping relationship between the second session identifier and the Selenium Hub routing information in the shared cache can be deleted; that is, the relevant information for this session will be unlinked. It should be noted that the order in which the HTTP response is determined to be a Selenium session creation response or a Selenium session deletion response after receiving the HTTP response from Selenium Hub is not important.

[0060] After receiving an HTTP response from Selenium Hub, if the HTTP response is not related to Selenium Hub or is not a response to a newly established Selenium session, then the HTTP response is sent directly to the client. In other words, after receiving an HTTP response from Selenium Hub, if it is determined that the HTTP response is not related to a Selenium Hub request or is not a response to a newly established Selenium session, then the HTTP response is sent directly to the client.

[0061] Figure 2 The flow of the method for implementing Selenium session sticking provided in the embodiments of this application Figure 2 .like Figure 2 As shown, the method for implementing Selenium session sticking provided in this embodiment is a complete implementation method.

[0062] First, this implementation provides a method for achieving Selenium session sticking, including parts implemented by nginx and parts implemented by Selenium Hub. It uses an nginx version that supports Lua, such as Tengine or OpenResty (which requires configuring the session sticking module). Then, shared cache settings are configured, using `lua_shared_dict` to declare the name (e.g., `wdsessions`) and size of the shared mapping data structure. Finally, the corresponding session sticking module needs to be configured.

[0063] The method in this embodiment can be divided into an HTTP request processing process, an HTTP request response process, and a new session request processing process.

[0064] The HTTP request processing is handled by nginx. During the access phase of Nginx's HTTP request handling, Lua is used for the following processing:

[0065] 1) Determine if it is a Selenium Hub related request.

[0066] (1) Obtain the URL of the HTTP request through Nginx (OpenResty) request variables

[0067] (2) Use regular expressions to determine whether the HTTP request URL starts with a specific identifier, such as whether it starts with " / wd / hub".

[0068] (3) If so, proceed to step 2); otherwise, end the process, which means directly sending the HTTP request to Selenium Hub.

[0069] 2) Determine if it is a new Selenium session request.

[0070] (1) Use regular expressions to determine whether the HTTP request URL starts with a specific identifier, such as whether it starts with " / wd / hub / session / ".

[0071] (2) Otherwise proceed to step 3), otherwise end, that is, directly send the HTTP request to seleniumhub.

[0072] 3) Obtain the session ID of the requested access: Extract the string after a specific identifier in the HTTP request URL using a regular expression, such as " / wd / hub / session / ", which is the session ID.

[0073] 4) Query the routing information of the backend Hub server where this session was created based on the session ID.

[0074] Query the corresponding route information in the shared cache storage structure using the session ID.

[0075] For example, this includes local session information and local routing information.

[0076] 5) Set cookies based on routing information (the name is determined by the session binding module configuration).

[0077] For example, it includes routing information and file information, with the file information including file packet header information.

[0078] The process of creating a new session request is implemented by Selenium Hub. The following is added to the end of the original Selenium Session creation process:

[0079] 1) Obtain the Session ID of the newly created Session

[0080] 2) Add a new cookie in the HTTP header Set-Cookie using a predefined name (such as wdsessionid) and set wdsessionid="New SessionId".

[0081] The HTTP response processing is handled by nginx. During the content processing phase of the HTTP request, Nginx uses Lua to perform the following steps:

[0082] 1) Determine if it is a Selenium Hub related response.

[0083] (1) Obtain the HTTP response URL through Nginx (OpenResty) request variables

[0084] (2) Use regular expressions to determine whether the HTTP response URL starts with a specific identifier, such as whether it starts with " / wd / hub".

[0085] (3) If so, proceed to step 2); otherwise, end the process, which means directly sending the HTTP response to the client.

[0086] 2) Determine if it is a newly created Selenium session response.

[0087] (1) Use regular expressions to determine whether the HTTP response URL starts with a specific identifier, such as whether it starts with " / wd / hub / session / ".

[0088] (2) Otherwise proceed to step 3; otherwise, skip to step 4.

[0089] 3) Save the mapping relationship between session IDs and backend routes.

[0090] (1) By iterating through the Set-cookie header of the HTTP response, obtain the cookie with the predefined name (e.g., wdsessionid) and obtain the newly created session ID.

[0091] (2) By traversing the Set-cookie header of the HTTP response, obtain the route cookie of the session sticky module and the route string inside the session sticky module.

[0092] (3) If there are any errors in (1) or (2) above, then the process ends, that is, the HTTP response is sent directly to the client.

[0093] (4) Write the shared cache mapping structure: the mapping relationship between the new session ID obtained in step (1) and the route string obtained in step (2).

[0094] 4) Determine if it is a Selenium session deletion response.

[0095] (1) Obtain the HTTP response method name through a specific request retrieval method.

[0096] (2) If the method name is "DELETE", then continue; otherwise, end.

[0097] (3) Obtain the session ID requested for access.

[0098] Extracting the session ID from the HTTP response URL using regular expressions, for example, the string following a specific identifier, such as " / wd / hub / session / ".

[0099] (4) Delete the mapping relationship with session ID as key in the shared storage mapping structure.

[0100] The technical solution provided in this application embodiment can support the construction of a unified Nginx as the front end within an enterprise, a Selenium server cluster supporting multiple hubs, a unified UI automation execution environment service, unified coordination and allocation of environment resources, and improved efficiency.

[0101] Figure 3 This is a schematic diagram of the device for implementing Selenium session sticking provided in an embodiment of this application. Figure 3 As shown, the device for implementing Selenium session sticking includes: a receiving module 310, a parsing module 320, a processing module 330, and a sending module 340.

[0102] The receiving module 310 is used to receive HTTP requests sent by the client.

[0103] The parsing module 320 is used to obtain the first session identifier of the HTTP request when the HTTP request is a Selenium Hub related request and is not a request to create a new Selenium session; determine the Selenium Hub routing information corresponding to the HTTP request based on the first session identifier and set the routing file cookie.

[0104] Processing module 330 is used to process HTTP requests by reading routing cookies through Selenium Hub.

[0105] The receiving module 310 is also used to receive HTTP responses sent by Selenium Hub. The parsing module 320 is also used to obtain the second session identifier of the HTTP response when the HTTP response is a Selenium Hub-related response and a response to a newly established Selenium session; determine the Selenium Hub routing information corresponding to the HTTP response based on the second session identifier and add the mapping relationship between the second session identifier and the Selenium Hub routing information to the shared cache. The sending module 340 is used to send an HTTP response to the client.

[0106] In some embodiments, the parsing module 320 is specifically used to query matching Selenium Hub routing information in the shared cache based on the first session identifier and set a routing file cookie.

[0107] In some embodiments, the parsing module 320 is specifically used to obtain the second session identifier of the HTTP response when the HTTP response is a Selenium Hub related response and a Selenium session deletion response; and to delete the mapping relationship between the second session identifier and the Selenium Hub routing information in the shared cache.

[0108] In some embodiments, the parsing module 320 is specifically used to obtain the second session identifier through the HTTP response header set-cookie; and to obtain the Selenium Hub routing information corresponding to the HTTP response through the HTTP response header set-cookie.

[0109] In some embodiments, the sending module 340 is further configured to send an HTTP response directly to the client if the HTTP response is not a Selenium hub-related request or a new Selenium session response.

[0110] In some embodiments, the parsing module 320 is specifically used to traverse the HTTP response header set-cookie to obtain a predefined cookie; obtain a second session identifier from the predefined cookie; traverse the HTTP response header set-cookie to obtain a session sticking module routing cookie; and obtain the Selenium Hub routing information corresponding to the HTTP response from the session sticking module routing cookie.

[0111] In some embodiments, the parsing module 320 is further configured to obtain the URL of the HTTP request; determine whether the HTTP request is a Selenium Hub related request and whether the HTTP request is a request to create a new Selenium session based on the URL.

[0112] In some embodiments, the processing module 330 is further configured to, if the HTTP request is a request to create a new Selenium session, process the HTTP request by reading the routing cookie through Selenium Hub, and then, through Selenium Hub, store the first session identifier in the predefined cookie in the set-cookie header of the HTTP response corresponding to the HTTP request.

[0113] In some embodiments, the processing module 330 is further configured to send the HTTP response directly to the client if the HTTP response is not a Selenium Hub related response or the HTTP response is not a new Selenium session response.

[0114] In some embodiments, an Nginx instance configured with a session sticking module receives an HTTP request, obtains a first session identifier, and sets a route cookie.

[0115] In some embodiments, the Nginx instance configured with the session sticking module receives the HTTP response, processes it, and then sends it to the client.

[0116] The apparatus for implementing Selenium session sticking provided in this application embodiment can be used to execute the technical solution of the method for implementing Selenium session sticking in the above embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.

[0117] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented in software via processing element calls, while others are implemented in hardware. For example, the receiving module 310, parsing module 320, processing module 330, and transmitting module 340 can all be separate processing elements, or they can be integrated into a single chip in the above device. Alternatively, they can be stored as program code in the memory of the above device, and their functions can be called and executed by a processing element of the above device. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0118] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device may include: transceiver 41, processor 42, and memory 43.

[0119] Processor 42 executes computer execution instructions stored in memory, causing processor 42 to perform the scheme in the above embodiments. Processor 42 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0120] The memory 43 is connected to the processor 42 via the system bus and completes communication between them. The memory 43 is used to store computer program instructions.

[0121] Transceiver 41 can be used to obtain the task to be run and its configuration information.

[0122] The system bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. Transceivers are used to enable communication between database access devices and other computers (e.g., clients, read-write libraries, and read-only libraries). Memory may include random access memory (RAM) and may also include non-volatile memory.

[0123] The electronic device provided in this application embodiment can be a computer or server in a computer system capable of data processing.

[0124] This application also provides a chip for executing instructions, which is used to execute the technical solution of the method for implementing Selenium session sticking in the above embodiments.

[0125] This application also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed on a computer, the computer performs the technical solution of the method for implementing Selenium session sticking described in the above embodiments.

[0126] This application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When the at least one processor executes the computer program, it can implement the technical solution of the method for implementing Selenium session sticking in the above embodiments.

[0127] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0128] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A method for implementing Selenium session stickiness, characterized in that, include: Receive HTTP requests sent by the client; When the HTTP request is a Selenium hub-related request and not a request to create a new Selenium session, obtain the first session identifier of the HTTP request; Determine the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and set the routing file; The HTTP request is processed by reading the routing file through the Selenium hub; Receive the HTTP response sent by the Selenium hub; When the HTTP response is a Selenium hub-related response and a response to a new Selenium session, obtain the second session identifier of the HTTP response; Based on the second session identifier, determine the Selenium hub routing information corresponding to the HTTP response and add the mapping relationship between the second session identifier and the Selenium hub routing information to the shared cache; Send the HTTP response to the client.

2. The method according to claim 1, characterized in that, After receiving the HTTP response sent by the Selenium hub, the process further includes: When the HTTP response is a Selenium hub-related response and a Selenium session deletion response, obtain the second session identifier of the HTTP response; Delete the mapping relationship between the second session identifier and the Selenium hub routing information in the shared cache.

3. The method according to claim 1, characterized in that, The step of obtaining the second session identifier of the HTTP response includes: The second session identifier is obtained by setting the HTTP response header file; The step of determining the Selenium hub routing information corresponding to the HTTP response based on the second session identifier includes: The Selenium hub routing information corresponding to the HTTP response is obtained through the HTTP response header settings file.

4. The method according to claim 3, characterized in that, The step of obtaining the second session identifier through the HTTP response header settings file includes: Iterate through the HTTP response header settings file to obtain the predefined file; Obtain the second session identifier from the predefined file; The step of obtaining the Selenium hub routing information corresponding to the HTTP response through the HTTP response header settings file includes: Iterate through the HTTP response header settings file to obtain the session sticky module route file; Obtain the Selenium hub routing information corresponding to the HTTP response from the session sticky module routing file.

5. The method according to claim 1, characterized in that, After receiving the HTTP response sent by the Selenium hub, the process further includes: If the HTTP response is not a Selenium hub-related request or a response to create a new Selenium session, then the HTTP response is sent directly to the client.

6. The method according to any one of claims 1 to 5, characterized in that, The step of determining the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and setting the routing file includes: Based on the first session identifier, query the shared cache for matching Selenium hub routing information and set the routing file.

7. The method according to any one of claims 1 to 5, characterized in that, After receiving the HTTP request sent by the client, the method further includes: Obtain the address of the HTTP request; Based on the address, determine whether the HTTP request is a Selenium hub-related request and whether the HTTP request is a request to create a new Selenium session.

8. The method according to any one of claims 1 to 5, characterized in that, After receiving the HTTP request sent by the client, the method further includes: If the HTTP request is not a Selenium hub-related request or the HTTP request is a request to create a new Selenium session, then the Selenium hub will directly process the HTTP request. The first session identifier is stored in a predefined file in the HTTP response header settings file corresponding to the HTTP request via the Selenium hub.

9. The method according to any one of claims 1 to 5, characterized in that, After receiving the HTTP response sent by the Selenium hub, the process further includes: If the HTTP response is not a Selenium hub-related response or a response to a new Selenium session, then the HTTP response will be sent directly to the client.

10. The method according to any one of claims 1 to 5, characterized in that, The HTTP request is received by an Nginx instance configured with a session sticking module, which obtains the first session identifier and sets the routing file.

11. The method according to any one of claims 1 to 5, characterized in that, The HTTP response is received by Nginx, which is configured with a session sticking module, processed, and then sent to the client.

12. A device for implementing Selenium session sticking, characterized in that, include: The receiving module is used to receive HTTP requests sent by the client; The parsing module is used to obtain the first session identifier of the HTTP request when the HTTP request is a Selenium hub-related request and is not a request to create a new Selenium session; Determine the Selenium hub routing information corresponding to the HTTP request based on the first session identifier and set the routing file; The processing module is used to read the routing file through the Selenium hub and process the HTTP request; The receiving module is also used to receive the HTTP response sent by the Selenium hub; The parsing module is also used to obtain the second session identifier of the HTTP response when the HTTP response is a Selenium hub-related response and a response to a new Selenium session; Based on the second session identifier, determine the Selenium hub routing information corresponding to the HTTP response and add the mapping relationship between the second session identifier and the Selenium hub routing information to the shared cache; The sending module is used to send the HTTP response to the client.

13. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-11.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-11.

15. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1-11.

Citation Information

Patent Citations

  • Conversation maintaining method and device

    CN103457869A

  • Method, device and equipment for realizing session maintenance based on server cluster

    CN115720234A