Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: fix codegen tests (#39433)

Dmitry Gozman982b9b279557
diff --git a/packages/injected/src/recorder/recorder.ts b/packages/injected/src/recorder/recorder.ts
index df9e989b8b..40dbf7df80 100644
--- a/packages/injected/src/recorder/recorder.ts
+++ b/packages/injected/src/recorder/recorder.ts
@@ -168,7 +168,7 @@ class InspectTool implements RecorderTool {
private _commit(selector: string, model: HighlightModel) {
if (this._assertVisibility) {
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'assertVisible',
selector,
signals: [],
@@ -658,8 +658,19 @@ class RecordActionTool implements RecorderTool {
consumeEvent(event);
}
+ private _reportPerformedActionForTests() {
+ if (!this._recorder.injectedScript.isUnderTest)
+ return;
+ // Serialize all to string as we cannot attribute console message to isolated world
+ // in Firefox.
+ console.error('Action performed for test: ' + JSON.stringify({ // eslint-disable-line no-console
+ hovered: this._hoveredModel ? this._hoveredModel.selector : null,
+ active: this._activeModel ? this._activeModel.selector : null,
+ }));
+ }
+
private _recordAction(action: actions.Action) {
- this._recorder.recordAction(action);
+ void this._recorder.recordAction(action).then(() => this._reportPerformedActionForTests());
}
private _performAction(action: actions.PerformOnRecordAction) {
@@ -667,23 +678,11 @@ class RecordActionTool implements RecorderTool {
this._performingActions.add(action);
- const promise = this._recorder.performAction(action).then(() => {
+ void this._recorder.performAction(action).finally(() => {
this._performingActions.delete(action);
// If that was a keyboard action, it similarly requires new selectors for active model.
this._onFocus(false);
- });
-
- if (!this._recorder.injectedScript.isUnderTest)
- return;
-
- void promise.then(() => {
- // Serialize all to string as we cannot attribute console message to isolated world
- // in Firefox.
- console.error('Action performed for test: ' + JSON.stringify({ // eslint-disable-line no-console
- hovered: this._hoveredModel ? (this._hoveredModel as any).selector : null,
- active: this._activeModel ? (this._activeModel as any).selector : null,
- }));
- });
+ }).then(() => this._reportPerformedActionForTests());
}
private _shouldGenerateKeyPressFor(event: KeyboardEvent): boolean {
@@ -772,7 +771,7 @@ class JsonRecordActionTool implements RecorderTool {
const { ariaSnapshot, selector, ref } = this._ariaSnapshot(element);
if (checkbox && event.detail === 1) {
// Interestingly, inputElement.checked is reversed inside this event handler.
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: checkbox.checked ? 'check' : 'uncheck',
selector,
ref,
@@ -782,7 +781,7 @@ class JsonRecordActionTool implements RecorderTool {
return;
}
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'click',
selector,
ref,
@@ -798,7 +797,7 @@ class JsonRecordActionTool implements RecorderTool {
onContextMenu(event: MouseEvent): void {
const element = this._recorder.deepEventTarget(event);
const { ariaSnapshot, selector, ref } = this._ariaSnapshot(element);
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'click',
selector,
ref,
@@ -816,7 +815,7 @@ class JsonRecordActionTool implements RecorderTool {
const { ariaSnapshot, selector, ref } = this._ariaSnapshot(element);
if (isRangeInput(element)) {
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'fill',
selector,
ref,
@@ -833,7 +832,7 @@ class JsonRecordActionTool implements RecorderTool {
return;
}
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'fill',
ref,
selector,
@@ -846,7 +845,7 @@ class JsonRecordActionTool implements RecorderTool {
if (element.nodeName === 'SELECT') {
const selectElement = element as HTMLSelectElement;
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'select',
selector,
ref,
@@ -869,7 +868,7 @@ class JsonRecordActionTool implements RecorderTool {
if (event.key === ' ') {
const checkbox = asCheckbox(element);
if (checkbox && event.detail === 0) {
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: checkbox.checked ? 'uncheck' : 'check',
selector,
ref,
@@ -880,7 +879,7 @@ class JsonRecordActionTool implements RecorderTool {
}
}
- this._recorder.recordAction({
+ void this._recorder.recordAction({
name: 'press',
selector,
ref,
@@ -1099,7 +1098,7 @@ class TextAssertionTool implements RecorderTool {
if (!this._action || !this._dialog.isShowing())
return;
this._dialog.close();
- this._recorder.recordAction(this._action);
+ void this._recorder.recordAction(this._action);
this._recorder.setMode('recording');
}
@@ -1110,7 +1109,7 @@ class TextAssertionTool implements RecorderTool {
if (this._action?.name === 'assertText') {
this._showTextDialog(this._action);
} else if (this._action?.name === 'assertSnapshot') {
- this._recorder.recordAction(this._action);
+ void this._recorder.recordAction(this._action);
this._recorder.setMode('recording');
this._recorder.overlay?.flashToolSucceeded('assertingSnapshot');
}
@@ -1151,7 +1150,7 @@ class TextAssertionTool implements RecorderTool {
const action = this._generateAction();
if (!action)
return;
- this._recorder.recordAction(action);
+ void this._recorder.recordAction(action);
this._recorder.setMode('recording');
this._recorder.overlay?.flashToolSucceeded('assertingValue');
}
@@ -1714,9 +1713,9 @@ export class Recorder {
await this._delegate.performAction?.(action).catch(() => {});
}
- recordAction(action: actions.Action) {
+ async recordAction(action: actions.Action) {
this._lastActionAutoexpectSnapshot = this._captureAutoExpectSnapshot();
- void this._delegate.recordAction?.(action);
+ await this._delegate.recordAction?.(action);
}
setOverlayState(state: { offsetX: number; }) {
diff --git a/tests/library/browsercontext-timezone-id.spec.ts b/tests/library/browsercontext-timezone-id.spec.ts
index 31436581a2..9a2e596a2c 100644
--- a/tests/library/browsercontext-timezone-id.spec.ts
+++ b/tests/library/browsercontext-timezone-id.spec.ts
@@ -18,29 +18,31 @@
import { browserTest as it, expect } from '../config/browserTest';
it('should work @smoke', async ({ browser, browserName }) => {
+ // Note: timezone names are rendered differently between browsers and platforms,
+ // so we only check the GMT offset.
const func = () => new Date(1479579154987).toString();
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: 'America/Jamaica' });
const page = await context.newPage();
- expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 13:12:34 GMT-0500 (Eastern Standard Time)');
+ expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 13:12:34 GMT-0500');
await context.close();
}
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Pacific/Honolulu' });
const page = await context.newPage();
- expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 08:12:34 GMT-1000 (Hawaii-Aleutian Standard Time)');
+ expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 08:12:34 GMT-1000');
await context.close();
}
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: browserName === 'firefox' ? 'America/Argentina/Buenos_Aires' : 'America/Buenos_Aires' });
const page = await context.newPage();
- expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 15:12:34 GMT-0300 (Argentina Standard Time)');
+ expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 15:12:34 GMT-0300');
await context.close();
}
{
const context = await browser.newContext({ locale: 'en-US', timezoneId: 'Europe/Berlin' });
const page = await context.newPage();
- expect(await page.evaluate(func)).toBe('Sat Nov 19 2016 19:12:34 GMT+0100 (Central European Standard Time)');
+ expect(await page.evaluate(func)).toContain('Sat Nov 19 2016 19:12:34 GMT+0100');
await context.close();
}
});
diff --git a/tests/library/inspector/cli-codegen-1.spec.ts b/tests/library/inspector/cli-codegen-1.spec.ts
index 7ced183e3b..dcfe89c72a 100644
--- a/tests/library/inspector/cli-codegen-1.spec.ts
+++ b/tests/library/inspector/cli-codegen-1.spec.ts
@@ -91,10 +91,8 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).DblClickAsync()
]);
});
- test('should click twice', async ({ openRecorder, headless }) => {
- test.skip(!headless, 'real mouse moves sneak between two clicks, moving away from the button');
-
- const { page, recorder } = await openRecorder();
+ test('should click twice', async ({ openRecorder }) => {
+ const { recorder } = await openRecorder();
await recorder.setContentAndWait(`<button onclick="console.log('click')">Submit</button>`);
@@ -104,14 +102,13 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).DblClickAsync()
await Promise.all([
recorder.waitForOutput('JavaScript', 'click'),
recorder.trustedClick(),
+ recorder.waitForActionPerformed(),
]);
- // Do not trigger double click.
- await page.waitForTimeout(3000);
-
const [sources] = await Promise.all([
recorder.waitForOutput('JavaScript', `click();\n await`),
recorder.trustedClick(),
+ recorder.waitForActionPerformed(),
]);
expect(sources.get('JavaScript')!.text).toContain(`
@@ -129,14 +126,13 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).DblClickAsync()
await Promise.all([
recorder.waitForOutput('JavaScript', 'click'),
recorder.trustedClick(),
+ recorder.waitForActionPerformed(),
]);
- // Do not trigger double click.
- await page.waitForTimeout(3000);
-
await Promise.all([
recorder.waitForOutput('JavaScript', `click();\n await`),
recorder.trustedClick(),
+ recorder.waitForActionPerformed(),
]);
await page.keyboard.type('bar');
@@ -1061,8 +1057,9 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();`)
await Promise.all([
recorder.waitForOutput('JavaScript', 'click'),
page.locator('button').click(),
+ recorder.waitForActionPerformed(),
]);
- await page.waitForTimeout(500);
+ await page.waitForTimeout(600); // See "signalThreshold" is signal processor.
await page.goto(server.PREFIX + `/empty.html`);
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/empty.html');`);
});
@@ -1073,8 +1070,9 @@ await page.GetByRole(AriaRole.Button, new() { Name = "Submit" }).ClickAsync();`)
await Promise.all([
recorder.waitForOutput('JavaScript', 'fill'),
page.locator('textarea').fill('Hello world'),
+ recorder.waitForActionPerformed(),
]);
- await page.waitForTimeout(500);
+ await page.waitForTimeout(600); // See "signalThreshold" is signal processor.
await page.goto(server.PREFIX + `/empty.html`);
await recorder.waitForOutput('JavaScript', `await page.goto('${server.PREFIX}/empty.html');`);
});
diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts
index 79899c011f..af403d56be 100644
--- a/tests/library/inspector/cli-codegen-2.spec.ts
+++ b/tests/library/inspector/cli-codegen-2.spec.ts
@@ -17,8 +17,6 @@
import { test, expect } from './inspectorTest';
test.describe('cli codegen', () => {
- test.skip(({ mode }) => mode !== 'default');
-
test('should contain open page', async ({ openRecorder }) => {
const { recorder } = await openRecorder();
@@ -412,7 +410,7 @@ await page1.GotoAsync("about:blank?foo");`);
});
test('should update active model on action', async ({ openRecorder, browserName, headless }) => {
- test.fixme(browserName === 'webkit');
+ test.skip(browserName === 'webkit', 'webkit does not actually focus the input after click');
const { page, recorder } = await openRecorder();
await recorder.setContentAndWait(`<input id="checkbox" type="checkbox" name="accept" onchange="checkbox.name='updated'"></input>`);
diff --git a/tests/library/inspector/cli-codegen-3.spec.ts b/tests/library/inspector/cli-codegen-3.spec.ts
index b6cba0bf8c..488d8b82e2 100644
--- a/tests/library/inspector/cli-codegen-3.spec.ts
+++ b/tests/library/inspector/cli-codegen-3.spec.ts
@@ -20,8 +20,6 @@ import { test, expect } from './inspectorTest';
import type { Page } from '@playwright/test';
test.describe('cli codegen', () => {
- test.skip(({ mode }) => mode !== 'default');
-
test('should click locator.first', async ({ openRecorder }) => {
const { page, recorder } = await openRecorder();
@@ -803,7 +801,7 @@ await page.GetByTestId("testid").HoverAsync();`);
});
test('should assert value on disabled input', async ({ openRecorder, browserName }) => {
- test.fixme(browserName === 'firefox', 'pointerup event is not dispatched on a disabled input');
+ test.skip(browserName === 'firefox', 'pointerup event is not dispatched on a disabled input');
const { recorder } = await openRecorder();
diff --git a/tests/library/inspector/cli-codegen-aria.spec.ts b/tests/library/inspector/cli-codegen-aria.spec.ts
index 5dc600921d..3c8d3cce7d 100644
--- a/tests/library/inspector/cli-codegen-aria.spec.ts
+++ b/tests/library/inspector/cli-codegen-aria.spec.ts
@@ -18,8 +18,6 @@ import { test, expect } from './inspectorTest';
import { roundBox } from '../../config/utils';
test.describe(() => {
- test.skip(({ mode }) => mode !== 'default');
-
test('should generate aria snapshot', async ({ openRecorder }) => {
const { recorder } = await openRecorder();
await recorder.setContentAndWait(`<main><button>Submit</button></main>`);
diff --git a/tests/library/inspector/cli-codegen-pick-locator.spec.ts b/tests/library/inspector/cli-codegen-pick-locator.spec.ts
index 346dbcfaad..154d0290f1 100644
--- a/tests/library/inspector/cli-codegen-pick-locator.spec.ts
+++ b/tests/library/inspector/cli-codegen-pick-locator.spec.ts
@@ -18,8 +18,6 @@ import { test, expect } from './inspectorTest';
import { roundBox } from '../../config/utils';
test.describe(() => {
- test.skip(({ mode }) => mode !== 'default');
-
test('should inspect locator', async ({ openRecorder }) => {
const { recorder } = await openRecorder();
await recorder.setContentAndWait(`<main><button>Submit</button></main>`);
diff --git a/tests/library/inspector/console-api.spec.ts b/tests/library/inspector/console-api.spec.ts
index 2b40b8943a..ebc9cef72a 100644
--- a/tests/library/inspector/console-api.spec.ts
+++ b/tests/library/inspector/console-api.spec.ts
@@ -16,8 +16,6 @@
import { test as it, expect } from './inspectorTest';
-it.skip(({ mode }) => mode !== 'default');
-
let scriptPromise: Promise<void>;
it.beforeEach(async ({ page, recorderPageGetter }) => {
diff --git a/tests/library/inspector/inspectorTest.ts b/tests/library/inspector/inspectorTest.ts
index fa1ccc9fb9..2838b0094f 100644
--- a/tests/library/inspector/inspectorTest.ts
+++ b/tests/library/inspector/inspectorTest.ts
@@ -50,8 +50,9 @@ const codegenLangId2lang = new Map([...codegenLang2Id.entries()].map(([lang, lan
const playwrightToAutomateInspector = require('../../../packages/playwright-core/lib/inProcessFactory').createInProcessPlaywright(nodePlatform);
export const test = contextTest.extend<CLITestArgs>({
- recorderPageGetter: async ({ context, toImpl, mode }, run, testInfo) => {
- testInfo.skip(mode.startsWith('service'));
+ recorderPageGetter: async ({ context, toImpl, mode, headless }, run, testInfo) => {
+ testInfo.skip(mode !== 'default');
+ testInfo.skip(!headless, 'real mouse moves mess up with recording');
await run(async () => {
while (!toImpl(context).recorderAppForTest)
await new Promise(f => setTimeout(f, 100));
diff --git a/tests/library/inspector/pause.spec.ts b/tests/library/inspector/pause.spec.ts
index 5f91d7638b..ca20662f6c 100644
--- a/tests/library/inspector/pause.spec.ts
+++ b/tests/library/inspector/pause.spec.ts
@@ -21,8 +21,6 @@ import type { BoundingBox } from '../../config/utils';
import { pauseHelper } from './pause-helper';
it('should resume when closing inspector', async ({ page, recorderPageGetter, closeRecorder, mode }) => {
- it.skip(mode !== 'default');
-
const scriptPromise = (async () => {
// @ts-ignore
await page.pause({ __testHookKeepTestTimeout: true });
@@ -62,8 +60,6 @@ world`);
});
it.describe('pause', () => {
- it.skip(({ mode }) => mode !== 'default');
-
it.afterEach(async ({ recorderPageGetter }, testInfo) => {
if (testInfo.status === 'skipped')
return;