Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(codegen): attribute navigation to press/fill (#34528)
Pavel Feldman931b9f28cd5d
diff --git a/packages/playwright-core/src/server/recorder/recorderCollection.ts b/packages/playwright-core/src/server/recorder/recorderCollection.tsindex 162d5d6813..9f28efd930 100644--- a/packages/playwright-core/src/server/recorder/recorderCollection.ts+++ b/packages/playwright-core/src/server/recorder/recorderCollection.ts@@ -85,7 +85,7 @@ export class RecorderCollection extends EventEmitter {let generateGoto = false;if (!lastAction)generateGoto = true;- else if (lastAction.action.name !== 'click' && lastAction.action.name !== 'press')+ else if (lastAction.action.name !== 'click' && lastAction.action.name !== 'press' && lastAction.action.name !== 'fill')generateGoto = true;else if (timestamp - lastAction.startTime > signalThreshold)generateGoto = true;diff --git a/tests/library/inspector/cli-codegen-1.spec.ts b/tests/library/inspector/cli-codegen-1.spec.tsindex 6936aeee41..aa52daffa9 100644--- a/tests/library/inspector/cli-codegen-1.spec.ts+++ b/tests/library/inspector/cli-codegen-1.spec.ts@@ -778,6 +778,70 @@ await page.GetByText("link").ClickAsync();`);expect(page.url()).toContain('about:blank#foo');});+ test('should attribute navigation to press/fill', async ({ openRecorder }) => {+ const { page, recorder } = await openRecorder();++ await recorder.setContentAndWait(`<input /><script>document.querySelector('input').addEventListener('input', () => window.location.href = 'about:blank#foo');</script>`);++ const locator = await recorder.hoverOverElement('input');+ expect(locator).toBe(`getByRole('textbox')`);+ await recorder.trustedClick();+ await expect.poll(() => page.locator('input').evaluate(e => e === document.activeElement)).toBeTruthy();+ const [, sources] = await Promise.all([+ page.waitForNavigation(),+ recorder.waitForOutput('JavaScript', '.fill'),+ recorder.trustedPress('h'),+ ]);++ expect.soft(sources.get('JavaScript')!.text).toContain(`+ await page.goto('about:blank');+ await page.getByRole('textbox').click();+ await page.getByRole('textbox').fill('h');++ // ---------------------+ await context.close();`);++ expect.soft(sources.get('Playwright Test')!.text).toContain(`+ await page.goto('about:blank');+ await page.getByRole('textbox').click();+ await page.getByRole('textbox').fill('h');+});`);++ expect.soft(sources.get('Java')!.text).toContain(`+ page.navigate(\"about:blank\");+ page.getByRole(AriaRole.TEXTBOX).click();+ page.getByRole(AriaRole.TEXTBOX).fill(\"h\");+ }`);++ expect.soft(sources.get('Python')!.text).toContain(`+ page.goto("about:blank")+ page.get_by_role("textbox").click()+ page.get_by_role("textbox").fill("h")++ # ---------------------+ context.close()`);++ expect.soft(sources.get('Python Async')!.text).toContain(`+ await page.goto("about:blank")+ await page.get_by_role("textbox").click()+ await page.get_by_role("textbox").fill("h")++ # ---------------------+ await context.close()`);++ expect.soft(sources.get('Pytest')!.text).toContain(`+ page.goto("about:blank")+ page.get_by_role("textbox").click()+ page.get_by_role("textbox").fill("h")`);++ expect.soft(sources.get('C#')!.text).toContain(`+await page.GotoAsync("about:blank");+await page.GetByRole(AriaRole.Textbox).ClickAsync();+await page.GetByRole(AriaRole.Textbox).FillAsync("h");`);++ expect(page.url()).toContain('about:blank#foo');+ });+test('should ignore AltGraph', async ({ openRecorder, browserName }) => {test.skip(browserName === 'firefox', 'The TextInputProcessor in Firefox does not work with AltGraph.');const { recorder } = await openRecorder();diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.tsindex b94bfc09a0..f5e3631b3a 100644--- a/tests/library/inspector/inspectorTest.ts+++ b/tests/library/inspector/inspectorTest.ts@@ -218,6 +218,10 @@ export class Recorder {await this.page.mouse.up(options);}+ async trustedPress(text: string) {+ await this.page.keyboard.press(text);+ }+async trustedDblclick() {await this.page.mouse.down();await this.page.mouse.up();