UNPKG

@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

79 lines 3.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Value = void 0; const core_1 = require("@serenity-js/core"); const models_1 = require("../models"); /** * Uses the [actor's](https://serenity-js.org/api/core/class/Actor/) [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) to retrieve * the `value` attribute of a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/). * * ## Example widget * ```html * <input type="text" id="username" value="Alice" /> * ``` * * ## Retrieve the `value` of a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/) * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure, equals } from '@serenity-js/assertions' * import { By, PageElement, Value } from '@serenity-js/web' * * const usernameField = () => * PageElement.located(By.id('username')) * .describedAs('username field') * * await actorCalled('Lisa') * .attemptsTo( * Ensure.that(Value.of(usernameField), equals('Alice')), * ) * ``` * * ## Using Value as [`QuestionAdapter`](https://serenity-js.org/api/core/#QuestionAdapter) * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure, equals } from '@serenity-js/assertions' * import { By, PageElement, Value } from '@serenity-js/web' * * const usernameField = () => * PageElement.located(By.id('username')) * .describedAs('username field') * * await actorCalled('Lisa') * .attemptsTo( * Ensure.that( * Value.of(usernameField).toLocaleLowerCase()[0], * equals('a') // [a]lice * ), * ) * ``` * * ## Learn more * - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) * - [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) * - [`QuestionAdapter`](https://serenity-js.org/api/core/#QuestionAdapter) * - [`Question`](https://serenity-js.org/api/core/class/Question/) * * @group Questions */ class Value { /** * Instantiates a [`Question`](https://serenity-js.org/api/core/class/Question/) that uses * the [actor's](https://serenity-js.org/api/core/class/Actor/) [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) to retrieve * the `value` attribute of a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/). * * #### Learn more * - [`MetaQuestion`](https://serenity-js.org/api/core/interface/MetaQuestion/) * * @param pageElement */ static of(pageElement) { return core_1.Question.about((0, core_1.the) `the value of ${pageElement}`, async (actor) => { const element = await actor.answer(pageElement); return element.value(); }, (parent) => Value.of(models_1.PageElement.of(pageElement, parent))); } } exports.Value = Value; //# sourceMappingURL=Value.js.map