mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(test): fix broken codegen test (#8383)
This commit is contained in:
parent
47724fed5a
commit
ce2aa1782b
@ -649,7 +649,7 @@ test.describe('cli codegen', () => {
|
||||
test('should fill tricky characters', async ({ page, openRecorder }) => {
|
||||
const recorder = await openRecorder();
|
||||
|
||||
await recorder.setContentAndWait(`<textarea id="textarea" name="name" oninput="console.log(textarea.value)"></textarea>`);
|
||||
await recorder.setContentAndWait(`<textarea spellcheck=false id="textarea" name="name" oninput="console.log(textarea.value)"></textarea>`);
|
||||
const selector = await recorder.focusElement('textarea');
|
||||
expect(selector).toBe('textarea[name="name"]');
|
||||
|
||||
|
||||
@ -165,13 +165,13 @@ test('should print load/save storageState', async ({ browserName, channel, runCL
|
||||
});
|
||||
var context = await browser.NewContextAsync(new BrowserNewContextOptions
|
||||
{
|
||||
StorageStatePath = "${loadFileName}",
|
||||
StorageStatePath = "${loadFileName.replace(/\\/g, '\\\\')}",
|
||||
});`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
const expectedResult2 = `
|
||||
await context.StorageStateAsync(new BrowserContextStorageStateOptions
|
||||
{
|
||||
Path = "${saveFileName}"
|
||||
Path = "${saveFileName.replace(/\\/g, '\\\\')}"
|
||||
});
|
||||
`;
|
||||
await cli.waitFor(expectedResult2);
|
||||
|
||||
@ -82,10 +82,10 @@ test('should print load/save storage_state', async ({ runCLI, browserName }, tes
|
||||
await fs.promises.writeFile(loadFileName, JSON.stringify({ cookies: [], origins: [] }), 'utf8');
|
||||
const cli = runCLI([`--load-storage=${loadFileName}`, `--save-storage=${saveFileName}`, '--target=java', emptyHTML]);
|
||||
const expectedResult1 = `BrowserContext context = browser.newContext(new Browser.NewContextOptions()
|
||||
.setStorageStatePath(Paths.get("${loadFileName}")));`;
|
||||
.setStorageStatePath(Paths.get("${loadFileName.replace(/\\/g, '\\\\')}")));`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
|
||||
const expectedResult2 = `
|
||||
context.storageState(new BrowserContext.StorageStateOptions().setPath("${saveFileName}"))`;
|
||||
context.storageState(new BrowserContext.StorageStateOptions().setPath("${saveFileName.replace(/\\/g, '\\\\')}"))`;
|
||||
await cli.waitFor(expectedResult2);
|
||||
});
|
||||
|
||||
@ -128,13 +128,13 @@ test('should print load/save storageState', async ({ browserName, channel, runCL
|
||||
${launchOptions(channel)}
|
||||
});
|
||||
const context = await browser.newContext({
|
||||
storageState: '${loadFileName}'
|
||||
storageState: '${loadFileName.replace(/\\/g, '\\\\')}'
|
||||
});`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
|
||||
const expectedResult2 = `
|
||||
// ---------------------
|
||||
await context.storageState({ path: '${saveFileName}' });
|
||||
await context.storageState({ path: '${saveFileName.replace(/\\/g, '\\\\')}' });
|
||||
await context.close();
|
||||
await browser.close();
|
||||
})();`;
|
||||
|
||||
@ -132,12 +132,12 @@ from playwright.async_api import Playwright, async_playwright
|
||||
|
||||
async def run(playwright: Playwright) -> None:
|
||||
browser = await playwright.${browserName}.launch(${launchOptions(channel)})
|
||||
context = await browser.new_context(storage_state="${loadFileName}")`;
|
||||
context = await browser.new_context(storage_state="${loadFileName.replace(/\\/g, '\\\\')}")`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
|
||||
const expectedResult2 = `
|
||||
# ---------------------
|
||||
await context.storage_state(path="${saveFileName}")
|
||||
await context.storage_state(path="${saveFileName.replace(/\\/g, '\\\\')}")
|
||||
await context.close()
|
||||
await browser.close()
|
||||
|
||||
|
||||
@ -116,12 +116,12 @@ test('should print load/save storage_state', async ({ runCLI, channel, browserNa
|
||||
|
||||
def run(playwright: Playwright) -> None:
|
||||
browser = playwright.${browserName}.launch(${launchOptions(channel)})
|
||||
context = browser.new_context(storage_state="${loadFileName}")`;
|
||||
context = browser.new_context(storage_state="${loadFileName.replace(/\\/g, '\\\\')}")`;
|
||||
await cli.waitFor(expectedResult1);
|
||||
|
||||
const expectedResult2 = `
|
||||
# ---------------------
|
||||
context.storage_state(path="${saveFileName}")
|
||||
context.storage_state(path="${saveFileName.replace(/\\/g, '\\\\')}")
|
||||
context.close()
|
||||
browser.close()
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ test('should print load storageState', async ({ browserName, channel, runCLI },
|
||||
const expectedResult = `const { test, expect } = require('@playwright/test');
|
||||
|
||||
test.use({
|
||||
storageState: '${loadFileName}'
|
||||
storageState: '${loadFileName.replace(/\\/g, '\\\\')}'
|
||||
});
|
||||
|
||||
test('test', async ({ page }) => {`;
|
||||
|
||||
@ -221,11 +221,18 @@ class CLIMock {
|
||||
});
|
||||
}
|
||||
|
||||
async waitFor(text: string): Promise<void> {
|
||||
async waitFor(text: string, timeout = 10_000): Promise<void> {
|
||||
if (this.data.includes(text))
|
||||
return Promise.resolve();
|
||||
this.waitForText = text;
|
||||
return new Promise(f => this.waitForCallback = f);
|
||||
return new Promise((f, r) => {
|
||||
this.waitForCallback = f;
|
||||
if (timeout) {
|
||||
setTimeout(() => {
|
||||
r(new Error('Timed out waiting for text:\n' + text + '\n\nRecieved:\n' + this.text()));
|
||||
}, timeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
text() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user