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.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Click = void 0; const core_1 = require("@serenity-js/core"); const PageElementInteraction_1 = require("./PageElementInteraction"); /** * 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 the given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/) into view and then [click](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event) on it. * * ## Example widget * * ```html * <form> * <input type="text" name="example" id="example" /> * </form> * ``` * * ## Lean Page Object describing the widget * * ```ts * import { By, PageElement } from '@serenity-js/webdriverio'; * * class Form { * static exampleInput = () => * PageElement.located(By.id('example')) * .describedAs('example input') * } * ``` * * ## Clicking on an element * * ```ts * import { actorCalled } from '@serenity-js/core' * import { Click, isSelected } from '@serenity-js/web' * import { Ensure } from '@serenity-js/assertions' * * await actorCalled('Chloé') * .attemptsTo( * Click.on(Form.exampleInput()), * Ensure.that(Form.exampleInput(), isSelected()), * ) * ``` * * ## Learn more * * - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/) * - [`PageElement`](https://serenity-js.org/api/web/class/PageElement/) * * @group Activities */ class Click extends PageElementInteraction_1.PageElementInteraction { element; /** * Instantiates this [`Interaction`](https://serenity-js.org/api/core/class/Interaction/). * * @param pageElement * The element to be clicked on */ static on(pageElement) { return new Click(pageElement); } constructor(element) { super((0, core_1.the) `#actor clicks on ${element}`); this.element = element; } /** * @inheritDoc */ async performAs(actor) { const element = await this.resolve(actor, this.element); await element.scrollIntoView(); await element.click(); } } exports.Click = Click; //# sourceMappingURL=Click.js.map