Fix unselect issue
This commit is contained in:
parent
a2a6431efd
commit
d5f282ce74
|
|
@ -141,7 +141,7 @@ export class JavaLanguageGenerator implements LanguageGenerator {
|
||||||
case 'navigate':
|
case 'navigate':
|
||||||
return `${subject}.navigate(${quote(action.url)});`;
|
return `${subject}.navigate(${quote(action.url)});`;
|
||||||
case 'select':
|
case 'select':
|
||||||
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.selectOption(${formatSelectOption(action.options.length > 1 ? action.options : action.options[0])});`;
|
return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.selectOption(${formatSelectOption(action.options.length === 1 ? action.options[0] : action.options)});`;
|
||||||
case 'assertText':
|
case 'assertText':
|
||||||
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${action.substring ? 'containsText' : 'hasText'}(${quote(action.text)});`;
|
return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${action.substring ? 'containsText' : 'hasText'}(${quote(action.text)});`;
|
||||||
case 'assertChecked':
|
case 'assertChecked':
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ export class JavaScriptLanguageGenerator implements LanguageGenerator {
|
||||||
case 'navigate':
|
case 'navigate':
|
||||||
return `await ${subject}.goto(${quote(action.url)});`;
|
return `await ${subject}.goto(${quote(action.url)});`;
|
||||||
case 'select':
|
case 'select':
|
||||||
return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`;
|
return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length === 1 ? action.options[0] : action.options)});`;
|
||||||
case 'assertText':
|
case 'assertText':
|
||||||
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
|
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
|
||||||
case 'assertChecked':
|
case 'assertChecked':
|
||||||
|
|
|
||||||
|
|
@ -623,6 +623,72 @@ await page.Locator(\"#age\").SelectOptionAsync(new[] { \"2\" });`);
|
||||||
expect(message.text()).toBe('2');
|
expect(message.text()).toBe('2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should select with multiple attribute', async ({ page, openRecorder }) => {
|
||||||
|
const recorder = await openRecorder();
|
||||||
|
|
||||||
|
await recorder.setContentAndWait('<select id="age" multiple onchange="console.log([...age.selectedOptions].map(x => x.value))"><option value="1">1<option value="2">2</select>');
|
||||||
|
|
||||||
|
const locator = await recorder.hoverOverElement('select');
|
||||||
|
expect(locator).toBe(`locator('#age')`);
|
||||||
|
await page.getByRole('option', { name: '1' }).click();
|
||||||
|
|
||||||
|
const [message, sources] = await Promise.all([
|
||||||
|
page.waitForEvent('console', msg => msg.type() !== 'error' && msg.text().includes('2')),
|
||||||
|
recorder.waitForOutput('JavaScript', 'selectOption(['),
|
||||||
|
page.getByRole('option', { name: '2' }).click({ modifiers: ['ControlOrMeta'] })
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(sources.get('JavaScript')!.text).toContain(`
|
||||||
|
await page.locator('#age').selectOption(['1', '2']);`);
|
||||||
|
|
||||||
|
expect(sources.get('Java')!.text).toContain(`
|
||||||
|
page.locator("#age").selectOption(new String[] {"1", "2"});`);
|
||||||
|
|
||||||
|
expect(sources.get('Python')!.text).toContain(`
|
||||||
|
page.locator("#age").select_option(["1", "2"])`);
|
||||||
|
|
||||||
|
expect(sources.get('Python Async')!.text).toContain(`
|
||||||
|
await page.locator("#age").select_option(["1", "2"])`);
|
||||||
|
|
||||||
|
expect(sources.get('C#')!.text).toContain(`
|
||||||
|
await page.Locator("#age").SelectOptionAsync(new[] { "1", "2" });`);
|
||||||
|
|
||||||
|
expect(message.text()).toBe('[1, 2]');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should unselect with multiple attribute', async ({ page, openRecorder }) => {
|
||||||
|
const recorder = await openRecorder();
|
||||||
|
|
||||||
|
await recorder.setContentAndWait('<select id="age" multiple onchange="console.log([...age.selectedOptions].map(x => x.value))"><option value="1">1<option value="2">2</select>');
|
||||||
|
|
||||||
|
const locator = await recorder.hoverOverElement('select');
|
||||||
|
expect(locator).toBe(`locator('#age')`);
|
||||||
|
await page.getByRole('option', { name: '1' }).click();
|
||||||
|
|
||||||
|
const [message, sources] = await Promise.all([
|
||||||
|
page.waitForEvent('console', msg => msg.type() !== 'error' && msg.text() === '[]'),
|
||||||
|
recorder.waitForOutput('JavaScript', 'selectOption(['),
|
||||||
|
page.getByRole('option', { name: '1' }).click({ modifiers: ['ControlOrMeta'] })
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(sources.get('JavaScript')!.text).toContain(`
|
||||||
|
await page.locator('#age').selectOption([]);`);
|
||||||
|
|
||||||
|
expect(sources.get('Java')!.text).toContain(`
|
||||||
|
page.locator("#age").selectOption(new String[0]);`);
|
||||||
|
|
||||||
|
expect(sources.get('Python')!.text).toContain(`
|
||||||
|
page.locator("#age").select_option([])`);
|
||||||
|
|
||||||
|
expect(sources.get('Python Async')!.text).toContain(`
|
||||||
|
await page.locator("#age").select_option([])`);
|
||||||
|
|
||||||
|
expect(sources.get('C#')!.text).toContain(`
|
||||||
|
await page.Locator("#age").SelectOptionAsync(new[] { });`);
|
||||||
|
|
||||||
|
expect(message.text()).toBe('[]');
|
||||||
|
});
|
||||||
|
|
||||||
test('should await popup', async ({ page, openRecorder, browserName, headless }) => {
|
test('should await popup', async ({ page, openRecorder, browserName, headless }) => {
|
||||||
const recorder = await openRecorder();
|
const recorder = await openRecorder();
|
||||||
await recorder.setContentAndWait('<a target=_blank rel=noopener href="about:blank">link</a>');
|
await recorder.setContentAndWait('<a target=_blank rel=noopener href="about:blank">link</a>');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue