feat(codegen): include framePath in jsonl format (#34310)
This commit is contained in:
parent
dfe80bb888
commit
9a9d22af44
|
@ -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);
|
||||
|
|
|
@ -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 }) => {
|
||||
|
|
Loading…
Reference in New Issue