Skip to content

Commit 4089f45

Browse files
authored
fix(codgen): assertValue works with disabled select (#31315)
1 parent ea33137 commit 4089f45

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/playwright-core/src/server/injected/recorder/recorder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ class TextAssertionTool implements RecorderTool {
578578

579579
onPointerUp(event: PointerEvent) {
580580
const target = this._hoverHighlight?.elements[0];
581-
if (this._kind === 'value' && target && target.nodeName === 'INPUT' && (target as HTMLInputElement).disabled) {
582-
// Click on a disabled input does not produce a "click" event, but we still want
581+
if (this._kind === 'value' && target && (target.nodeName === 'INPUT' || target.nodeName === 'SELECT') && (target as HTMLInputElement).disabled) {
582+
// Click on a disabled input (or select) does not produce a "click" event, but we still want
583583
// to assert the value.
584584
this._commitAssertValue();
585585
}

tests/library/inspector/cli-codegen-3.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,27 @@ await page.GetByLabel("Coun\\"try").ClickAsync();`);
631631
expect.soft(sources2.get('C#')!.text).toContain(`await Expect(page.Locator("#second")).ToHaveValueAsync("bar")`);
632632
});
633633

634+
test('should assert value on disabled select', async ({ openRecorder, browserName }) => {
635+
const recorder = await openRecorder();
636+
637+
await recorder.setContentAndWait(`
638+
<select id=first><option value=foo1>Foo1</option><option value=bar1>Bar1</option></select>
639+
<select id=second disabled><option value=foo2>Foo2</option><option value=bar2 selected>Bar2</option></select>
640+
`);
641+
642+
await recorder.page.click('x-pw-tool-item.value');
643+
await recorder.hoverOverElement('#second');
644+
const [sources2] = await Promise.all([
645+
recorder.waitForOutput('JavaScript', '#second'),
646+
recorder.trustedClick(),
647+
]);
648+
expect.soft(sources2.get('JavaScript')!.text).toContain(`await expect(page.locator('#second')).toHaveValue('bar2')`);
649+
expect.soft(sources2.get('Python')!.text).toContain(`expect(page.locator("#second")).to_have_value("bar2")`);
650+
expect.soft(sources2.get('Python Async')!.text).toContain(`await expect(page.locator("#second")).to_have_value("bar2")`);
651+
expect.soft(sources2.get('Java')!.text).toContain(`assertThat(page.locator("#second")).hasValue("bar2")`);
652+
expect.soft(sources2.get('C#')!.text).toContain(`await Expect(page.Locator("#second")).ToHaveValueAsync("bar2")`);
653+
});
654+
634655
test('should assert visibility', async ({ openRecorder }) => {
635656
const recorder = await openRecorder();
636657

0 commit comments

Comments
 (0)