Skip to main content

abstractCookie

A Screenplay Pattern-style model responsible for managing cookies available to the current Page.

Checking if a cookie exists

import { actorCalled } from '@serenity-js/core'
import { Navigate, Cookie } from '@serenity-js/web'
import { Ensure, isPresent } from '@serenity-js/assertions'

await actorCalled('Sid')
.attemptsTo(
Navigate.to('https://example.org'),

Ensure.that(
Cookie.called('example-cookie-name'),
isPresent()
),
)

Setting a cookie

import { actorCalled } from '@serenity-js/core'
import { Navigate, Cookie } from '@serenity-js/web'
import { Ensure, isPresent, not } from '@serenity-js/assertions'

await actorCalled('Sid')
.attemptsTo(
Navigate.to('https://example.org'),

Ensure.that(Cookie.called('example-cookie-name'), not(isPresent())),

Cookie.set({
name: 'favourite',
value: 'triple chocolate',
}),

Ensure.that(Cookie.called('example-cookie-name'), isPresent()),
)

Reading a cookie

import { actorCalled } from '@serenity-js/core'
import { Navigate, Cookie } from '@serenity-js/web'
import { Ensure, equals } from '@serenity-js/assertions'

await actorCalled('Sid')
.attemptsTo(
Navigate.to('https://example.org'),

Ensure.that(
Cookie.called('some-cookie-name').value(),
equals('triple chocolate')
),
)

Learn more

Implements

  • Optional

Index

Methods

staticcalled

  • called(name: Answerable<string>): QuestionAdapter<Cookie>

staticset

  • set(cookieData: Answerable<{ name: Answerable<string>; value: Answerable<string>; domain?: Answerable<string>; path?: Answerable<string>; expiry?: { readonly value: { toString: {}; toDateString: {}; toTimeString: {}; toLocaleString: {}; toLocaleDateString: {}; toLocaleTimeString: {}; valueOf: {}; getTime: {}; getFullYear: {}; getUTCFullYear: {}; getMonth: {}; ... 32 more ...; [Symbol.toPrimitive]: {}; }; ... 13 more ...; equals: {}; }; httpOnly?: Answerable<false> | Answerable<true>; secure?: Answerable<false> | Answerable<true>; sameSite?: Answerable<Lax> | Answerable<Strict> | Answerable<None> }>): Interaction
  • Sets a cookie for the current Page. Note that CookieData can be either a plain-old JavaScript object, or an Answerable WithAnswerableProperties.

    info

    Make sure that the actor performing this interaction is on the page that should receive the cookie. Because of browser security restrictions, an actor canโ€™t set a cookie for an arbitrary page without being on that page.


    Parameters

    • cookieData: Answerable<{ name: Answerable<string>; value: Answerable<string>; domain?: Answerable<string>; path?: Answerable<string>; expiry?: { readonly value: { toString: {}; toDateString: {}; toTimeString: {}; toLocaleString: {}; toLocaleDateString: {}; toLocaleTimeString: {}; valueOf: {}; getTime: {}; getFullYear: {}; getUTCFullYear: {}; getMonth: {}; ... 32 more ...; [Symbol.toPrimitive]: {}; }; ... 13 more ...; equals: {}; }; httpOnly?: Answerable<false> | Answerable<true>; secure?: Answerable<false> | Answerable<true>; sameSite?: Answerable<Lax> | Answerable<Strict> | Answerable<None> }>

    Returns Interaction

staticdeleteAll

  • deleteAll(): Interaction
  • Creates an interaction to delete all cookies available to the current Page..


    Returns Interaction

name

  • name(): string
  • Returns the name of this cookie.


    Returns string

isPresent

  • isPresent(): Promise<boolean>
  • Checks if a given cookie is set.

    Learn more


    Returns Promise<boolean>

value

  • value(): Promise<string>
  • Returns the value of a given cookie.


    Returns Promise<string>

path

  • path(): Promise<string>
  • Returns the path of a given cookie, if any was set.


    Returns Promise<string>

domain

  • domain(): Promise<string>
  • Returns the domain of a given cookie, if any was set.


    Returns Promise<string>

isHttpOnly

  • isHttpOnly(): Promise<boolean>

isSecure

  • isSecure(): Promise<boolean>

expiry

  • expiry(): Promise<Timestamp>
  • Returns the expiry date of a given cookie

    Learn more


    Returns Promise<Timestamp>

abstractdelete

  • delete(): Promise<void>
  • Deletes a given cookie.


    Returns Promise<void>