Skip to content

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

fix(codegen): do not forget to reset currentAction in didPerformAction (#5194)

Dmitry Gozman2793d14409e0
diff --git a/src/server/supplements/recorder/codeGenerator.ts b/src/server/supplements/recorder/codeGenerator.ts
index 8b5cc029df..bda7efe9e1 100644
--- a/src/server/supplements/recorder/codeGenerator.ts
+++ b/src/server/supplements/recorder/codeGenerator.ts
@@ -93,8 +93,10 @@ export class CodeGenerator {
eraseLastAction = true;
}
if (lastAction && action.name === 'navigate' && lastAction.name === 'navigate') {
- if (action.url === lastAction.url)
+ if (action.url === lastAction.url) {
+ this._currentAction = undefined;
return;
+ }
}
for (const name of ['check', 'uncheck']) {
if (lastAction && action.name === name && lastAction.name === 'click') {
diff --git a/test/cli/cli-codegen.spec.ts b/test/cli/cli-codegen.spec.ts
index 326417bfc4..950cb98c42 100644
--- a/test/cli/cli-codegen.spec.ts
+++ b/test/cli/cli-codegen.spec.ts
@@ -638,4 +638,22 @@ describe('cli codegen', (test, { browserName, headful }) => {
url: '${otherFrame.url()}'
}).click('text="Hi, I\\'m frame"');`);
});
+
+ it('should record navigations after identical pushState', async ({ page, recorder, httpServer }) => {
+ httpServer.setHandler((req: http.IncomingMessage, res: http.ServerResponse) => {
+ res.setHeader('Content-Type', 'text/html; charset=utf-8');
+ res.end('Hello world');
+ });
+ await recorder.setContentAndWait(`
+ <script>
+ function pushState() {
+ history.pushState({}, 'title', '${httpServer.PREFIX}');
+ }
+ </script>`, httpServer.PREFIX);
+ for (let i = 1; i < 3; ++i)
+ await page.evaluate('pushState()');
+
+ await page.goto(httpServer.PREFIX + '/page2.html');
+ await recorder.waitForOutput(`await page.goto('${httpServer.PREFIX}/page2.html');`);
+ });
});