Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions packages/playwright-core/src/server/recorder/recorderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { renderTitleForCall } from '@isomorphic/protocolFormatter';
import { raceAgainstDeadline } from '@isomorphic/timeoutRunner';
import { monotonicTime } from '@isomorphic/time';
import { quoteCSSAttributeValue } from '@isomorphic/stringUtils';
import { isUnderTest } from '@utils/debug';
import { Frame } from '../frames';

import type { CallMetadata } from '../instrumentation';
Expand All @@ -28,8 +29,8 @@ function buildFullSelector(framePath: string[], selector: string) {
return [...framePath, selector].join(' >> internal:control=enter-frame >> ');
}

export async function buildFullSelectorForFrame(progress: Progress, frame: Frame, selector: string): Promise<string> {
const framePath = await generateFrameSelector(progress, frame);
export async function buildFullSelectorForFrame(progress: Progress, frame: Frame, selector: string, timeout = isUnderTest() ? 10000 : 2000): Promise<string> {
const framePath = await generateFrameSelector(progress, frame, timeout);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's instead check isUnderTest() and always use 10000 in this case?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot dima is right, do it!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented in 7fdb420. Frame-selector generation now uses a 10s deadline whenever isUnderTest() is true, while production retains 2s.

if (!frame._page.browserContext._options.pierceFrames || !framePath.length)
return buildFullSelector(framePath, selector);

Expand All @@ -40,7 +41,7 @@ export async function buildFullSelectorForFrame(progress: Progress, frame: Frame
if (await resolvesToFrame(progress, candidate, frame))
return candidate;
}
}, monotonicTime() + 2000));
}, monotonicTime() + timeout));
if (!result.timedOut && result.result)
return result.result;

Expand Down Expand Up @@ -83,22 +84,22 @@ export function metadataToCallLog(metadata: CallMetadata, status: CallLogStatus)
}


async function generateFrameSelector(progress: Progress, frame: Frame): Promise<string[]> {
async function generateFrameSelector(progress: Progress, frame: Frame, timeout: number): Promise<string[]> {
const selectorPromises: Promise<string>[] = [];
progress.setAllowConcurrentOrNestedRaces(true);
while (frame) {
const parent = frame.parentFrame();
if (!parent)
break;
selectorPromises.push(generateFrameSelectorInParent(progress, parent, frame));
selectorPromises.push(generateFrameSelectorInParent(progress, parent, frame, timeout));
frame = parent;
}
const result = await Promise.all(selectorPromises);
progress.setAllowConcurrentOrNestedRaces(false);
return result.reverse();
}

async function generateFrameSelectorInParent(prgoress: Progress, parent: Frame, frame: Frame): Promise<string> {
async function generateFrameSelectorInParent(prgoress: Progress, parent: Frame, frame: Frame, timeout: number): Promise<string> {
const result = await raceAgainstDeadline(async () => {
try {
const frameElement = await frame.frameElement(prgoress);
Expand All @@ -112,7 +113,7 @@ async function generateFrameSelectorInParent(prgoress: Progress, parent: Frame,
return selector;
} catch (e) {
}
}, monotonicTime() + 2000);
}, monotonicTime() + timeout);
if (!result.timedOut && result.result)
return result.result;

Expand Down
Loading