ya
`);
expect(await page._createSelector('zs', await page.$('#target'))).toBe('"ya"~"hey"~"hello"');
expect(await page.$eval(`zs="ya"~"hey"~"hello"`, e => e.outerHTML)).toBe('
hello
');
expect(await page.$eval(`zs="ya"~"hey"~"unique"`, e => e.outerHTML).catch(e => e.message)).toBe('Error: failed to find element matching selector "zs="ya"~"hey"~"unique""');
expect(await page.$$eval(`zs="ya" ~ "hey" ~ "hello"`, es => es.map(e => e.outerHTML).join('\n'))).toBe('
hello
\n
hello
');
});
});
describe('text selector', () => {
it('query', async ({page}) => {
await page.setContent(`
yo
ya
\nye
`);
expect(await page.$eval(`text=ya`, e => e.outerHTML)).toBe('
ya
');
expect(await page.$eval(`text="ya"`, e => e.outerHTML)).toBe('
ya
');
expect(await page.$eval(`text=/^[ay]+$/`, e => e.outerHTML)).toBe('
ya
');
expect(await page.$eval(`text=/Ya/i`, e => e.outerHTML)).toBe('
ya
');
expect(await page.$eval(`text=ye`, e => e.outerHTML)).toBe('
\nye
');
await page.setContent(`
ye
ye
`);
expect(await page.$eval(`text="ye"`, e => e.outerHTML)).toBe('
ye
');
await page.setContent(`
yo
"ya
hello world!
`);
expect(await page.$eval(`text="\\"ya"`, e => e.outerHTML)).toBe('
"ya
');
expect(await page.$eval(`text=/hello/`, e => e.outerHTML)).toBe('
hello world!
');
expect(await page.$eval(`text=/^\\s*heLLo/i`, e => e.outerHTML)).toBe('
hello world!
');
await page.setContent(`
`);
expect(await page.$eval(`text=hey`, e => e.outerHTML)).toBe('
');
await page.setContent(`
yo
yo
`);
expect(await page.$$eval(`text=yo`, es => es.map(e => e.outerHTML).join('\n'))).toBe('
yo
\n
yo
');
});
it('create', async ({page}) => {
await page.setContent(`
yo
"ya
ye ye
`);
expect(await page._createSelector('text', await page.$('div'))).toBe('yo');
expect(await page._createSelector('text', await page.$('div:nth-child(2)'))).toBe('"\\"ya"');
expect(await page._createSelector('text', await page.$('div:nth-child(3)'))).toBe('"ye ye"');
await page.setContent(`
yo
`);
expect(await page._createSelector('text', await page.$('div:nth-child(2)'))).toBe('hey');
await page.setContent(`
`);
expect(await page._createSelector('text', await page.$('div'))).toBe('yo');
await page.setContent(`
`);
expect(await page._createSelector('text', await page.$('div'))).toBe('" \\"yo "');
});
});
};