@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
80 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Hover = 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 hover the mouse pointer over a given [`PageElement`](https://serenity-js.org/api/web/class/PageElement/).
*
* ## Example widget
* ```html
* <a data-test="example-link"
* class="off"
* onmouseover="this.className='on';"
* onmouseout="this.className='off';"
* href="/">hover over me</a>
* ```
*
* ## Lean Page Object describing the widget
*
* ```ts
* import { By, PageElement } from '@serenity-js/web'
*
* class Example {
* static link = () =>
* PageElement.located(By.css('[data-test="example-link"]'))
* .describedAs('example link')
* }
* ```
*
* ## Hovering over an element
*
* ```ts
* import { actorCalled } from '@serenity-js/core'
* import { Hover, CssClasses } from '@serenity-js/web'
* import { Ensure, equals } from '@serenity-js/assertions'
*
* await actorCalled('Hank')
* .whoCan(BrowseTheWeb.using(browser))
* .attemptsTo(
* Ensure.that(CssClasses.of(Example.link()), equals([ 'off' ])),
*
* Hover.over(Example.link),
* Ensure.that(CssClasses.of(Example.link()), equals([ 'on' ])),
* )
* ```
*
* ## Learn more
*
* - [`BrowseTheWeb`](https://serenity-js.org/api/web/class/BrowseTheWeb/)
* - [`PageElement`](https://serenity-js.org/api/web/class/PageElement/)
*
* @group Activities
*/
class Hover extends PageElementInteraction_1.PageElementInteraction {
element;
/**
* Instantiates this [`Interaction`](https://serenity-js.org/api/core/class/Interaction/)
*
* @param pageElement
* The element to be hovered over
*/
static over(pageElement) {
return new Hover(pageElement);
}
constructor(element) {
super((0, core_1.the) `#actor hovers the mouse over ${element}`);
this.element = element;
}
/**
* @inheritDoc
*/
async performAs(actor) {
const element = await this.resolve(actor, this.element);
await element.scrollIntoView();
await element.hoverOver();
}
}
exports.Hover = Hover;
//# sourceMappingURL=Hover.js.map