Skip to main content

externalabstractCookie

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

Index

Methods

staticexternalcalled

staticexternalset

  • set(cookieData: Answerable<{ name: Answerable<string>; value: Answerable<string>; domain?: Answerable<string>; path?: Answerable<string>; expiry?: { value: { [toPrimitive]: any; toString: any; toDateString: any; toTimeString: any; toLocaleString: any; toLocaleDateString: any; toLocaleTimeString: any; valueOf: any; getTime: any; getFullYear: any; getUTCFullYear: any; getMonth: any; getUTCMonth: any; getDate: any; getUTCDate: any; getDay: any; getUTCDay: any; getHours: any; getUTCHours: any; getMinutes: any; getUTCMinutes: any; getSeconds: any; getUTCSeconds: any; getMilliseconds: any; getUTCMilliseconds: any; getTimezoneOffset: any; setTime: any; setMilliseconds: any; setUTCMilliseconds: any; setSeconds: any; setUTCSeconds: any; setMinutes: any; setUTCMinutes: any; setHours: any; setUTCHours: any; setDate: any; setUTCDate: any; setMonth: any; setUTCMonth: any; setFullYear: any; setUTCFullYear: any; toUTCString: any; toISOString: any; toJSON: any }; diff: any; plus: any; less: any; isBefore: any; isBeforeOrEqual: any; isAfter: any; isAfterOrEqual: any; toMilliseconds: any; toSeconds: any; toJSON: any; toISOString: any; toString: any; [custom]: any; equals: any }; 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.

    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

    • externalcookieData: Answerable<{ name: Answerable<string>; value: Answerable<string>; domain?: Answerable<string>; path?: Answerable<string>; expiry?: { value: { [toPrimitive]: any; toString: any; toDateString: any; toTimeString: any; toLocaleString: any; toLocaleDateString: any; toLocaleTimeString: any; valueOf: any; getTime: any; getFullYear: any; getUTCFullYear: any; getMonth: any; getUTCMonth: any; getDate: any; getUTCDate: any; getDay: any; getUTCDay: any; getHours: any; getUTCHours: any; getMinutes: any; getUTCMinutes: any; getSeconds: any; getUTCSeconds: any; getMilliseconds: any; getUTCMilliseconds: any; getTimezoneOffset: any; setTime: any; setMilliseconds: any; setUTCMilliseconds: any; setSeconds: any; setUTCSeconds: any; setMinutes: any; setUTCMinutes: any; setHours: any; setUTCHours: any; setDate: any; setUTCDate: any; setMonth: any; setUTCMonth: any; setFullYear: any; setUTCFullYear: any; toUTCString: any; toISOString: any; toJSON: any }; diff: any; plus: any; less: any; isBefore: any; isBeforeOrEqual: any; isAfter: any; isAfterOrEqual: any; toMilliseconds: any; toSeconds: any; toJSON: any; toISOString: any; toString: any; [custom]: any; equals: any }; httpOnly?: Answerable<false> | Answerable<true>; secure?: Answerable<false> | Answerable<true>; sameSite?: Answerable<Lax> | Answerable<Strict> | Answerable<None> }>

    Returns Interaction

staticexternaldeleteAll

externalname

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


    Returns string

externalisPresent

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

    Learn more


    Returns Promise<boolean>

externalvalue

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


    Returns Promise<string>

externalpath

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


    Returns Promise<string>

externaldomain

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


    Returns Promise<string>

externalisHttpOnly

  • isHttpOnly(): Promise<boolean>

externalisSecure

  • isSecure(): Promise<boolean>

externalexpiry

externalabstractdelete

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


    Returns Promise<void>