@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
95 lines • 2.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RightClick = 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 perform a right click on a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/).
*
* This is typically used to open a [custom context menu](https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event)
* on a given Web element, since it's not possible to interact with the standard context menu offered by your browser.
*
* ## Example widget
*
* ```html
* <form>
* <input type="text" id="field"
* oncontextmenu="showMenu(); return false;" />
*
* <div id="context-menu" style="display:none">
* Custom context menu
* </div>
* </form>
*
* <script>
* function showMenu() {
* document.getElementById("context-menu").style.display = 'block';
* }
* </script>
* ```
*
* ## Lean Page Object describing the widget
*
* ```ts
* import { By, PageElement } from '@serenity-js/web'
*
* class Form {
* static exampleInput = () =>
* PageElement.located(By.id('example'))
* .describedAs('example input')
*
* static exampleContextMenu = () =>
* PageElement.located(By.id('context-menu'))
* .describedAs('example context menu')
* }
* ```
*
* ## Right-click on an element
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { RightClick, isVisible } from '@serenity-js/web'
* import { Ensure } from '@serenity-js/assertions'
*
* await actorCalled('Chloé')
* .whoCan(BrowseTheWeb.using(browser))
* .attemptsTo(
* RightClick.on(Form.exampleInput()),
* Ensure.that(Form.exampleContextMenu(), isVisible()),
* )
* ```
*
* ## Learn more
*
* - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
* - [`PageElement`](https://serenity-js.org/api/web/class/PageElement/)
*
* @group Activities
*/
class RightClick extends PageElementInteraction_1.PageElementInteraction {
pageElement;
/**
* Instantiates this [`Interaction`](https://serenity-js.org/api/core/class/Interaction/).
*
* @param pageElement
* The element to be right-clicked on
*/
static on(pageElement) {
return new RightClick(pageElement);
}
constructor(pageElement) {
super((0, core_1.the) `#actor right-clicks on ${pageElement}`);
this.pageElement = pageElement;
}
/**
* @inheritDoc
*/
async performAs(actor) {
const element = await this.resolve(actor, this.pageElement);
await element.scrollIntoView();
await element.rightClick();
}
}
exports.RightClick = RightClick;
//# sourceMappingURL=RightClick.js.map