Skip to content

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

test: more clear test for click on child text node (#37968)

Yury Semikhatsky927f055e26ca
diff --git a/tests/page/elementhandle-click.spec.ts b/tests/page/elementhandle-click.spec.ts
index e9d16ef40f..211055f25a 100644
--- a/tests/page/elementhandle-click.spec.ts
+++ b/tests/page/elementhandle-click.spec.ts
@@ -39,11 +39,16 @@ it('should work for Shadow DOM v1', async ({ page, server }) => {
expect(await page.evaluate('clicked')).toBe(true);
});
-it('should work for TextNodes', async ({ page, server }) => {
- await page.goto(server.PREFIX + '/input/button.html');
- const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);
+it('should work for TextNodes', async ({ page }) => {
+ await page.setContent(`
+ <div id='outer' onclick="window['result'] = 'Clicked ' + event.target.id;">
+ <div id='inner' style="max-width: 50px">Lorem ipsum dolor sit amet consectetur adipiscing elit proin, integer curabitur imperdiet rhoncus cursus tincidunt bibendum, consequat sed magnis laoreet luctus mollis tellus. Nisl parturient mus accumsan feugiat sem laoreet magnis nisi, aptent per sollicitudin gravida orci ac blandit, viverra eros praesent auctor vivamus semper bibendum. Consequat sed habitasse luctus dictumst gravida platea semper phasellus, nascetur ridiculus purus est varius quisque et scelerisque, id vehicula eleifend montes sollicitudin dis velit. Pellentesque ridiculus per natoque et eleifend taciti nunc, laoreet auctor at condimentum imperdiet ante, conubia mi cubilia scelerisque sociosqu sem.</div>
+ Custom Text.
+ </div>
+ `);
+ const buttonTextNode = await page.evaluateHandle(() => document.querySelector('#outer').lastChild);
await buttonTextNode.click();
- expect(await page.evaluate(() => window['result'])).toBe('Clicked');
+ expect(await page.evaluate(() => window['result'])).toBe('Clicked outer');
});
it('should throw for detached nodes', async ({ page, server }) => {
diff --git a/tests/page/locator-click.spec.ts b/tests/page/locator-click.spec.ts
index 4221225927..7554e7f0a6 100644
--- a/tests/page/locator-click.spec.ts
+++ b/tests/page/locator-click.spec.ts
@@ -32,13 +32,6 @@ it('should work with Node removed', async ({ page, server }) => {
expect(await page.evaluate(() => window['result'])).toBe('Clicked');
});
-it('should work for TextNodes', async ({ page, server }) => {
- await page.goto(server.PREFIX + '/input/button.html');
- const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);
- await buttonTextNode.click();
- expect(await page.evaluate(() => window['result'])).toBe('Clicked');
-});
-
it('should double click the button', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/button.html');
await page.evaluate(() => {