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!

Guides    Changelog

getCookie(name)

Gets a cookie by a specific name:

  • returns: Promise which fulfills with a Cookie object for the domain you are in (for another domain you have to navigate first:
    • name {string} cookie name
    • value {string} cookie value
    • domain {string} domain the cookie is visible to
    • path {string} cookie path
    • expires {number} when the cookie expires, specified in seconds since midnight, January 1, 1970 UTC
    • httpOnly {boolean} whether the cookie is an httpOnly cookie
    • secure {boolean} whether the cookie is a secure cookie
const cookie = await getCookie('whatilanloves');
console.log(cookie.name, cookie.value); 

Full Example

'use strict';

const expect = require('chai').expect;
const { go, it, describe, getCookie, setCookie, evaluate } = require('testim');

describe('cookies', () => {
    it('sets and gets cookies', async () => {

        const cookieData = {
            name: 'first',
            value: '33'
        }
    
        await go('http://jsbin.testim.io/fim/');
        await setCookie(cookieData);
    
        const cookie = await getCookie('first');
    
        expect(cookie.name).to.eq(cookieData.name);
        expect(cookie.value).to.eq(cookieData.value);
    
        cookie.name = 'second';
    
        await setCookie(cookie);
    
        const cookie2 = await getCookie('second');
        expect(cookie2.name).to.eq(cookie.name);
        expect(cookie2.value).to.eq(cookie.value);
    
        const clientCookie = await evaluate(() => {
            return document.cookie;
        });

        expect(clientCookie).to.eq('first=33; second=33');
    });

    it('sets and gets httpOnly cookie', async () => {

        const cookieData = {
            name: 'first',
            value: '33',
            httpOnly: true
        }
    
        await goto('http://jsbin.testim.io/fim/');
        await setCookie(cookieData);
    
        const cookie = await getCookie('first');
    
        expect(cookie.name).to.eq(cookieData.name);
        expect(cookie.value).to.eq(cookieData.value);
        expect(cookie.httpOnly).to.eq(cookieData.httpOnly);

        const clientCookie = await evaluate(() => {
            return document.cookie;
        });

        expect(clientCookie).to.not.contain('first');
    });
});

Updated about a month ago

getCookie(name)


Suggested Edits are limited on API Reference Pages

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