Skip to content

Commit 0f5836b

Browse files
committed
Optionally highlighted element's shadow root
1 parent b031803 commit 0f5836b

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/runner-shared/src/iframe/aut-iframe.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { eventManager } from '../event-manager'
77
import { dom } from '../dom'
88
import { logger } from '../logger'
99
import { studioRecorder } from '../studio'
10+
import { getShadowElementFromPoint } from '@packages/driver/src/dom/elements/shadow'
1011

1112
const $ = $Cypress.$
1213

@@ -291,7 +292,7 @@ export class AutIframe {
291292
const $highlight = $el
292293

293294
$highlight.css('display', 'none')
294-
el = this._document().elementFromPoint(e.clientX, e.clientY)
295+
el = getShadowElementFromPoint(this._document().elementFromPoint(e.clientX, e.clientY), e.clientX, e.clientY)
295296
$el = $(el)
296297
$highlight.css('display', 'block')
297298
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<my-custom-element></my-custom-element>
2+
<button data-testid="outside-button">Outside button (data-testid="outside-button")</button>
3+
4+
<script type="module">
5+
window.customElements.define(
6+
'my-custom-element',
7+
class extends HTMLElement {
8+
constructor() {
9+
super();
10+
this.attachShadow({ mode: 'open' });
11+
}
12+
13+
connectedCallback() {
14+
this.shadowRoot.innerHTML = `
15+
<button data-testid="inside-button">Inside button (data-testid="inside-button")</button>
16+
`;
17+
}
18+
}
19+
);
20+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// https://github.com/cypress-io/cypress/issues/20989
2+
describe('issue 20989', { baseUrl: null, includeShadowDom: true }, () => {
3+
it('highlights elements inside shadow roots', () => {
4+
Cypress.SelectorPlayground.defaults({
5+
onElement: ($el) => {
6+
const testId = $el.attr('data-testid')
7+
8+
if (testId) {
9+
return `[data-testid=${testId}]`
10+
}
11+
},
12+
})
13+
14+
cy.visit('/cypress/fixtures/issues/issue-20989.html')
15+
})
16+
})

0 commit comments

Comments
 (0)