Testim Documentation

Welcome to the Testim documentation. You'll find comprehensive guides to help you get started quickly, example code snippets, and tips for being more productive. You will also find details about advanced features that allow you to customize Testim to fit your environment or special testing conditions. Don't worry, we'll support you if you get stuck. Let's jump right in!

Get Started    Guides

Cookies

Getting and setting browser cookies

A cookie (also called web cookie, Internet cookie, or browser cookie) is a small piece of data sent from a website and stored on the user's computer by the user's web browser while the user is browsing. Cookies have a variety of uses but are mainly used for identifying users.
In the context of test automation, cookies can be leveraged to speed up the authentication process as the cookie can be set directly negating the need to perform the entire login flow.

Testim provides a variety of ways to set, get and handle cookies:

  • Cookie steps
  • Test Data
  • Custom JS (JavaScript) step
  • Configuration File & Run Hooks

Cookie steps

Cookie steps allow you to easily get and set cookies in the context of a test directly from the UI. This is also the recommended way to create HttpOnly and Secure cookies.

How to use the 'get cookie' step:

  • Hover over the arrow menu where you want to add the step.
  • Click ‘+’ ⇒ Actions tab ⇒ 'Get cookie'
  • Provide the name of the cookie you would like to get.
  • Provide the name of the variable you want to store the cookie in.

How to use the 'set cookie' step:

  • Hover over the arrow menu where you want to add the step.
  • Click ‘+’ ⇒ Actions tab ⇒ 'Set cookie'

The set cookie step provides you with two ways of setting the cookie:

  • Creating a new cookie from scratch by filling out all the required cookie parameters (cookie name, value, domain, httponly, etc.)
  • Setting a cookie using a cookie object fetched previously by a 'get cookie' step

Test Data

Use this in the following cases:

  • You need the cookies to be loaded before your system loads.
  • You need the cookies for a particular test.

How to set cookies using dynamic data:

1.Go to your test editor.;
2.Click on Setup step (First step in the test) and open the 'Properties' panel.
3.In 'Test Data' section, choose 'Set Dynamic Data...'
4.The JS editor should have opened now.
5.Set your cookies in the following format:

return {
 "cookies":[{
    "name": "username",
    "value": "tomsmith",
    "domain": "http://google.com"
  },{
    "name": "password",
    "value": "SuperSecretPassword!"
  }]
};

Note:

  • name: Cookie name
  • value: Cookie value
  • domain: Cookie domain (optional)

Custom JavaScript

This option will allow you to set cookies that you need during the test but not immediately at the beginning.

How to set cookies using custom JS:

1.Go to your test editor.;
2.Create a custom JS step: Use ‘+’ menu ⇒ 'Add Custom Action'
3.The JS editor should have opened now.

  1. Set your cookies in the following format:
document.cookie = "username=tomsmith; password=SuperSecretPassword!";

Note: ;The cookies will be uploaded after the page was loaded, so if you need the cookies on loading, use one of the other methods. If you need to add a domain to the cookie, use the Dynamic data.;

Configuration File & Run Hooks

This option will be useful when you need the cookies for your entire test suite.

How to set cookies using configuration file:

1.Create a JS configuration file.;
2.Add the following code to beforeSuite section.

beforeSuite: function (suite) {   
  return {
	"cookies":[
        {
	  "name": "username",
	  "value": "tomsmith",
	},
        {
	  "name": "password",
	  "value": "SuperSecretPassword!"
	}]
  };
}

Cookies


Getting and setting browser cookies

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.