Skip to content

Commit

Permalink
fix(codgen): assertValue works with disabled select (#31315)
Browse files Browse the repository at this point in the history
  • Loading branch information
4ydx committed Jun 28, 2024
1 parent ea33137 commit 4089f45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
21 changes: 21 additions & 0 deletions tests/library/inspector/cli-codegen-3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4089f45

Please sign in to comment.