fix(codegen): make select work with size attribute (#18712)

Fixes https://github.com/microsoft/playwright/issues/18711
This commit is contained in:
Max Schmitt 2022-11-10 15:06:53 -08:00 committed by GitHub
parent 0765182a4d
commit 56d7d47d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 1 deletions

View File

@ -196,7 +196,7 @@ class Recorder {
return true;
}
const nodeName = target.nodeName;
if (nodeName === 'SELECT')
if (nodeName === 'SELECT' || nodeName === 'OPTION')
return true;
if (nodeName === 'INPUT' && ['date'].includes((target as HTMLInputElement).type))
return true;

View File

@ -532,6 +532,47 @@ test.describe('cli codegen', () => {
expect(message.text()).toBe('2');
});
test('should select with size attribute', async ({ page, openRecorder }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`
<style>
body {
margin: 0;
}
</style>
<select id="age" size="2" onchange="console.log(age.selectedOptions[0].value)">
<option value="1">v1</option>
<option value="2">v2</option>
</select>
`);
const locator = await recorder.hoverOverElement('select');
expect(locator).toBe(`locator('#age')`);
const [message, sources] = await Promise.all([
page.waitForEvent('console', msg => msg.type() !== 'error'),
recorder.waitForOutput('JavaScript', 'select'),
page.mouse.click(10, 25)
]);
expect(sources.get('JavaScript').text).toContain(`
await page.locator('#age').selectOption('2');`);
expect(sources.get('Java').text).toContain(`
page.locator("#age").selectOption("2");`);
expect(sources.get('Python').text).toContain(`
page.locator(\"#age\").select_option(\"2\")`);
expect(sources.get('Python Async').text).toContain(`
await page.locator(\"#age\").select_option(\"2\")`);
expect(sources.get('C#').text).toContain(`
await page.Locator(\"#age\").SelectOptionAsync(new[] { \"2\" });`);
expect(message.text()).toBe('2');
});
test('should await popup', async ({ page, openRecorder, browserName, headless }) => {
test.fixme(browserName === 'webkit' && !headless, 'Middle click does not open a popup in our webkit embedder');