fix(codgen): assertValue works with disabled select (#31315)

This commit is contained in:
4ydx 2024-06-29 05:04:59 +09:00 committed by GitHub
parent ea33137a0e
commit 4089f4593b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -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();
}

View File

@ -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(`
<select id=first><option value=foo1>Foo1</option><option value=bar1>Bar1</option></select>
<select id=second disabled><option value=foo2>Foo2</option><option value=bar2 selected>Bar2</option></select>
`);
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();