Skip to content

Commit

Permalink
feat(codegen): include framePath in jsonl format (#34310)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifigueira authored Jan 14, 2025
1 parent dfe80bb commit 9a9d22a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/codegen/jsonl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
52 changes: 52 additions & 0 deletions tests/library/inspector/cli-codegen-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down Expand Up @@ -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 }) => {
Expand All @@ -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 }) => {
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 9a9d22a

Please sign in to comment.