Created
March 8, 2019 01:24
-
-
Save noherczeg/26c22377994f1983e73fc5b76a979123 to your computer and use it in GitHub Desktop.
How to operate on multiple levels of shadow DOM elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import puppeteer from 'puppeteer'; | |
function queryShadow(...args: any[]): string { | |
const prop = args.pop(); | |
const middle = args.map(a => `.querySelector('${a}')`).join('.shadowRoot'); | |
return `document${middle}.${prop}`; | |
} | |
describe('my-component', () => { | |
it('renders', async () => { | |
const browser = await puppeteer.launch({ headless: true }); | |
const page = await browser.newPage(); | |
await page.goto('http://localhost:3333', {waitUntil: 'networkidle2'}); | |
// const inputValue = await page.evaluate(() => { | |
// const input: HTMLInputElement = document.querySelector('body > my-component').shadowRoot.querySelector('div > div > other-comp').shadowRoot.querySelector('div > input[type="text"]'); | |
// return input.value; | |
// }); | |
const inputValue = await page.evaluate(queryShadow('my-component', 'other-comp', 'input', 'value')); | |
// const inputValue = await page.evaluate(queryShadow('my-component', 'other-comp', 'input', 'value=\'BaaaaaBB\'')); | |
// await page.screenshot({ path: 'yas.png' }); | |
expect(inputValue).toEqual('AAA'); | |
await browser.close(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment