Skip to content

Commit

Permalink
Add a shadow example
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Feb 9, 2024
1 parent 9f56aa8 commit 75d33b3
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions examples/shadowdom.js
Original file line number Diff line number Diff line change
@@ -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("<html><head><style></style></head><body>hello!</body></html>")
await page.evaluate(() => {
const shadowRoot = document.createElement('div');
shadowRoot.id = 'shadow-root';
shadowRoot.attachShadow({mode: 'open'});
shadowRoot.shadowRoot.innerHTML = '<p id="find">Shadow DOM</p>';
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();
}

0 comments on commit 75d33b3

Please sign in to comment.