From 537ed8164e479dfaaceec5c81fbaa3a79eeb3239 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 6 Feb 2020 18:56:15 +0000 Subject: [PATCH] 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 Reviewed-by: Paul Lewis --- test/shared/helper.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/shared/helper.ts b/test/shared/helper.ts index 22f3c1f8a5..f7ccdc29de 100644 --- a/test/shared/helper.ts +++ b/test/shared/helper.ts @@ -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.