fix(codegen): recorded actions prevented recording omnibox navigation

This commit is contained in:
Rui Figueira 2024-03-04 00:25:02 +00:00
parent d5d4f591f3
commit 6a86c71400
2 changed files with 35 additions and 6 deletions

View file

@ -626,13 +626,8 @@ class ContextRecorder extends EventEmitter {
callMetadata.endTime = monotonicTime();
await frame.instrumentation.onAfterCall(frame, callMetadata);
const timer = setTimeout(() => {
// Commit the action after 5 seconds so that no further signals are added to it.
actionInContext.committed = true;
this._timers.delete(timer);
}, 5000);
this._setCommittedAfterTimeout(actionInContext);
this._generator.didPerformAction(actionInContext);
this._timers.add(timer);
};
const kActionTimeout = 5000;
@ -664,9 +659,19 @@ class ContextRecorder extends EventEmitter {
frame: frameDescription,
action
};
this._setCommittedAfterTimeout(actionInContext);
this._generator.addAction(actionInContext);
}
private _setCommittedAfterTimeout(actionInContext: ActionInContext) {
const timer = setTimeout(() => {
// Commit the action after 5 seconds so that no further signals are added to it.
actionInContext.committed = true;
this._timers.delete(timer);
}, isUnderTest() ? 500 : 5000);
this._timers.add(timer);
}
private _onFrameNavigated(frame: Frame, page: Page) {
const pageAlias = this._pageAliases.get(page);
this._generator.signal(pageAlias!, frame, { name: 'navigation', url: frame.url() });

View file

@ -817,4 +817,28 @@ await page.GetByRole(AriaRole.Slider).FillAsync("10");`);
expect.soft(sources.get('C#')!.text).toContain(`
await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();`);
});
test('should record omnibox navigations after performAction', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`<button>Submit</button>`);
await Promise.all([
recorder.waitForOutput('JavaScript', 'click'),
page.locator('button').click(),
]);
await page.waitForTimeout(500);
await page.goto(server.PREFIX + `/empty.html`);
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/empty.html');`);
});
test('should record omnibox navigations after recordAction', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`<textarea></textarea>`);
await Promise.all([
recorder.waitForOutput('JavaScript', 'fill'),
page.locator('textarea').fill('Hello world'),
]);
await page.waitForTimeout(500);
await page.goto(server.PREFIX + `/empty.html`);
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/empty.html');`);
});
});