Skip to content

Commit

Permalink
feat(codegen): include framepPath in jsonl format
Browse files Browse the repository at this point in the history
Fixes: #34157
  • Loading branch information
ruifigueira committed Jan 12, 2025
1 parent 6179b5b commit ffccfff
Show file tree
Hide file tree
Showing 2 changed files with 33 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
32 changes: 32 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,14 @@ 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).toMatchObject({
name: 'click',
selector: 'internal:role=button[name="Submit"i] >> nth=0',
framePath: [],
pageAlias: 'page',
});

expect(message.text()).toBe('click1');
});

Expand Down Expand Up @@ -116,6 +124,14 @@ 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).toMatchObject({
name: 'click',
selector: 'internal:text="Hello1"i',
framePath: ['#frame1'],
pageAlias: 'page',
});
});

test('should generate frame locators (2)', async ({ openRecorder, server }) => {
Expand All @@ -141,6 +157,14 @@ 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).toMatchObject({
name: 'click',
selector: 'internal:text="Hello2"i',
framePath: ['#frame1', 'iframe'],
pageAlias: 'page',
});
});

test('should generate frame locators (3)', async ({ openRecorder, server }) => {
Expand All @@ -166,6 +190,14 @@ 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).toMatchObject({
name: 'click',
selector: 'internal:text="HelloNameAnonymous"i',
framePath: ['#frame1', 'iframe', 'iframe >> nth=2'],
pageAlias: 'page',
});
});

test('should generate frame locators (4)', async ({ openRecorder, server }) => {
Expand Down

0 comments on commit ffccfff

Please sign in to comment.