Skip to content

Commit

Permalink
fix(recorder): ignore clicks in slider fields
Browse files Browse the repository at this point in the history
Also, in webkit, a click was being recorded because the click event had body as target, which didn't match the hovered element. Ignoring clicks on hovered elements when event target doesn't match prevents this.
  • Loading branch information
ruifigueira committed Dec 22, 2023
1 parent 663cb4a commit 13e4912
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/playwright-core/src/server/injected/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class RecordActionTool implements RecorderTool {
return;
if (this._performingAction)
return;
if (!this._hoveredModel)
if (this._isHoveredWrongTarget(event))
return;

const checkbox = asCheckbox(this._recorder.deepEventTarget(event));
Expand Down Expand Up @@ -257,7 +257,7 @@ class RecordActionTool implements RecorderTool {
}

// Non-navigating actions are simply recorded by Playwright.
if (this._isWrongTarget(event))
if (this._isActiveWrongTarget(event))
return;
this._recorder.delegate.recordAction?.({
name: 'fill',
Expand Down Expand Up @@ -285,7 +285,7 @@ class RecordActionTool implements RecorderTool {
return;
if (this._performingAction)
return;
if (this._isWrongTarget(event))
if (this._isHoveredWrongTarget(event))
return;
// Similarly to click, trigger checkbox on key event, not input.
if (event.key === ' ') {
Expand Down Expand Up @@ -338,8 +338,12 @@ class RecordActionTool implements RecorderTool {
return false;
}

private _isWrongTarget(event: Event): boolean {
return !(this._activeModel && this._activeModel.elements[0] === this._recorder.deepEventTarget(event));
private _isActiveWrongTarget(event: Event): boolean {
return !this._activeModel || this._activeModel.elements[0] !== this._recorder.deepEventTarget(event);
}

private _isHoveredWrongTarget(event: Event): boolean {
return !this._hoveredModel || this._hoveredModel.elements[0] !== this._recorder.deepEventTarget(event);
}

private async _performAction(action: actions.Action) {
Expand Down
4 changes: 4 additions & 0 deletions tests/library/inspector/cli-codegen-1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,8 @@ await page.GetByText("Click me").ClickAsync(new LocatorClickOptions

expect(sources.get('JavaScript')!.text).toContain(`
await page.getByRole('slider').fill('10');`);

expect(sources.get('JavaScript')!.text).not.toContain(`
await page.getByRole('slider').click();`);
});
});

0 comments on commit 13e4912

Please sign in to comment.