Get and set cookie support in Zoho QEngine | Zoho QEngine Help

Get and set cookie support in Zoho QEngine

1. In a nutshell

Cookie support in Zoho QEngine allows users to capture and use browser cookies during test automations. This enables efficient session handling, such as maintaining login state across multiple test cases or test plans.

2. Overview

Modern web applications rely heavily on cookies to manage user sessions, preferences, and authentication states. In test automation, especially for workflows involving login or user-specific behavior, managing these cookies efficiently is crucial to avoid redundant test scripts and improving execution time.

Zoho QEngine provides cookie support abilities through the get cookies and set cookies tasks, allowing you to extract and apply cookies during test execution.

With QEngine’s cookie management abilities, you can:
  1. Use get cookies to capture cookies from an active browser session after login or any authenticated action

  2. Reuse those captured cookies across multiple test cases or test plans using set cookies
  3. Simulate an authenticated user session without repeating login steps for each test

  4. Maintain consistent session states across repeated or parallel test executions 
In this document you'll learn how Zoho QEngine handles cookie management and how to use cookies for your automation test scenarios.

3. Cookie tasks

You can capture all cookies from the active browser session and store them in a variable.

Syntax
getcookies("<variable_name>");

Parameter
Description
<variable_name>
Name of the variable to store the cookies.
NotesNote: This is a temporary variable that can be used to hold the cookie object during test execution. It is not stored in your Variables tab.
You can insert previously stored cookies into the browser session being tested to simulate an authenticated or preconfigured state.

Syntax

setCookies("<domain_name>", "<variable_name>");

Parameter
Description
<domain_name>
The domain for which the cookies should be applied.
<variable_name>
The variable holding cookie objects.

Possible values:
  1. Cookie object fetched using the get cookies task 
  2. Cookie value stored locally in a QEngine variable 
Notes

Note:

1. In order to save a cookie manually, it must be in a key-value format. If you use the get cookie task, QEngine returns the full cookie object. You'll need to manually extract and paste only the required key-value pairs to reuse the cookie in your test script.

2. Cookies are passed as key=value pairs; some web URLs expect multiple cookies to be sent in a single string. To handle this, you can store multiple cookies in one variable by joining the key-value pairs with semicolons (;).

<variable_name> =<key1=value1>;<key2=value2>;<key3=value3>

For example,

cookieVar=token=abc123; sessionid=xyz789

3.3 Example

To optimize your automated testing workflow, especially for scenarios that require a logged-in user, you can leverage session cookie management using get and set cookies. 

After successfully logging in to the application, use the get cookies task to save the authentication cookies. This enables reuse across multiple test cases.
  1. getcookies("authCookies");
Before executing a test case that requires an authenticated session, inject the stored cookies using the set cookies task.
  1. setCookies("zylker.com", "authCookies");

4. Use cases

Use case 1: Reusing authentication across test cases using cookies
In this use case, we demonstrate a test plan used to automate an end-to-end scenario in a mining management platform. Each step in the user flow is represented by its own test case, covering signing in, reusing authentication via cookies, and performing operations such as adding mines.

Test Case 1: Signing in and capturing the authentication cookie
The first test case covers the sign-in process. Upon successful login, the session cookie is extracted using the get cookie task. This cookie holds the authenticated state, which will be reused in subsequent test cases.



Test Case 2 (Function): Parsing cookies via the login function
The cookie_login() function applies the stored cookie fetched from test case 1, using the set cookie task. This approach programmatically restores the authentication session in a reusable manner.


This function can be reused across any test case throughout the test plan in order to maintain a logged-in state without repeating the login flow.

Test Case 3: Performing authenticated operations
The login function in test case 2 restores the session, allowing this test case to proceed with authenticated operations such as adding a mine to the platform.


Example 2: Using pre-saved cookies for flexible test execution
In this use case, we demonstrate how to create a flexible test case that logs in using a pre-saved cookie stored in a variable without needing to interact with the login form. QEngine provides built-in functions, such as IS_PREVIEW_RUN,  that allow your script to adapt automatically based on the type of execution. This ensures the test behaves appropriately, whether it's running as a live preview or as part of a full test plan.

In the following script, if the test is running in live preview, it uses the pre-saved cookie variable ($cookie_value) for authentication. If the test is running as part of a test plan, it retrieves the session cookie from the browser actions created by previous test cases, saves it into a variable ("login_cookie"), and applies it using the set cookie task.

5. Related links

  1. Test cases
  2. Variables 

6. What's next

Next step
Next step
You can now start using get and set cookie tasks within your test scripts to manage session states and simulate user behavior.