Skip to content

Commit

Permalink
fix(recorder): align apiName with the real one (#33567)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Nov 13, 2024
1 parent 88082b4 commit 099dd80
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
14 changes: 9 additions & 5 deletions packages/playwright-core/src/server/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export class Recorder implements InstrumentationListener, IRecorder {
this._highlightedElement = {};
this._mode = mode;
this._recorderApp?.setMode(this._mode);
this._contextRecorder.setEnabled(this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue' || this._mode === 'assertingSnapshot');
this._debugger.setMuted(this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue');
this._contextRecorder.setEnabled(this._isRecording());
this._debugger.setMuted(this._isRecording());
if (this._mode !== 'none' && this._mode !== 'standby' && this._context.pages().length === 1)
this._context.pages()[0].bringToFront().catch(() => {});
this._refreshOverlay();
Expand Down Expand Up @@ -292,7 +292,7 @@ export class Recorder implements InstrumentationListener, IRecorder {
}

async onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata) {
if (this._omitCallTracking || this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue')
if (this._omitCallTracking || this._isRecording())
return;
this._currentCallsMetadata.set(metadata, sdkObject);
this._updateUserSources();
Expand All @@ -304,7 +304,7 @@ export class Recorder implements InstrumentationListener, IRecorder {
}

async onAfterCall(sdkObject: SdkObject, metadata: CallMetadata) {
if (this._omitCallTracking || this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue')
if (this._omitCallTracking || this._isRecording())
return;
if (!metadata.error)
this._currentCallsMetadata.delete(metadata);
Expand Down Expand Up @@ -354,7 +354,7 @@ export class Recorder implements InstrumentationListener, IRecorder {
}

updateCallLog(metadatas: CallMetadata[]) {
if (this._mode === 'recording' || this._mode === 'assertingText' || this._mode === 'assertingVisibility' || this._mode === 'assertingValue')
if (this._isRecording())
return;
const logs: CallLog[] = [];
for (const metadata of metadatas) {
Expand All @@ -370,6 +370,10 @@ export class Recorder implements InstrumentationListener, IRecorder {
this._recorderApp?.updateCallLogs(logs);
}

private _isRecording() {
return ['recording', 'assertingText', 'assertingVisibility', 'assertingValue', 'assertingSnapshot'].includes(this._mode);
}

private _readSource(fileName: string): string {
try {
return fs.readFileSync(fileName, 'utf-8');
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/server/recorder/recorderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export async function frameForAction(pageAliases: Map<Page, string>, actionInCon

export function callMetadataForAction(pageAliases: Map<Page, string>, actionInContext: actions.ActionInContext): { callMetadata: CallMetadata, mainFrame: Frame } {
const mainFrame = mainFrameForAction(pageAliases, actionInContext);
const { method, params } = traceParamsForAction(actionInContext);
const { method, apiName, params } = traceParamsForAction(actionInContext);

const callMetadata: CallMetadata = {
id: `call@${createGuid()}`,
apiName: 'page.' + method,
apiName,
objectId: mainFrame.guid,
pageId: mainFrame._page.guid,
frameId: mainFrame.guid,
Expand Down
28 changes: 14 additions & 14 deletions packages/playwright-core/src/utils/isomorphic/recorderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ export function buildFullSelector(framePath: string[], selector: string) {

const kDefaultTimeout = 5_000;

export function traceParamsForAction(actionInContext: recorderActions.ActionInContext): { method: string, params: any } {
export function traceParamsForAction(actionInContext: recorderActions.ActionInContext): { method: string, apiName: string, params: any } {
const { action } = actionInContext;

switch (action.name) {
case 'navigate': {
const params: channels.FrameGotoParams = {
url: action.url,
};
return { method: 'goto', params };
return { method: 'goto', apiName: 'page.goto', params };
}
case 'openPage':
case 'closePage':
Expand All @@ -50,53 +50,53 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
clickCount: action.clickCount,
position: action.position,
};
return { method: 'click', params };
return { method: 'click', apiName: 'locator.click', params };
}
case 'press': {
const params: channels.FramePressParams = {
selector,
strict: true,
key: [...toKeyboardModifiers(action.modifiers), action.key].join('+'),
};
return { method: 'press', params };
return { method: 'press', apiName: 'locator.press', params };
}
case 'fill': {
const params: channels.FrameFillParams = {
selector,
strict: true,
value: action.text,
};
return { method: 'fill', params };
return { method: 'fill', apiName: 'locator.fill', params };
}
case 'setInputFiles': {
const params: channels.FrameSetInputFilesParams = {
selector,
strict: true,
localPaths: action.files,
};
return { method: 'setInputFiles', params };
return { method: 'setInputFiles', apiName: 'locator.setInputFiles', params };
}
case 'check': {
const params: channels.FrameCheckParams = {
selector,
strict: true,
};
return { method: 'check', params };
return { method: 'check', apiName: 'locator.check', params };
}
case 'uncheck': {
const params: channels.FrameUncheckParams = {
selector,
strict: true,
};
return { method: 'uncheck', params };
return { method: 'uncheck', apiName: 'locator.uncheck', params };
}
case 'select': {
const params: channels.FrameSelectOptionParams = {
selector,
strict: true,
options: action.options.map(option => ({ value: option })),
};
return { method: 'selectOption', params };
return { method: 'selectOption', apiName: 'locator.selectOption', params };
}
case 'assertChecked': {
const params: channels.FrameExpectParams = {
Expand All @@ -105,7 +105,7 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
isNot: !action.checked,
timeout: kDefaultTimeout,
};
return { method: 'expect', params };
return { method: 'expect', apiName: 'expect.toBeChecked', params };
}
case 'assertText': {
const params: channels.FrameExpectParams = {
Expand All @@ -115,7 +115,7 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
isNot: false,
timeout: kDefaultTimeout,
};
return { method: 'expect', params };
return { method: 'expect', apiName: 'expect.toContainText', params };
}
case 'assertValue': {
const params: channels.FrameExpectParams = {
Expand All @@ -125,7 +125,7 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
isNot: false,
timeout: kDefaultTimeout,
};
return { method: 'expect', params };
return { method: 'expect', apiName: 'expect.toHaveValue', params };
}
case 'assertVisible': {
const params: channels.FrameExpectParams = {
Expand All @@ -134,7 +134,7 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
isNot: false,
timeout: kDefaultTimeout,
};
return { method: 'expect', params };
return { method: 'expect', apiName: 'expect.toBeVisible', params };
}
case 'assertSnapshot': {
const params: channels.FrameExpectParams = {
Expand All @@ -144,7 +144,7 @@ export function traceParamsForAction(actionInContext: recorderActions.ActionInCo
isNot: false,
timeout: kDefaultTimeout,
};
return { method: 'expect', params };
return { method: 'expect', apiName: 'expect.toMatchAriaSnapshot', params };
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/trace-viewer/src/ui/recorder/actionListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ export const ActionListView: React.FC<{
};

export const renderAction = (sdkLanguage: Language, action: actionTypes.ActionInContext) => {
const { method, params } = traceParamsForAction(action);
const { method, apiName, params } = traceParamsForAction(action);
const locator = params.selector ? asLocator(sdkLanguage || 'javascript', params.selector) : undefined;

const apiName = `page.${method}`;
return <>
<div className='action-title' title={apiName}>
<span>{apiName}</span>
Expand Down

0 comments on commit 099dd80

Please sign in to comment.