Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: click links in shadow dom (#5773)

Yury Semikhatsky13977301fd03
diff --git a/test/assets/shadow-dom-link.html b/test/assets/shadow-dom-link.html
new file mode 100644
index 0000000000..dabb9272c3
--- /dev/null
+++ b/test/assets/shadow-dom-link.html
@@ -0,0 +1,28 @@
+<html>
+<head>
+<script>
+customElements.define('my-link',
+ class extends HTMLElement {
+ constructor() {
+ super();
+
+ const template = document.getElementById('my-link-template');
+ const templateContent = template.content;
+
+ this.attachShadow({mode: 'open'}).appendChild(
+ templateContent.cloneNode(true)
+ );
+ }
+ }
+);
+
+window.clickCount = 0;
+</script>
+</head>
+<body>
+<template id="my-link-template">
+ <a href="#" id="inner-link" onclick="clickCount++"><slot></slot></a>
+</template>
+<my-link>Sign up</my-link>
+</body>
+</html>
diff --git a/test/selectors-misc.spec.ts b/test/selectors-misc.spec.ts
index 310b314d81..cf4dd48ac7 100644
--- a/test/selectors-misc.spec.ts
+++ b/test/selectors-misc.spec.ts
@@ -27,6 +27,15 @@ it('should work for open shadow roots', async ({page, server}) => {
expect(await page.$$(`data-testid:light=foo`)).toEqual([]);
});
+it('should click on links in shadow dom', (test, { browserName }) => {
+ test.fixme(browserName === 'chromium', 'Cannot get link quads, see #5765');
+}, async ({page, server}) => {
+ await page.goto(server.PREFIX + '/shadow-dom-link.html');
+ expect(await page.evaluate(() => (window as any).clickCount)).toBe(0);
+ await page.click('#inner-link');
+ expect(await page.evaluate(() => (window as any).clickCount)).toBe(1);
+});
+
it('should work with :visible', async ({page}) => {
await page.setContent(`
<section>