import { Question, UsesAbilities } from '@serenity-js/core/lib/screenplay'; import { BrowseTheWeb } from '../abilities/browse_the_web'; import { Target } from '../ui/target'; export class Text { static of = (element: Target): Question> => new TextOf(element); static ofAll = (elements: Target): Question> => new TextOfAll(elements); } class TextOf implements Question> { answeredBy(actor: UsesAbilities): PromiseLike { return BrowseTheWeb.as(actor).locate(this.target).getText(); } constructor(private target: Target) { } toString = () => `the text of ${ this.target}`; } class TextOfAll implements Question> { answeredBy(actor: UsesAbilities): PromiseLike { // protractor ignores type definitions for the ElementArrayFinder // https://github.com/angular/protractor/blob/c3978ec166760ac07db01e700c4aaaa19d9b5c38/lib/element.ts#L92 return BrowseTheWeb.as(actor).locateAll(this.target).getText() as any; } constructor(private target: Target) { } toString = () => `the text of all ${ this.target}`; }