Skip to main content

RightClick

Instructs an actor who has the ability to BrowseTheWeb to perform a right click on a given PageElement.

This is typically used to open a custom context menu on a given Web element, since it’s not possible to interact with the standard context menu offered by your browser.

Example widget

<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

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

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

Hierarchy

Index

Methods

staticon

  • on(pageElement: Answerable<PageElement<any>>): Interaction
  • Instantiates this Interaction.


    Parameters

    • pageElement: Answerable<PageElement<any>>

      The element to be right-clicked on

    Returns Interaction

instantiationLocation

  • instantiationLocation(): FileSystemLocation
  • Returns the location where this Activity was instantiated.


    Returns FileSystemLocation

toString

  • toString(): string
  • Generates a human-friendly description to be used when reporting this Activity.

    Note: When this activity is reported, token #actor in the description will be replaced with the name of the actor performing this Activity.

    For example, #actor clicks on a button becomes Wendy clicks on a button.


    Returns string

performAs

  • performAs(actor: UsesAbilities & AnswersQuestions): Promise<void>