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

76 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Scroll = void 0; const core_1 = require("@serenity-js/core"); /** * Instructs an [actor](https://serenity-js.org/api/core/class/Actor/) who has the [ability](https://serenity-js.org/api/core/class/Ability/) to [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) * to scroll until a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/) comes into view. * * ## Example widget * * ```html * <!-- * an element somewhere at the bottom of the page, * outside of the visible area * --> * <input type="submit" id="submit" /> * ``` * * ## Lean Page Object describing the widget * * ```ts * import { By, PageElement } from '@serenity-js/web' * * class Form { * static submitButton = () => { * PageElement.located(By.id('submit')) * .describedAs('submit button') * } * ``` * * ## Scrolling to element * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Ensure } from '@serenity-js/assertions' * import { Scroll, isVisible } from '@serenity-js/web' * * await actorCalled('Sara') * .attemptsTo( * Scroll.to(Form.submitButton()), * Ensure.that(Form.submitButton(), isVisible()), * ) * ``` * * ## Learn more * * - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) * - [`PageElement`](https://serenity-js.org/api/web/class/PageElement/) * * @group Activities */ class Scroll extends core_1.Interaction { element; /** * Instantiates this [`Interaction`](https://serenity-js.org/api/core/class/Interaction/). * * @param pageElement * The element to scroll to */ static to(pageElement) { return new Scroll(pageElement); } constructor(element) { super((0, core_1.the) `#actor scrolls to ${element}`); this.element = element; } /** * @inheritDoc */ async performAs(actor) { const pageElement = await actor.answer(this.element); await pageElement.scrollIntoView(); } } exports.Scroll = Scroll; //# sourceMappingURL=Scroll.js.map