Closed vigneshshanmugam closed 2 years ago
@vigneshshanmugam do you think this blocks the next release?
@justinkambic I dont think so, For now if we can educate people about this edge case that should be good enough while we figure out a fix on the generator side.
POST FF Testing LGTM
Works as expected with following example
let page1;
step('Go to https://vigneshh.in/', async () => {
await page.goto('https://vigneshh.in/');
await page.click('text=Blogs & Talks');
await page.click('html');
await page.press('body:has-text("Vignesh Shanmugam Web Performance, JavaScript Fanatic, Front End Enthusiast, Moz")', 'Meta+f');
});
step('Click text=Tailor', async () => {
[page1] = await Promise.all([
page.waitForEvent('popup'),
page.click('text=Tailor')
]);
await page1.click('summary:has-text("Code")');
await page1.click('text=GitHub CLI');
await page1.click(':nth-match([aria-label="Copy to clipboard"], 2)');
await page1.click('summary:has-text("Code")');
await Promise.all([
page1.waitForNavigation(/*{ url: 'https://github.com/zalando/tailor/pulls' }*/),
page1.click('text=Pull requests 12')
]);
});
Bug summary
When multiple page objects are created in the recorder session either by
a.com
tob.com
a.com
tob.com
Playwright creates page objects for each of those pages, The Synthetics JS generator then creates the necessary code to express those sessions. Take an example below
The problem here is we want the variable declaration for
page1
andpage2
and theirclose
method to be on their dedicated steps or grouped on a single step. This issue was mitigated before as we controlled the time when steps gets created which was only onclicks
that triggered new navigations.But with the introduction of Step divider UI, Its way easier for our users to create steps for each action and run in to the
variable not being defined
issue. Creating step beforepage1 close
would yield this code.Recorder Version
main branch
Steps to reproduce
www.vigneshh.in
for now as the test was performed on that page.a
links that opens new page objects.Test
button.Expected behavior
JS errors
.Additional information
The easiest way to solve this would be to hoist the page variables before the step function declaration and adds guards when functions are invoked on them.
Another approaches, Google chrome recorder tries to create separate blocks for each of the step, but requires you to be on the recorder page to work correctly.
Open to new ideas as well, If anyone wants to tackle, I am more than happy to pair on this one.