From adcb65fa5430f40593088f979d4c5d13eece6ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 27 Sep 2024 14:11:51 -0400 Subject: [PATCH] Update examples/shadowdom to async check --- examples/shadowdom.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/shadowdom.js b/examples/shadowdom.js index ac32d8a93..6f3b16155 100644 --- a/examples/shadowdom.js +++ b/examples/shadowdom.js @@ -1,5 +1,5 @@ -import { check } from 'k6'; import { browser } from 'k6/x/browser/async'; +import { check } from 'https://jslib.k6.io/k6-utils/1.5.0/index.js'; export const options = { scenarios: { @@ -26,15 +26,17 @@ export default async function() { const shadowRoot = document.createElement('div'); shadowRoot.id = 'shadow-root'; shadowRoot.attachShadow({mode: 'open'}); - shadowRoot.shadowRoot.innerHTML = '

Shadow DOM

'; + shadowRoot.shadowRoot.innerHTML = '

Shadow DOM

'; document.body.appendChild(shadowRoot); }); - const shadowEl = page.locator("#find"); - const ok = await shadowEl.innerText() === "Shadow DOM"; - check(shadowEl, { - "shadow element exists": (e) => e !== null, - "shadow element text is correct": () => ok, + await check( + page.locator('#shadow-dom'), { + 'shadow element exists': + e => e !== null, + 'shadow element text is correct': + async e => e.innerText() + .then(text => text === 'Shadow DOM'), }); await page.close();