@serenity-js/web
Version:
Serenity/JS Screenplay Pattern library offering a flexible, web driver-agnostic approach for interacting with web-based user interfaces and components, suitable for various testing contexts
158 lines • 5.46 kB
TypeScript
import type { Answerable, Optional, QuestionAdapter, WithAnswerableProperties } from '@serenity-js/core';
import { Interaction, Timestamp } from '@serenity-js/core';
import type { CookieData } from './CookieData';
/**
* A Screenplay Pattern-style model responsible for managing cookies available to the current [`Page`](https://serenity-js.org/api/web/class/Page/).
*
* ## Checking if a cookie exists
*
* ```typescript
* 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
*
* ```typescript
* 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
*
* ```typescript
* 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
* - [`CookieData`](https://serenity-js.org/api/web/interface/CookieData/)
* - [`Page.cookie`](https://serenity-js.org/api/web/class/Page/#cookie)
*
* @group Models
*/
export declare abstract class Cookie implements Optional {
protected readonly cookieName: string;
/**
* Creates a [`QuestionAdapter`](https://serenity-js.org/api/core/#QuestionAdapter) that resolves to [`Cookie`](https://serenity-js.org/api/web/class/Cookie/) identified by `name`.
*
* @param name
*/
static called(name: Answerable<string>): QuestionAdapter<Cookie>;
/**
* Sets a cookie for the current [`Page`](https://serenity-js.org/api/web/class/Page/). Note that [`CookieData`](https://serenity-js.org/api/web/interface/CookieData/) can be either a plain-old JavaScript object, or an [`Answerable`](https://serenity-js.org/api/core/#Answerable) [`WithAnswerableProperties`](https://serenity-js.org/api/core/#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.
* :::
*
* @param cookieData
*/
static set(cookieData: Answerable<WithAnswerableProperties<CookieData>>): Interaction;
/**
* Creates an [interaction](https://serenity-js.org/api/core/class/Interaction/) to delete all cookies available to the current [`Page`](https://serenity-js.org/api/web/class/Page/)..
*/
static deleteAll(): Interaction;
private cookie;
protected constructor(cookieName: string);
/**
* Returns the name of this cookie.
*/
name(): string;
/**
* Checks if a given cookie is set.
*
* #### Learn more
* - [`Optional`](https://serenity-js.org/api/core/interface/Optional/)
*/
isPresent(): Promise<boolean>;
/**
* Returns the value of a given cookie.
*/
value(): Promise<string>;
/**
* Returns the path of a given cookie, if any was set.
*/
path(): Promise<string>;
/**
* Returns the domain of a given cookie, if any was set.
*/
domain(): Promise<string>;
/**
* Checks if a given cookie is HTTP-only.
*
* #### Learn more
* - [Mozilla Developer Network: Restricting access to cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)
*/
isHttpOnly(): Promise<boolean>;
/**
* Checks if a given cookie is secure.
*
* #### Learn more
* - [Mozilla Developer Network: Restricting access to cookies](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#restrict_access_to_cookies)
*/
isSecure(): Promise<boolean>;
/**
* Returns the expiry date of a given cookie
*
* #### Learn more
* - [`Timestamp`](https://serenity-js.org/api/core/class/Timestamp/)
*/
expiry(): Promise<Timestamp>;
/**
* Deletes a given cookie.
*/
abstract delete(): Promise<void>;
/**
* Reads a given cookie from the browser.
*
* This method is to be implemented by test integration tool-specific adapters.
*
* **Please note**: you don't need to implement any response caching here
* since it is covered by [`Cookie`](https://serenity-js.org/api/web/class/Cookie/).lazyLoadCookie} method.
*/
protected abstract read(): Promise<CookieData>;
/**
* Invokes `Cookie.read` and caches the result in memory.
*/
private lazyLoadCookie;
}
//# sourceMappingURL=Cookie.d.ts.map