2021-02-12 04:46:54 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
import { test, expect } from './inspectorTest';
|
2021-02-12 04:46:54 +03:00
|
|
|
import * as url from 'url';
|
2021-08-18 17:27:45 +03:00
|
|
|
import fs from 'fs';
|
2021-02-12 04:46:54 +03:00
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test.describe('cli codegen', () => {
|
2021-04-30 23:26:13 +03:00
|
|
|
test.skip(({ mode }) => mode !== 'default');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
test('should contain open page', async ({ openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
|
|
|
|
await recorder.setContentAndWait(``);
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', `page.goto`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
const page = await context.newPage();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2021-03-04 01:32:09 +03:00
|
|
|
Page page = context.newPage();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page = context.new_page()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page = await context.new_page()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2021-05-21 01:47:14 +03:00
|
|
|
var page = await context.NewPageAsync();`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should contain second page', async ({ openRecorder, page }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(``);
|
2021-04-02 21:19:26 +03:00
|
|
|
await page.context().newPage();
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'page1');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
const page1 = await context.newPage();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2021-03-04 01:32:09 +03:00
|
|
|
Page page1 = context.newPage();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page1 = context.new_page()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page1 = await context.new_page()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2021-05-21 01:47:14 +03:00
|
|
|
var page1 = await context.NewPageAsync();`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should contain close page', async ({ openRecorder, page }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(``);
|
2021-04-02 21:19:26 +03:00
|
|
|
await page.context().newPage();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.page.close();
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'page.close();');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
await page.close();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2021-03-04 01:32:09 +03:00
|
|
|
page.close();`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page.close()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
await page.close()`);
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2021-05-21 01:47:14 +03:00
|
|
|
await page.CloseAsync();`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should not lead to an error if html gets clicked', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait('');
|
2021-04-02 21:19:26 +03:00
|
|
|
await page.context().newPage();
|
2021-02-12 04:46:54 +03:00
|
|
|
const errors: any[] = [];
|
|
|
|
recorder.page.on('pageerror', e => errors.push(e));
|
|
|
|
await recorder.page.evaluate(() => document.querySelector('body').remove());
|
|
|
|
const selector = await recorder.hoverOverElement('html');
|
|
|
|
expect(selector).toBe('html');
|
|
|
|
await recorder.page.close();
|
2021-06-11 02:52:59 +03:00
|
|
|
await recorder.waitForOutput('JavaScript', 'page.close();');
|
2021-02-12 04:46:54 +03:00
|
|
|
expect(errors.length).toBe(0);
|
|
|
|
});
|
|
|
|
|
2021-04-06 01:51:45 +03:00
|
|
|
test('should upload a single file', async ({ page, openRecorder, browserName, asset }) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
test.fixme(browserName === 'firefox', 'Hangs');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<form>
|
|
|
|
<input type="file">
|
|
|
|
</form>
|
|
|
|
`);
|
|
|
|
|
|
|
|
await page.focus('input[type=file]');
|
2021-04-06 01:51:45 +03:00
|
|
|
await page.setInputFiles('input[type=file]', asset('file-to-upload.txt'));
|
2021-02-12 04:46:54 +03:00
|
|
|
await page.click('input[type=file]');
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator('input[type="file"]').setInputFiles('file-to-upload.txt');`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator("input[type=\\\"file\\\"]").setInputFiles(Paths.get("file-to-upload.txt"));`);
|
2021-03-04 01:32:09 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator(\"input[type=\\\"file\\\"]\").set_input_files(\"file-to-upload.txt\")`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator(\"input[type=\\\"file\\\"]\").set_input_files(\"file-to-upload.txt\")`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.Locator(\"input[type=\\\"file\\\"]\").SetInputFilesAsync(new[] { \"file-to-upload.txt\" });`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-06 01:51:45 +03:00
|
|
|
test('should upload multiple files', async ({ page, openRecorder, browserName, asset }) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
test.fixme(browserName === 'firefox', 'Hangs');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<form>
|
|
|
|
<input type="file" multiple>
|
|
|
|
</form>
|
|
|
|
`);
|
|
|
|
|
|
|
|
await page.focus('input[type=file]');
|
2021-04-06 01:51:45 +03:00
|
|
|
await page.setInputFiles('input[type=file]', [asset('file-to-upload.txt'), asset('file-to-upload-2.txt')]);
|
2021-02-12 04:46:54 +03:00
|
|
|
await page.click('input[type=file]');
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator('input[type=\"file\"]').setInputFiles(['file-to-upload.txt', 'file-to-upload-2.txt']);`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator("input[type=\\\"file\\\"]").setInputFiles(new Path[] {Paths.get("file-to-upload.txt"), Paths.get("file-to-upload-2.txt")});`);
|
2021-03-04 01:32:09 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator(\"input[type=\\\"file\\\"]\").set_input_files([\"file-to-upload.txt\", \"file-to-upload-2.txt\"]`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator(\"input[type=\\\"file\\\"]\").set_input_files([\"file-to-upload.txt\", \"file-to-upload-2.txt\"]`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.Locator(\"input[type=\\\"file\\\"]\").SetInputFilesAsync(new[] { \"file-to-upload.txt\", \"file-to-upload-2.txt\" });`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-06 01:51:45 +03:00
|
|
|
test('should clear files', async ({ page, openRecorder, browserName, asset }) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
test.fixme(browserName === 'firefox', 'Hangs');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<form>
|
|
|
|
<input type="file" multiple>
|
|
|
|
</form>
|
|
|
|
`);
|
|
|
|
await page.focus('input[type=file]');
|
2021-04-06 01:51:45 +03:00
|
|
|
await page.setInputFiles('input[type=file]', asset('file-to-upload.txt'));
|
2021-02-12 04:46:54 +03:00
|
|
|
await page.setInputFiles('input[type=file]', []);
|
|
|
|
await page.click('input[type=file]');
|
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'setInputFiles');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator('input[type=\"file\"]').setInputFiles([]);`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator("input[type=\\\"file\\\"]").setInputFiles(new Path[0]);`);
|
2021-03-04 01:32:09 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator(\"input[type=\\\"file\\\"]\").set_input_files([])`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator(\"input[type=\\\"file\\\"]\").set_input_files([])`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.Locator(\"input[type=\\\"file\\\"]\").SetInputFilesAsync(new[] { });`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
test('should download files', async ({ page, openRecorder, server }) => {
|
2021-04-02 21:19:26 +03:00
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
server.setRoute('/download', (req, res) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
const pathName = url.parse(req.url!).path;
|
|
|
|
if (pathName === '/download') {
|
|
|
|
res.setHeader('Content-Type', 'application/octet-stream');
|
|
|
|
res.setHeader('Content-Disposition', 'attachment; filename=file.txt');
|
|
|
|
res.end(`Hello world`);
|
|
|
|
} else {
|
|
|
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
|
|
res.end('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
await recorder.setContentAndWait(`
|
2021-05-09 03:45:04 +03:00
|
|
|
<a href="${server.PREFIX}/download" download>Download</a>
|
|
|
|
`, server.PREFIX);
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.hoverOverElement('text=Download');
|
|
|
|
await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
|
|
|
page.click('text=Download')
|
|
|
|
]);
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'waitForEvent');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('JavaScript').text).toContain(`
|
2021-12-06 20:25:24 +03:00
|
|
|
const context = await browser.newContext();`);
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('JavaScript').text).toContain(`
|
2021-02-12 04:46:54 +03:00
|
|
|
const [download] = await Promise.all([
|
|
|
|
page.waitForEvent('download'),
|
2022-10-04 03:14:02 +03:00
|
|
|
page.getByRole('link', { name: 'Download' }).click()
|
2021-02-12 04:46:54 +03:00
|
|
|
]);`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Java').text).toContain(`
|
2021-12-06 20:25:24 +03:00
|
|
|
BrowserContext context = browser.newContext();`);
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Java').text).toContain(`
|
2021-03-04 01:32:09 +03:00
|
|
|
Download download = page.waitForDownload(() -> {
|
2022-10-10 22:25:56 +03:00
|
|
|
page.getByRole(AriaRole.LINK, new Page.GetByRoleOptions().setName("Download")).click();
|
2021-03-04 01:32:09 +03:00
|
|
|
});`);
|
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python').text).toContain(`
|
2021-12-06 20:25:24 +03:00
|
|
|
context = browser.new_context()`);
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
with page.expect_download() as download_info:
|
2022-10-04 03:14:02 +03:00
|
|
|
page.get_by_role("link", name="Download").click()
|
2021-02-17 05:13:26 +03:00
|
|
|
download = download_info.value`);
|
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python Async').text).toContain(`
|
2021-12-06 20:25:24 +03:00
|
|
|
context = await browser.new_context()`);
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python Async').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
async with page.expect_download() as download_info:
|
2022-10-04 03:14:02 +03:00
|
|
|
await page.get_by_role("link", name="Download").click()
|
2021-02-17 05:13:26 +03:00
|
|
|
download = await download_info.value`);
|
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('C#').text).toContain(`
|
2021-12-06 20:25:24 +03:00
|
|
|
var context = await browser.NewContextAsync();`);
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('C#').text).toContain(`
|
2021-05-27 01:44:40 +03:00
|
|
|
var download1 = await page.RunAndWaitForDownloadAsync(async () =>
|
2021-05-21 01:47:14 +03:00
|
|
|
{
|
2022-10-13 18:23:43 +03:00
|
|
|
await page.GetByRole(AriaRole.Link, new() { NameString = "Download" }).ClickAsync();
|
2021-05-21 01:47:14 +03:00
|
|
|
});`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should handle dialogs', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<button onclick="alert()">click me</button>
|
|
|
|
`);
|
|
|
|
await recorder.hoverOverElement('button');
|
|
|
|
page.once('dialog', async dialog => {
|
|
|
|
await dialog.dismiss();
|
|
|
|
});
|
|
|
|
await page.click('text=click me');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'once');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('JavaScript').text).toContain(`
|
2021-02-12 04:46:54 +03:00
|
|
|
page.once('dialog', dialog => {
|
2021-02-17 05:13:26 +03:00
|
|
|
console.log(\`Dialog message: \${dialog.message()}\`);
|
2021-02-12 04:46:54 +03:00
|
|
|
dialog.dismiss().catch(() => {});
|
|
|
|
});
|
2022-10-04 03:14:02 +03:00
|
|
|
await page.getByRole('button', { name: 'click me' }).click();`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Java').text).toContain(`
|
2021-03-04 01:32:09 +03:00
|
|
|
page.onceDialog(dialog -> {
|
|
|
|
System.out.println(String.format("Dialog message: %s", dialog.message()));
|
|
|
|
dialog.dismiss();
|
|
|
|
});
|
2022-10-10 22:25:56 +03:00
|
|
|
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("click me")).click();`);
|
2021-03-04 01:32:09 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page.once(\"dialog\", lambda dialog: dialog.dismiss())
|
2022-10-04 03:14:02 +03:00
|
|
|
page.get_by_role("button", name="click me").click()`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('Python Async').text).toContain(`
|
2021-02-17 05:13:26 +03:00
|
|
|
page.once(\"dialog\", lambda dialog: dialog.dismiss())
|
2022-10-04 03:14:02 +03:00
|
|
|
await page.get_by_role("button", name="click me").click()`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-10-10 22:25:56 +03:00
|
|
|
expect.soft(sources.get('C#').text).toContain(`
|
2021-05-21 01:47:14 +03:00
|
|
|
void page_Dialog1_EventHandler(object sender, IDialog dialog)
|
|
|
|
{
|
|
|
|
Console.WriteLine($\"Dialog message: {dialog.Message}\");
|
|
|
|
dialog.DismissAsync();
|
|
|
|
page.Dialog -= page_Dialog1_EventHandler;
|
|
|
|
}
|
|
|
|
page.Dialog += page_Dialog1_EventHandler;
|
2022-10-13 18:23:43 +03:00
|
|
|
await page.GetByRole(AriaRole.Button, new() { NameString = "click me" }).ClickAsync();`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
test('should handle history.postData', async ({ page, openRecorder, server }) => {
|
2021-04-02 21:19:26 +03:00
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<script>
|
|
|
|
let seqNum = 0;
|
|
|
|
function pushState() {
|
2021-05-09 03:45:04 +03:00
|
|
|
history.pushState({}, 'title', '${server.PREFIX}/#seqNum=' + (++seqNum));
|
2021-02-12 04:46:54 +03:00
|
|
|
}
|
2021-05-09 03:45:04 +03:00
|
|
|
</script>`, server.PREFIX);
|
2021-02-12 04:46:54 +03:00
|
|
|
for (let i = 1; i < 3; ++i) {
|
|
|
|
await page.evaluate('pushState()');
|
2021-06-11 02:52:59 +03:00
|
|
|
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/#seqNum=${i}');`);
|
2021-02-12 04:46:54 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should record open in a new tab with url', async ({ page, openRecorder, browserName, platform }) => {
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`<a href="about:blank?foo">link</a>`);
|
|
|
|
|
|
|
|
const selector = await recorder.hoverOverElement('a');
|
2022-10-20 05:38:47 +03:00
|
|
|
expect(selector).toBe('internal:role=link[name=\"link\"]');
|
2021-02-12 04:46:54 +03:00
|
|
|
|
2022-08-18 21:12:33 +03:00
|
|
|
await page.click('a', { modifiers: [platform === 'darwin' ? 'Meta' : 'Control'] });
|
2021-06-11 02:52:59 +03:00
|
|
|
const sources = await recorder.waitForOutput('JavaScript', 'page1');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-02-08 03:09:11 +03:00
|
|
|
if (browserName !== 'firefox') {
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2021-02-12 04:46:54 +03:00
|
|
|
const page1 = await context.newPage();
|
2021-04-21 17:59:38 +03:00
|
|
|
await page1.goto('about:blank?foo');`);
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2021-04-21 17:59:38 +03:00
|
|
|
page1 = await context.new_page()
|
|
|
|
await page1.goto("about:blank?foo")`);
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`
|
2021-05-21 01:47:14 +03:00
|
|
|
var page1 = await context.NewPageAsync();
|
|
|
|
await page1.GotoAsync("about:blank?foo");`);
|
2022-02-08 03:09:11 +03:00
|
|
|
} else {
|
2021-06-11 02:52:59 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2021-02-12 04:46:54 +03:00
|
|
|
const [page1] = await Promise.all([
|
|
|
|
page.waitForEvent('popup'),
|
2022-10-04 03:14:02 +03:00
|
|
|
page.getByRole('link', { name: 'link' }).click({
|
2021-02-12 04:46:54 +03:00
|
|
|
modifiers: ['${platform === 'darwin' ? 'Meta' : 'Control'}']
|
|
|
|
})
|
|
|
|
]);`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should not clash pages', async ({ page, openRecorder, browserName }) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
test.fixme(browserName === 'firefox', 'Times out on Firefox, maybe the focus issue');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
const [popup1] = await Promise.all([
|
|
|
|
page.context().waitForEvent('page'),
|
|
|
|
page.evaluate(`window.open('about:blank')`)
|
|
|
|
]);
|
|
|
|
await recorder.setPageContentAndWait(popup1, '<input id=name>');
|
|
|
|
|
|
|
|
const [popup2] = await Promise.all([
|
|
|
|
page.context().waitForEvent('page'),
|
|
|
|
page.evaluate(`window.open('about:blank')`)
|
|
|
|
]);
|
|
|
|
await recorder.setPageContentAndWait(popup2, '<input id=name>');
|
|
|
|
|
|
|
|
await popup1.type('input', 'TextA');
|
2021-06-11 02:52:59 +03:00
|
|
|
await recorder.waitForOutput('JavaScript', 'TextA');
|
2021-02-12 04:46:54 +03:00
|
|
|
|
|
|
|
await popup2.type('input', 'TextB');
|
2021-06-11 02:52:59 +03:00
|
|
|
await recorder.waitForOutput('JavaScript', 'TextB');
|
2021-02-17 05:13:26 +03:00
|
|
|
|
|
|
|
const sources = recorder.sources();
|
2022-02-05 06:27:45 +03:00
|
|
|
expect(sources.get('JavaScript').text).toContain(`await page1.locator('input').fill('TextA');`);
|
|
|
|
expect(sources.get('JavaScript').text).toContain(`await page2.locator('input').fill('TextB');`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-02-05 06:27:45 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`page1.locator("input").fill("TextA");`);
|
|
|
|
expect(sources.get('Java').text).toContain(`page2.locator("input").fill("TextB");`);
|
2021-03-04 01:32:09 +03:00
|
|
|
|
2022-02-05 06:27:45 +03:00
|
|
|
expect(sources.get('Python').text).toContain(`page1.locator(\"input\").fill(\"TextA\")`);
|
|
|
|
expect(sources.get('Python').text).toContain(`page2.locator(\"input\").fill(\"TextB\")`);
|
2021-02-12 04:46:54 +03:00
|
|
|
|
2022-02-05 06:27:45 +03:00
|
|
|
expect(sources.get('Python Async').text).toContain(`await page1.locator(\"input\").fill(\"TextA\")`);
|
|
|
|
expect(sources.get('Python Async').text).toContain(`await page2.locator(\"input\").fill(\"TextB\")`);
|
2021-02-17 05:13:26 +03:00
|
|
|
|
2022-02-05 06:27:45 +03:00
|
|
|
expect(sources.get('C#').text).toContain(`await page1.Locator(\"input\").FillAsync(\"TextA\");`);
|
|
|
|
expect(sources.get('C#').text).toContain(`await page2.Locator(\"input\").FillAsync(\"TextB\");`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('click should emit events in order', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<button id=button>
|
|
|
|
<script>
|
|
|
|
button.addEventListener('mousedown', e => console.log(e.type));
|
|
|
|
button.addEventListener('mouseup', e => console.log(e.type));
|
|
|
|
button.addEventListener('click', e => console.log(e.type));
|
|
|
|
</script>
|
|
|
|
`);
|
|
|
|
|
|
|
|
const messages: any[] = [];
|
2021-05-13 01:19:27 +03:00
|
|
|
page.on('console', message => {
|
|
|
|
if (message.type() !== 'error')
|
|
|
|
messages.push(message.text());
|
|
|
|
});
|
2021-02-12 04:46:54 +03:00
|
|
|
await Promise.all([
|
|
|
|
page.click('button'),
|
2022-02-05 06:27:45 +03:00
|
|
|
recorder.waitForOutput('JavaScript', '.click(')
|
2021-02-12 04:46:54 +03:00
|
|
|
]);
|
|
|
|
expect(messages).toEqual(['mousedown', 'mouseup', 'click']);
|
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should update hover model on action', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name='updated'"></input>`);
|
2022-08-18 21:12:33 +03:00
|
|
|
const [models] = await Promise.all([
|
2021-02-12 04:46:54 +03:00
|
|
|
recorder.waitForActionPerformed(),
|
|
|
|
page.click('input')
|
|
|
|
]);
|
|
|
|
expect(models.hovered).toBe('input[name="updated"]');
|
|
|
|
});
|
|
|
|
|
2021-05-13 20:22:23 +03:00
|
|
|
test('should update active model on action', async ({ page, openRecorder, browserName, headless }) => {
|
2022-06-09 01:13:39 +03:00
|
|
|
test.fixme(browserName !== 'chromium');
|
2021-04-02 21:19:26 +03:00
|
|
|
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name='updated'"></input>`);
|
2022-08-18 21:12:33 +03:00
|
|
|
const [models] = await Promise.all([
|
2021-02-12 04:46:54 +03:00
|
|
|
recorder.waitForActionPerformed(),
|
|
|
|
page.click('input')
|
|
|
|
]);
|
|
|
|
expect(models.active).toBe('input[name="updated"]');
|
|
|
|
});
|
|
|
|
|
2021-04-02 21:19:26 +03:00
|
|
|
test('should check input with chaning id', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
2021-02-12 04:46:54 +03:00
|
|
|
await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name = 'updated'"></input>`);
|
|
|
|
await Promise.all([
|
|
|
|
recorder.waitForActionPerformed(),
|
|
|
|
page.click('input[id=checkbox]')
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
test('should record navigations after identical pushState', async ({ page, openRecorder, server }) => {
|
2021-04-02 21:19:26 +03:00
|
|
|
const recorder = await openRecorder();
|
2021-05-09 03:45:04 +03:00
|
|
|
server.setRoute('/page2.html', (req, res) => {
|
2021-02-12 04:46:54 +03:00
|
|
|
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
|
|
res.end('Hello world');
|
|
|
|
});
|
|
|
|
await recorder.setContentAndWait(`
|
|
|
|
<script>
|
|
|
|
function pushState() {
|
2021-05-09 03:45:04 +03:00
|
|
|
history.pushState({}, 'title', '${server.PREFIX}');
|
2021-02-12 04:46:54 +03:00
|
|
|
}
|
2021-05-09 03:45:04 +03:00
|
|
|
</script>`, server.PREFIX);
|
2021-02-12 04:46:54 +03:00
|
|
|
for (let i = 1; i < 3; ++i)
|
|
|
|
await page.evaluate('pushState()');
|
|
|
|
|
2021-05-09 03:45:04 +03:00
|
|
|
await page.goto(server.PREFIX + '/page2.html');
|
2021-06-11 02:52:59 +03:00
|
|
|
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/page2.html');`);
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|
2021-04-21 04:45:52 +03:00
|
|
|
|
2021-08-18 17:27:45 +03:00
|
|
|
test('should --save-trace', async ({ runCLI }, testInfo) => {
|
|
|
|
const traceFileName = testInfo.outputPath('trace.zip');
|
|
|
|
const cli = runCLI([`--save-trace=${traceFileName}`]);
|
|
|
|
await cli.exited;
|
|
|
|
expect(fs.existsSync(traceFileName)).toBeTruthy();
|
|
|
|
});
|
2021-08-23 19:22:19 +03:00
|
|
|
|
2022-08-09 01:13:38 +03:00
|
|
|
test('should save assets via SIGINT', async ({ runCLI, platform }, testInfo) => {
|
|
|
|
test.skip(platform === 'win32', 'SIGINT not supported on Windows');
|
|
|
|
|
|
|
|
const traceFileName = testInfo.outputPath('trace.zip');
|
|
|
|
const storageFileName = testInfo.outputPath('auth.json');
|
|
|
|
const harFileName = testInfo.outputPath('har.har');
|
|
|
|
const cli = runCLI([`--save-trace=${traceFileName}`, `--save-storage=${storageFileName}`, `--save-har=${harFileName}`], {
|
|
|
|
noAutoExit: true,
|
|
|
|
});
|
|
|
|
await cli.waitFor(`import { test, expect } from '@playwright/test'`);
|
|
|
|
cli.exit('SIGINT');
|
|
|
|
const { exitCode } = await cli.process.exited;
|
|
|
|
expect(exitCode).toBe(130);
|
|
|
|
expect(fs.existsSync(traceFileName)).toBeTruthy();
|
|
|
|
expect(fs.existsSync(storageFileName)).toBeTruthy();
|
|
|
|
expect(fs.existsSync(harFileName)).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2021-08-23 19:22:19 +03:00
|
|
|
test('should fill tricky characters', async ({ page, openRecorder }) => {
|
|
|
|
const recorder = await openRecorder();
|
|
|
|
|
2021-08-24 05:38:50 +03:00
|
|
|
await recorder.setContentAndWait(`<textarea spellcheck=false id="textarea" name="name" oninput="console.log(textarea.value)"></textarea>`);
|
2021-08-23 19:22:19 +03:00
|
|
|
const selector = await recorder.focusElement('textarea');
|
|
|
|
expect(selector).toBe('textarea[name="name"]');
|
|
|
|
|
|
|
|
const [message, sources] = await Promise.all([
|
|
|
|
page.waitForEvent('console', msg => msg.type() !== 'error'),
|
|
|
|
recorder.waitForOutput('JavaScript', 'fill'),
|
|
|
|
page.fill('textarea', 'Hello\'\"\`\nWorld')
|
|
|
|
]);
|
|
|
|
|
|
|
|
expect(sources.get('JavaScript').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator('textarea[name="name"]').fill('Hello\\'"\`\\nWorld');`);
|
|
|
|
|
2021-08-23 19:22:19 +03:00
|
|
|
expect(sources.get('Java').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator("textarea[name=\\\"name\\\"]").fill("Hello'\\"\`\\nWorld");`);
|
2021-08-23 19:22:19 +03:00
|
|
|
|
|
|
|
expect(sources.get('Python').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
page.locator(\"textarea[name=\\\"name\\\"]\").fill(\"Hello'\\"\`\\nWorld\")`);
|
2021-08-23 19:22:19 +03:00
|
|
|
|
|
|
|
expect(sources.get('Python Async').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.locator(\"textarea[name=\\\"name\\\"]\").fill(\"Hello'\\"\`\\nWorld\")`);
|
2021-08-23 19:22:19 +03:00
|
|
|
|
|
|
|
expect(sources.get('C#').text).toContain(`
|
2022-02-05 06:27:45 +03:00
|
|
|
await page.Locator(\"textarea[name=\\\"name\\\"]\").FillAsync(\"Hello'\\"\`\\nWorld\");`);
|
2021-08-23 19:22:19 +03:00
|
|
|
|
|
|
|
expect(message.text()).toBe('Hello\'\"\`\nWorld');
|
|
|
|
});
|
|
|
|
|
2021-02-12 04:46:54 +03:00
|
|
|
});
|