mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: fix multiple focus highlights in ff codegen tests (#14937)
This commit is contained in:
parent
245c33a5d4
commit
2e646ef92a
@ -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 }> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user