Skip to content

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

feat(codegen): include framePath in jsonl format (#34310)

Rui Figueira9a9d22af4412
diff --git a/packages/playwright-core/src/server/codegen/jsonl.ts b/packages/playwright-core/src/server/codegen/jsonl.ts
index 8f506433f0..e6769cd8d7 100644
--- a/packages/playwright-core/src/server/codegen/jsonl.ts
+++ b/packages/playwright-core/src/server/codegen/jsonl.ts
@@ -28,7 +28,7 @@ export class JsonlLanguageGenerator implements LanguageGenerator {
const locator = (actionInContext.action as any).selector ? JSON.parse(asLocator('jsonl', (actionInContext.action as any).selector)) : undefined;
const entry = {
...actionInContext.action,
- pageAlias: actionInContext.frame.pageAlias,
+ ...actionInContext.frame,
locator,
};
return JSON.stringify(entry);
diff --git a/tests/library/inspector/cli-codegen-3.spec.ts b/tests/library/inspector/cli-codegen-3.spec.ts
index 22032a8f26..87c7e7bfec 100644
--- a/tests/library/inspector/cli-codegen-3.spec.ts
+++ b/tests/library/inspector/cli-codegen-3.spec.ts
@@ -55,6 +55,19 @@ test.describe('cli codegen', () => {
expect.soft(sources.get('C#')!.text).toContain(`
await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).First.ClickAsync();`);
+ const clickAction = sources.get('JSON')!.actions.map(l => JSON.parse(l)).find(a => a.name === 'click');
+ expect.soft(clickAction).toEqual({
+ name: 'click',
+ selector: 'internal:role=button[name="Submit"i] >> nth=0',
+ button: 'left',
+ clickCount: 1,
+ locator: { body: 'button', kind: 'role', options: { exact: false, attrs: [], name: 'Submit' }, next: { body: '', kind: 'first', options: {} } },
+ modifiers: 0,
+ signals: [],
+ framePath: [],
+ pageAlias: 'page',
+ });
+
expect(message.text()).toBe('click1');
});
@@ -116,6 +129,19 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).Nth(1).ClickAsy
expect.soft(sources.get('C#')!.text).toContain(`
await page.Locator("#frame1").ContentFrame.GetByText("Hello1").ClickAsync();`);
+
+ const clickAction = sources.get('JSON')!.actions.map(l => JSON.parse(l)).find(a => a.name === 'click');
+ expect.soft(clickAction).toEqual({
+ name: 'click',
+ selector: 'internal:text="Hello1"i',
+ button: 'left',
+ clickCount: 1,
+ locator: { body: 'Hello1', kind: 'text', options: { exact: false } },
+ modifiers: 0,
+ signals: [],
+ framePath: ['#frame1'],
+ pageAlias: 'page',
+ });
});
test('should generate frame locators (2)', async ({ openRecorder, server }) => {
@@ -141,6 +167,19 @@ await page.Locator("#frame1").ContentFrame.GetByText("Hello1").ClickAsync();`);
expect.soft(sources.get('C#')!.text).toContain(`
await page.Locator("#frame1").ContentFrame.Locator("iframe").ContentFrame.GetByText("Hello2").ClickAsync();`);
+
+ const clickAction = sources.get('JSON')!.actions.map(l => JSON.parse(l)).find(a => a.name === 'click');
+ expect.soft(clickAction).toEqual({
+ name: 'click',
+ selector: 'internal:text="Hello2"i',
+ button: 'left',
+ clickCount: 1,
+ locator: { body: 'Hello2', kind: 'text', options: { exact: false } },
+ modifiers: 0,
+ signals: [],
+ framePath: ['#frame1', 'iframe'],
+ pageAlias: 'page',
+ });
});
test('should generate frame locators (3)', async ({ openRecorder, server }) => {
@@ -166,6 +205,19 @@ await page.Locator("#frame1").ContentFrame.Locator("iframe").ContentFrame.GetByT
expect.soft(sources.get('C#')!.text).toContain(`
await page.Locator("#frame1").ContentFrame.Locator("iframe").ContentFrame.Locator("iframe").Nth(2).ContentFrame.GetByText("HelloNameAnonymous").ClickAsync();`);
+
+ const clickAction = sources.get('JSON')!.actions.map(l => JSON.parse(l)).find(a => a.name === 'click');
+ expect.soft(clickAction).toEqual({
+ name: 'click',
+ selector: 'internal:text="HelloNameAnonymous"i',
+ button: 'left',
+ clickCount: 1,
+ locator: { body: 'HelloNameAnonymous', kind: 'text', options: { exact: false } },
+ modifiers: 0,
+ signals: [],
+ framePath: ['#frame1', 'iframe', 'iframe >> nth=2'],
+ pageAlias: 'page',
+ });
});
test('should generate frame locators (4)', async ({ openRecorder, server }) => {