From 4089f4593b3430dda5e4aca28119c50b71bd85e7 Mon Sep 17 00:00:00 2001 From: 4ydx Date: Sat, 29 Jun 2024 05:04:59 +0900 Subject: [PATCH] fix(codgen): assertValue works with disabled select (#31315) --- .../src/server/injected/recorder/recorder.ts | 4 ++-- tests/library/inspector/cli-codegen-3.spec.ts | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/server/injected/recorder/recorder.ts b/packages/playwright-core/src/server/injected/recorder/recorder.ts index 261a0eab2134a..4cfa512a4faa2 100644 --- a/packages/playwright-core/src/server/injected/recorder/recorder.ts +++ b/packages/playwright-core/src/server/injected/recorder/recorder.ts @@ -578,8 +578,8 @@ class TextAssertionTool implements RecorderTool { onPointerUp(event: PointerEvent) { const target = this._hoverHighlight?.elements[0]; - if (this._kind === 'value' && target && target.nodeName === 'INPUT' && (target as HTMLInputElement).disabled) { - // Click on a disabled input does not produce a "click" event, but we still want + if (this._kind === 'value' && target && (target.nodeName === 'INPUT' || target.nodeName === 'SELECT') && (target as HTMLInputElement).disabled) { + // Click on a disabled input (or select) does not produce a "click" event, but we still want // to assert the value. this._commitAssertValue(); } diff --git a/tests/library/inspector/cli-codegen-3.spec.ts b/tests/library/inspector/cli-codegen-3.spec.ts index 96a6295f13a26..2c0fff974afac 100644 --- a/tests/library/inspector/cli-codegen-3.spec.ts +++ b/tests/library/inspector/cli-codegen-3.spec.ts @@ -631,6 +631,27 @@ await page.GetByLabel("Coun\\"try").ClickAsync();`); expect.soft(sources2.get('C#')!.text).toContain(`await Expect(page.Locator("#second")).ToHaveValueAsync("bar")`); }); + test('should assert value on disabled select', async ({ openRecorder, browserName }) => { + const recorder = await openRecorder(); + + await recorder.setContentAndWait(` + + + `); + + await recorder.page.click('x-pw-tool-item.value'); + await recorder.hoverOverElement('#second'); + const [sources2] = await Promise.all([ + recorder.waitForOutput('JavaScript', '#second'), + recorder.trustedClick(), + ]); + expect.soft(sources2.get('JavaScript')!.text).toContain(`await expect(page.locator('#second')).toHaveValue('bar2')`); + expect.soft(sources2.get('Python')!.text).toContain(`expect(page.locator("#second")).to_have_value("bar2")`); + expect.soft(sources2.get('Python Async')!.text).toContain(`await expect(page.locator("#second")).to_have_value("bar2")`); + expect.soft(sources2.get('Java')!.text).toContain(`assertThat(page.locator("#second")).hasValue("bar2")`); + expect.soft(sources2.get('C#')!.text).toContain(`await Expect(page.Locator("#second")).ToHaveValueAsync("bar2")`); + }); + test('should assert visibility', async ({ openRecorder }) => { const recorder = await openRecorder();