From 0e6eaeee4622b5d455e8b5c2c16821feb32738aa Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Thu, 16 Mar 2023 10:57:35 +0100 Subject: [PATCH] MOBILE-4270 behat: Select option values by text --- src/testing/services/behat-runtime.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/testing/services/behat-runtime.ts b/src/testing/services/behat-runtime.ts index 46e47c906..e9cb4f2e4 100644 --- a/src/testing/services/behat-runtime.ts +++ b/src/testing/services/behat-runtime.ts @@ -422,13 +422,22 @@ export class TestingBehatRuntimeService { async setField(field: string, value: string): Promise { 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.'; } - 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'; }