test: fix multiple focus highlights in ff codegen tests (#14937)

This commit is contained in:
Dmitry Gozman 2022-06-16 17:49:08 -07:00 committed by GitHub
parent 245c33a5d4
commit 2e646ef92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@
*/ */
import { contextTest } from '../../config/browserTest'; import { contextTest } from '../../config/browserTest';
import type { Page } from 'playwright-core'; import type { ConsoleMessage, Page } from 'playwright-core';
import * as path from 'path'; import * as path from 'path';
import type { Source } from '../../../packages/playwright-core/src/server/recorder/recorderTypes'; import type { Source } from '../../../packages/playwright-core/src/server/recorder/recorderTypes';
import type { CommonFixtures, TestChildProcess } from '../../config/commonFixtures'; import type { CommonFixtures, TestChildProcess } from '../../config/commonFixtures';
@ -131,21 +131,27 @@ class Recorder {
} }
async waitForHighlight(action: () => Promise<void>): Promise<string> { async waitForHighlight(action: () => Promise<void>): Promise<string> {
let callback; // We get the last highlighted selector, because Firefox sometimes issues multiple
const result = new Promise<string>(f => callback = f); // focus events.
const listener = async msg => { let generatedSelector: string | undefined;
let callback: Function | undefined;
const listener = async (msg: ConsoleMessage) => {
const prefix = 'Highlight updated for test: '; const prefix = 'Highlight updated for test: ';
if (msg.text().startsWith(prefix)) { if (msg.text().startsWith(prefix)) {
generatedSelector = msg.text().substr(prefix.length);
if (callback) {
this.page.off('console', listener); this.page.off('console', listener);
callback(msg.text().substr(prefix.length)); callback(generatedSelector);
}
} }
}; };
this.page.on('console', listener); this.page.on('console', listener);
const [ generatedSelector ] = await Promise.all([
result, await action();
action() if (generatedSelector)
]);
return generatedSelector; return generatedSelector;
return await new Promise<string>(f => callback = f);
} }
async waitForActionPerformed(): Promise<{ hovered: string | null, active: string | null }> { async waitForActionPerformed(): Promise<{ hovered: string | null, active: string | null }> {