diff --git a/examples/touchscreen.js b/examples/touchscreen.js index d69be1be3..937843e58 100644 --- a/examples/touchscreen.js +++ b/examples/touchscreen.js @@ -16,17 +16,19 @@ export const options = { export default async function () { const page = await browser.newPage(); - await page.goto('https://test.k6.io/', { waitUntil: 'networkidle' }); + await page.goto("https://test.k6.io/", { waitUntil: "networkidle" }); // Obtain ElementHandle for news link and navigate to it // by tapping in the 'a' element's bounding box - const newsLinkBox = page.$('a[href="/news.php"]').boundingBox(); - await page.touchscreen.tap(newsLinkBox.x + newsLinkBox.width / 2, newsLinkBox.y); + const newsLinkBox = await page.$('a[href="/news.php"]').boundingBox(); // Wait until the navigation is done before closing the page. // Otherwise, there will be a race condition between the page closing // and the navigation. - await page.waitForNavigation({ waitUntil: 'networkidle' }); + await Promise.all([ + page.waitForNavigation(), + page.touchscreen.tap(newsLinkBox.x + newsLinkBox.width / 2, newsLinkBox.y), + ]); page.close(); }