feat(codegen): use web-first page assertions to match URL (#12177)
This commit is contained in:
parent
a667d94d45
commit
4115235f4d
|
|
@ -89,7 +89,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
|||
formatter.add(code);
|
||||
|
||||
if (signals.assertNavigation)
|
||||
formatter.add(`// assert ${pageAlias}.url().equals(${quote(signals.assertNavigation.url)});`);
|
||||
formatter.add(`// assertThat(${pageAlias}).hasURL(${quote(signals.assertNavigation.url)});`);
|
||||
return formatter.format();
|
||||
}
|
||||
|
||||
|
|
@ -141,6 +141,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
|||
formatter.add(`
|
||||
import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.options.*;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import java.util.*;
|
||||
|
||||
public class Example {
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export class PythonLanguageGenerator implements LanguageGenerator {
|
|||
formatter.add(code);
|
||||
|
||||
if (signals.assertNavigation)
|
||||
formatter.add(` # assert ${pageAlias}.url == ${quote(signals.assertNavigation.url)}`);
|
||||
formatter.add(` # ${this._awaitPrefix}expect(${pageAlias}).to_have_url(${quote(signals.assertNavigation.url)})`);
|
||||
return formatter.format();
|
||||
}
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ export class PythonLanguageGenerator implements LanguageGenerator {
|
|||
formatter.add(`
|
||||
import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None {
|
||||
|
|
@ -159,7 +159,7 @@ async def run(playwright: Playwright) -> None {
|
|||
context = await browser.new_context(${formatContextOptions(options.contextOptions, options.deviceName)})`);
|
||||
} else {
|
||||
formatter.add(`
|
||||
from playwright.sync_api import Playwright, sync_playwright
|
||||
from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None {
|
||||
|
|
|
|||
|
|
@ -624,17 +624,17 @@ test.describe('cli codegen', () => {
|
|||
expect(sources.get('Java').text).toContain(`
|
||||
// Click text=link
|
||||
page.locator("text=link").click();
|
||||
// assert page.url().equals("about:blank#foo");`);
|
||||
// assertThat(page).hasURL("about:blank#foo");`);
|
||||
|
||||
expect(sources.get('Python').text).toContain(`
|
||||
# Click text=link
|
||||
page.locator(\"text=link\").click()
|
||||
# assert page.url == \"about:blank#foo\"`);
|
||||
# expect(page).to_have_url(\"about:blank#foo\")`);
|
||||
|
||||
expect(sources.get('Python Async').text).toContain(`
|
||||
# Click text=link
|
||||
await page.locator(\"text=link\").click()
|
||||
# assert page.url == \"about:blank#foo\"`);
|
||||
# await expect(page).to_have_url(\"about:blank#foo\")`);
|
||||
|
||||
expect(sources.get('C#').text).toContain(`
|
||||
// Click text=link
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ test('should print the correct imports and context options', async ({ runCLI, ch
|
|||
const cli = runCLI(['--target=java', emptyHTML]);
|
||||
const expectedResult = `import com.microsoft.playwright.*;
|
||||
import com.microsoft.playwright.options.*;
|
||||
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
|
||||
import java.util.*;
|
||||
|
||||
public class Example {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ test('should print the correct imports and context options', async ({ browserNam
|
|||
const cli = runCLI(['--target=python-async', emptyHTML]);
|
||||
const expectedResult = `import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
@ -41,7 +41,7 @@ test('should print the correct context options for custom settings', async ({ br
|
|||
const cli = runCLI(['--color-scheme=light', '--target=python-async', emptyHTML]);
|
||||
const expectedResult = `import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
@ -57,7 +57,7 @@ test('should print the correct context options when using a device', async ({ br
|
|||
const cli = runCLI(['--device=Pixel 2', '--target=python-async', emptyHTML]);
|
||||
const expectedResult = `import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
@ -73,7 +73,7 @@ test('should print the correct context options when using a device and additiona
|
|||
const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python-async', emptyHTML]);
|
||||
const expectedResult = `import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
@ -87,10 +87,10 @@ test('should save the codegen output to a file if specified', async ({ browserNa
|
|||
const tmpFile = testInfo.outputPath('script.js');
|
||||
const cli = runCLI(['--target=python-async', '--output', tmpFile, emptyHTML]);
|
||||
await cli.exited;
|
||||
const content = await fs.readFileSync(tmpFile);
|
||||
const content = fs.readFileSync(tmpFile);
|
||||
expect(content.toString()).toBe(`import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
@ -127,7 +127,7 @@ test('should print load/save storage_state', async ({ browserName, channel, runC
|
|||
const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python-async', emptyHTML]);
|
||||
const expectedResult1 = `import asyncio
|
||||
|
||||
from playwright.async_api import Playwright, async_playwright
|
||||
from playwright.async_api import Playwright, async_playwright, expect
|
||||
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ const launchOptions = (channel: string) => {
|
|||
|
||||
test('should print the correct imports and context options', async ({ runCLI, channel, browserName }) => {
|
||||
const cli = runCLI(['--target=python', emptyHTML]);
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
@ -37,7 +37,7 @@ def run(playwright: Playwright) -> None:
|
|||
|
||||
test('should print the correct context options for custom settings', async ({ runCLI, channel, browserName }) => {
|
||||
const cli = runCLI(['--color-scheme=light', '--target=python', emptyHTML]);
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
@ -51,7 +51,7 @@ test('should print the correct context options when using a device', async ({ br
|
|||
test.skip(browserName !== 'chromium');
|
||||
|
||||
const cli = runCLI(['--device=Pixel 2', '--target=python', emptyHTML]);
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
@ -65,7 +65,7 @@ test('should print the correct context options when using a device and additiona
|
|||
test.skip(browserName !== 'webkit');
|
||||
|
||||
const cli = runCLI(['--color-scheme=light', '--device=iPhone 11', '--target=python', emptyHTML]);
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright
|
||||
const expectedResult = `from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
@ -80,7 +80,7 @@ test('should save the codegen output to a file if specified', async ({ runCLI, c
|
|||
const cli = runCLI(['--target=python', '--output', tmpFile, emptyHTML]);
|
||||
await cli.exited;
|
||||
const content = fs.readFileSync(tmpFile);
|
||||
expect(content.toString()).toBe(`from playwright.sync_api import Playwright, sync_playwright
|
||||
expect(content.toString()).toBe(`from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
@ -111,7 +111,7 @@ test('should print load/save storage_state', async ({ runCLI, channel, browserNa
|
|||
const saveFileName = testInfo.outputPath('save.json');
|
||||
await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');
|
||||
const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=python', emptyHTML]);
|
||||
const expectedResult1 = `from playwright.sync_api import Playwright, sync_playwright
|
||||
const expectedResult1 = `from playwright.sync_api import Playwright, sync_playwright, expect
|
||||
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue