Skip to content

Commit

Permalink
Update examples/shadowdom to async check
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Sep 27, 2024
1 parent 67163da commit adcb65f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions examples/shadowdom.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -26,15 +26,17 @@ export default async function() {
const shadowRoot = document.createElement('div');
shadowRoot.id = 'shadow-root';
shadowRoot.attachShadow({mode: 'open'});
shadowRoot.shadowRoot.innerHTML = '<p id="find">Shadow DOM</p>';
shadowRoot.shadowRoot.innerHTML = '<p id="shadow-dom">Shadow DOM</p>';
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();
Expand Down

0 comments on commit adcb65f

Please sign in to comment.