MOBILE-4270 behat: Select option values by text

main
Noel De Martin 2023-03-16 10:57:35 +01:00
parent a8e7e61e1e
commit 0e6eaeee46
1 changed files with 12 additions and 3 deletions

View File

@ -422,13 +422,22 @@ export class TestingBehatRuntimeService {
async setField(field: string, value: string): Promise<string> { async setField(field: string, value: string): Promise<string> {
this.log('Action - Set field ' + field + ' to: ' + value); this.log('Action - Set field ' + field + ' to: ' + value);
const found = TestingBehatDomUtils.findField(field); const input = TestingBehatDomUtils.findField(field);
if (!found) { if (!input) {
return 'ERROR: No element matches field to set.'; return 'ERROR: No element matches field to set.';
} }
await TestingBehatDomUtils.setElementValue(found, value); if (input instanceof HTMLSelectElement) {
const options = Array.from(input.querySelectorAll('option'));
value = options.find(option => option.value === value)?.value
?? options.find(option => option.text === value)?.value
?? options.find(option => option.text.includes(value))?.value
?? value;
}
await TestingBehatDomUtils.setElementValue(input, value);
return 'OK'; return 'OK';
} }