chore(codegen): do not generate waitForURL (#18167)

Fixes https://github.com/microsoft/playwright/issues/17179
This commit is contained in:
Yury Semikhatsky 2022-10-19 11:26:19 -07:00 committed by GitHub
parent f250ab5d2a
commit 69092b153a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 101 deletions

View File

@ -114,8 +114,6 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
for (const line of lines)
formatter.add(line);
if (signals.assertNavigation)
formatter.add(`await ${pageAlias}.WaitForURLAsync(${quote(signals.assertNavigation.url)});`);
return formatter.format();
}

View File

@ -85,8 +85,6 @@ export class JavaLanguageGenerator implements LanguageGenerator {
formatter.add(code);
if (signals.assertNavigation)
formatter.add(`assertThat(${pageAlias}).hasURL(${quote(signals.assertNavigation.url)});`);
return formatter.format();
}

View File

@ -100,14 +100,9 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {
const suffix = emitPromiseAll ? '' : ';';
formatter.add(`${prefix}${subject}.${actionCall}${suffix}`);
if (emitPromiseAll) {
if (emitPromiseAll)
formatter.add(`]);`);
} else if (signals.assertNavigation) {
if (this._isTest)
formatter.add(`await expect(${pageAlias}).toHaveURL(${quote(signals.assertNavigation.url)});`);
else
formatter.add(`await ${pageAlias}.waitForURL(${quote(signals.assertNavigation.url)});`);
}
return formatter.format();
}

View File

@ -17,7 +17,7 @@
import type { BrowserContextOptions, LaunchOptions } from '../../..';
import type { Language } from '../isomorphic/locatorGenerators';
import type { ActionInContext } from './codeGenerator';
import type { Action, DialogSignal, DownloadSignal, NavigationSignal, PopupSignal } from './recorderActions';
import type { Action, DialogSignal, DownloadSignal, PopupSignal } from './recorderActions';
export type { Language } from '../isomorphic/locatorGenerators';
export type LanguageGeneratorOptions = {
@ -52,14 +52,11 @@ export function sanitizeDeviceOptions(device: any, options: BrowserContextOption
}
export function toSignalMap(action: Action) {
let assertNavigation: NavigationSignal | undefined;
let popup: PopupSignal | undefined;
let download: DownloadSignal | undefined;
let dialog: DialogSignal | undefined;
for (const signal of action.signals) {
if (signal.name === 'navigation')
assertNavigation = signal;
else if (signal.name === 'popup')
if (signal.name === 'popup')
popup = signal;
else if (signal.name === 'download')
download = signal;
@ -67,7 +64,6 @@ export function toSignalMap(action: Action) {
dialog = signal;
}
return {
assertNavigation,
popup,
download,
dialog,

View File

@ -97,12 +97,6 @@ export class PythonLanguageGenerator implements LanguageGenerator {
formatter.add(code);
if (signals.assertNavigation) {
if (this._isPyTest)
formatter.add(`${this._awaitPrefix}expect(${pageAlias}).to_have_url(${quote(signals.assertNavigation.url)})`);
else
formatter.add(`${this._awaitPrefix}${pageAlias}.wait_for_url(${quote(signals.assertNavigation.url)})`);
}
return formatter.format();
}

View File

@ -587,75 +587,30 @@ test.describe('cli codegen', () => {
expect(selector).toBe('internal:text="link"i');
const [, sources] = await Promise.all([
page.waitForNavigation(),
recorder.waitForOutput('JavaScript', 'waitForURL'),
recorder.waitForOutput('JavaScript', '.click()'),
page.dispatchEvent('a', 'click', { detail: 1 })
]);
expect.soft(sources.get('JavaScript').text).toContain(`
await page.getByText('link').click();
await page.waitForURL('about:blank#foo');`);
await page.getByText('link').click();`);
expect.soft(sources.get('Playwright Test').text).toContain(`
await page.getByText('link').click();
await expect(page).toHaveURL('about:blank#foo');`);
await page.getByText('link').click();`);
expect.soft(sources.get('Java').text).toContain(`
page.getByText("link").click();
assertThat(page).hasURL("about:blank#foo");`);
page.getByText("link").click();`);
expect.soft(sources.get('Python').text).toContain(`
page.get_by_text("link").click()
page.wait_for_url("about:blank#foo")`);
page.get_by_text("link").click()`);
expect.soft(sources.get('Python Async').text).toContain(`
await page.get_by_text("link").click()
await page.wait_for_url("about:blank#foo")`);
await page.get_by_text("link").click()`);
expect.soft(sources.get('Pytest').text).toContain(`
page.get_by_text("link").click()
expect(page).to_have_url("about:blank#foo")`);
page.get_by_text("link").click()`);
expect.soft(sources.get('C#').text).toContain(`
await page.GetByText("link").ClickAsync();
await page.WaitForURLAsync("about:blank#foo");`);
expect(page.url()).toContain('about:blank#foo');
});
test('should await navigation', async ({ page, openRecorder }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`<a onclick="setTimeout(() => window.location.href='about:blank#foo', 1000)">link</a>`);
const selector = await recorder.hoverOverElement('a');
expect(selector).toBe('internal:text="link"i');
const [, sources] = await Promise.all([
page.waitForNavigation(),
recorder.waitForOutput('JavaScript', 'waitForURL'),
page.dispatchEvent('a', 'click', { detail: 1 })
]);
expect.soft(sources.get('JavaScript').text).toContain(`
await page.getByText('link').click();
await page.waitForURL('about:blank#foo');`);
expect.soft(sources.get('Java').text).toContain(`
page.getByText("link").click();
assertThat(page).hasURL("about:blank#foo");`);
expect.soft(sources.get('Python').text).toContain(`
page.get_by_text("link").click()
page.wait_for_url("about:blank#foo")`);
expect.soft(sources.get('Python Async').text).toContain(`
await page.get_by_text("link").click()
await page.wait_for_url("about:blank#foo")`);
expect.soft(sources.get('C#').text).toContain(`
await page.GetByText("link").ClickAsync();
await page.WaitForURLAsync(\"about:blank#foo\");`);
await page.GetByText("link").ClickAsync();`);
expect(page.url()).toContain('about:blank#foo');
});

View File

@ -473,31 +473,6 @@ test.describe('cli codegen', () => {
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/page2.html');`);
});
test('should record slow navigation signal after mouse move', async ({ page, openRecorder, server }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`
<script>
async function onClick() {
await new Promise(f => setTimeout(f, 100));
await window.letTheMouseMove();
window.location = ${JSON.stringify(server.EMPTY_PAGE)};
}
</script>
<button onclick="onClick()">Click me</button>
`);
await page.exposeBinding('letTheMouseMove', async () => {
await page.mouse.move(200, 200);
});
const [, sources] = await Promise.all([
// This will click, finish the click, then mouse move, then navigate.
page.click('button'),
recorder.waitForOutput('JavaScript', 'waitForURL'),
]);
expect(sources.get('JavaScript').text).toContain(`page.waitForURL('${server.EMPTY_PAGE}')`);
});
test('should --save-trace', async ({ runCLI }, testInfo) => {
const traceFileName = testInfo.outputPath('trace.zip');
const cli = runCLI([`--save-trace=${traceFileName}`]);