Skip to content

Commit 3da9702

Browse files
committed
test(codegen): ensure buttons with nested divs are recorded
This handles scenarios where the current hovered element in recorder may not correspond to the event target. See: #29067 (comment)
1 parent 9290cff commit 3da9702

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/library/inspector/cli-codegen-1.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,4 +785,36 @@ await page.GetByText("Click me").ClickAsync(new LocatorClickOptions
785785
expect.soft(sources.get('C#')!.text).toContain(`
786786
await page.GetByRole(AriaRole.Slider).FillAsync("10");`);
787787
});
788+
789+
test('should click button with nested div', async ({ page, openRecorder }) => {
790+
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/29067' });
791+
792+
const recorder = await openRecorder();
793+
794+
await recorder.setContentAndWait(`<button><div role="none">Submit</div></button>`);
795+
796+
// we hover the nested div, but it must record the button
797+
const locator = await recorder.hoverOverElement('div');
798+
expect(locator).toBe(`getByRole('button', { name: 'Submit' })`);
799+
800+
const [sources] = await Promise.all([
801+
recorder.waitForOutput('JavaScript', 'Submit'),
802+
recorder.trustedClick(),
803+
]);
804+
805+
expect.soft(sources.get('JavaScript')!.text).toContain(`
806+
await page.getByRole('button', { name: 'Submit' }).click();`);
807+
808+
expect.soft(sources.get('Python')!.text).toContain(`
809+
page.get_by_role("button", name="Submit").click()`);
810+
811+
expect.soft(sources.get('Python Async')!.text).toContain(`
812+
await page.get_by_role("button", name="Submit").click()`);
813+
814+
expect.soft(sources.get('Java')!.text).toContain(`
815+
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Submit")).click()`);
816+
817+
expect.soft(sources.get('C#')!.text).toContain(`
818+
await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();`);
819+
});
788820
});

0 commit comments

Comments
 (0)