diff --git a/examples/shadowdom.js b/examples/shadowdom.js new file mode 100644 index 000000000..0916a3706 --- /dev/null +++ b/examples/shadowdom.js @@ -0,0 +1,36 @@ +import { check } from 'k6'; +import { browser } from 'k6/x/browser'; + +export const options = { + scenarios: { + ui: { + executor: 'shared-iterations', + options: { + browser: { + type: 'chromium', + }, + }, + }, + }, + thresholds: { + checks: ["rate==1.0"] + } +} + +export default async function() { + const page = browser.newPage(); + page.setContent("
hello!") + await page.evaluate(() => { + const shadowRoot = document.createElement('div'); + shadowRoot.id = 'shadow-root'; + shadowRoot.attachShadow({mode: 'open'}); + shadowRoot.shadowRoot.innerHTML = 'Shadow DOM
'; + document.body.appendChild(shadowRoot); + }); + const shadowEl = page.locator("#find"); + check(shadowEl, { + "shadow element exists": (e) => e !== null, + "shadow element text is correct": (e) => e.innerText() === "Shadow DOM", + }); + page.close(); +}