Add click options to click helper

This allows the user to specify different click options, such as right
click or timeouts.

Bug: 1044632
Change-Id: Id7eccf43cf88f53647a8e98583dca0d5b020a65b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2042610
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
This commit is contained in:
Tim van der Lippe
2020-02-07 10:55:00 +00:00
committed by Commit Bot
parent a848518f85
commit 537ed8164e
+4 -3
View File
@@ -69,12 +69,13 @@ export const getElementPosition = async (selector: string, root?: puppeteer.JSHa
return position;
};
export const click = async (selector: string, root?: puppeteer.JSHandle) => {
export const click =
async (selector: string, options?: {root?: puppeteer.JSHandle, clickOptions?: puppeteer.ClickOptions}) => {
const frontend: puppeteer.Page = globalThis[frontEndPage];
if (!frontend) {
throw new Error('Unable to locate DevTools frontend page. Was it stored first?');
}
const clickableElement = await getElementPosition(selector, root);
const clickableElement = await getElementPosition(selector, options?.root);
if (!clickableElement) {
throw new Error(`Unable to locate clickable element "${selector}".`);
@@ -85,7 +86,7 @@ export const click = async (selector: string, root?: puppeteer.JSHandle) => {
// a 'mousedown' event (not the 'click' event). To avoid attaching the test behavior
// to a specific event we instead locate the button in question and ask Puppeteer to
// click on it instead.
await frontend.mouse.click(clickableElement.x, clickableElement.y);
await frontend.mouse.click(clickableElement.x, clickableElement.y, options?.clickOptions);
};
// Get a single element handle, across Shadow DOM boundaries.