Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(recorder): skip click on file inputs and use hoveredModel (#40899)
Yury Semikhatsky9afece0faebf
diff --git a/packages/injected/src/recorder/recorder.ts b/packages/injected/src/recorder/recorder.tsindex 7b4c98f59b..22a22144e4 100644--- a/packages/injected/src/recorder/recorder.ts+++ b/packages/injected/src/recorder/recorder.ts@@ -414,7 +414,8 @@ class RecordActionTool implements RecorderTool {if (target.nodeName === 'INPUT' && (target as HTMLInputElement).type.toLowerCase() === 'file') {this._recordAction({name: 'setInputFiles',- selector: this._activeModel!.selector,+ // webkit doesn't focus file inputs on click, so activeModel is unreliable here.+ selector: this._hoveredModel!.selector,signals: [],files: [...((target as HTMLInputElement).files || [])].map(file => file.name),});@@ -614,13 +615,7 @@ class RecordActionTool implements RecorderTool {}private _shouldIgnoreMouseEvent(event: MouseEvent): boolean {- const target = this._recorder.deepEventTarget(event);- const nodeName = target.nodeName;- if (nodeName === 'SELECT' || nodeName === 'OPTION')- return true;- if (nodeName === 'INPUT' && ['date', 'range'].includes((target as HTMLInputElement).type))- return true;- return false;+ return shouldIgnoreMouseEvent(this._recorder.deepEventTarget(event));}private _actionInProgress(event: Event): boolean {@@ -891,13 +886,7 @@ class JsonRecordActionTool implements RecorderTool {}private _shouldIgnoreMouseEvent(event: MouseEvent): boolean {- const target = this._recorder.deepEventTarget(event);- const nodeName = target.nodeName;- if (nodeName === 'SELECT' || nodeName === 'OPTION')- return true;- if (nodeName === 'INPUT' && ['date', 'range'].includes((target as HTMLInputElement).type))- return true;- return false;+ return shouldIgnoreMouseEvent(this._recorder.deepEventTarget(event));}private _shouldGenerateKeyPressFor(event: KeyboardEvent): boolean {@@ -1886,6 +1875,18 @@ function isRangeInput(node: Node | null): node is HTMLInputElement {return inputElement.type.toLowerCase() === 'range';}+// Non-text input types that open native pickers.+const kNativePickerInputTypes = new Set(['color', 'date', 'datetime-local', 'file', 'month', 'range', 'time', 'week']);++function shouldIgnoreMouseEvent(target: Node): boolean {+ const nodeName = target.nodeName;+ if (nodeName === 'SELECT' || nodeName === 'OPTION')+ return true;+ if (nodeName === 'INPUT' && kNativePickerInputTypes.has((target as HTMLInputElement).type))+ return true;+ return false;+}+function addEventListener(target: EventTarget, eventName: string, listener: EventListener, useCapture?: boolean): () => void {target.addEventListener(eventName, listener, useCapture);const remove = () => {diff --git a/packages/playwright-core/src/server/recorder/recorderUtils.ts b/packages/playwright-core/src/server/recorder/recorderUtils.tsindex ed23d59b6d..fca4472208 100644--- a/packages/playwright-core/src/server/recorder/recorderUtils.ts+++ b/packages/playwright-core/src/server/recorder/recorderUtils.ts@@ -97,12 +97,6 @@ export function shouldMergeAction(action: actions.ActionInContext, lastAction: areturn isSameAction(action, lastAction);case 'click':return isSameAction(action, lastAction) && isSameSelector(action, lastAction) && isShortlyAfter(action, lastAction) && action.action.clickCount > (lastAction.action as actions.ClickAction).clickCount;- case 'setInputFiles':- // Drop the click that opens the file picker — setInputFiles already does it,- // and on replay the leftover click() opens an extra picker that never closes.- // No time check: picking a file from the OS dialog can take many seconds and- // no other recorder actions can run while the dialog is open.- return lastAction.action.name === 'click' && isSameSelector(action, lastAction);}return false;}