import { Answerable , AnswersQuestions , Question , Transform , UsesAbilities } from '@serenity-js/core' ; import { IWebDriverOptionsCookie } from 'selenium-webdriver' ; import { BrowseTheWeb } from '../abilities' ; export class Cookie { static valueOf ( cookieName ) { return Transform . the ( new CookieDetails ( cookieName ) , details => details && details . value ) . as ( `the value of the "${ cookieName }" cookie` ) ; } static pathOf ( cookieName ) { return Transform . the ( new CookieDetails ( cookieName ) , details => details && details . path ) . as ( `the path of the "${ cookieName }" cookie` ) ; } static domainOf ( cookieName ) { return new CookieDetails ( cookieName ) . map ( actor => details => details ?. domain ) . describedAs ( `the domain of the "${ cookieName }" cookie` ) ; } static isHTTPOnly ( cookieName ) { return new CookieDetails ( cookieName ) . map ( actor => details => details && ! ! details . httpOnly ) . describedAs ( `the HTTP-only status of the "${ cookieName }" cookie` ) ; } static isSecure ( cookieName ) { return new CookieDetails ( cookieName ) . map ( actor => details => details && ! ! details . secure ) . describedAs ( `the "secure" status of the "${ cookieName }" cookie` ) ; } static expiryDateOf ( cookieName ) { return new CookieDetails ( cookieName ) . map ( actor => details => details ?. expiry && new Date ( Number ( details . expiry ) * 1000 ) ) . describedAs ( `the expiry date of the "${ cookieName }" cookie` ) ; } } package class CookieDetails extends Question < Promise < IWebDriverOptionsCookie > > { constructor ( private readonly name ) { super ( `the details of the "${ name } cookie` ) ; } desc Makes the provided  {@link @serenity-js/core/lib/screenplay/actor~Actor} *  answer this  {@link @serenity-js/core/lib/screenplay~Question} .
     *
     *  param { AnswersQuestions & UsesAbilities } actor returns { Promise < void > } see {@link @serenity-js/core/lib/screenplay/actor~Actor} see {@link @serenity-js/core/lib/screenplay/actor~AnswersQuestions} see {@link @serenity-js/core/lib/screenplay/actor~UsesAbilities} answeredBy ( actor ) { return actor . answer ( this . name ) . then ( name => BrowseTheWeb . as ( actor ) . manage ( ) . getCookie ( name ) ) . then ( details => details ? details : undefined ) ; } }