import { Answerable , AnswersQuestions , Question , UsesAbilities } from '@serenity-js/core' ; import { formatted } from '@serenity-js/core/lib/io' ; import { ElementFinder } from 'protractor' ; import { BrowseTheWeb } from '../abilities' ; import { withAnswerOf } from '../withAnswerOf' ; export class Attribute extends Question < Promise < string > > { param { Question < ElementFinder > | ElementFinder } target returns { AttributeBuilder } static of ( target ) { return { called : ( name ) => new Attribute ( target , name ) , } ; } constructor ( private readonly target , private readonly name ) { super ( formatted `the value of the ${ name } attribute of ${ target }` ) ; } 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 => withAnswerOf ( actor , this . target , ( elf ) => elf . getAttribute ( name ) . then ( value => { return value !== null ? value : BrowseTheWeb . as ( actor ) . executeFunction ( function getAttribute ( webElement , attributeName ) { var value = ( webElement [ attributeName ] || webElement . getAttribute ( attributeName ) ) ; if ( value !== null && value !== undefined ) { return '' + value ; } return value ; } , elf . getWebElement ( ) , name ) ; } ) ) ) ; } } interface AttributeBuilder { called ( name ) : Attribute ; }