diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index a1e4204a1..4a7d0a08a 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -1738,8 +1738,15 @@ class Playwright extends Helper { const el = els[0]; await highlightActiveElement.call(this, el); + let optionToSelect = ''; - if (!Array.isArray(option)) option = [option]; + try { + optionToSelect = await el.locator('option', { hasText: option }).textContent(); + } catch (e) { + optionToSelect = option; + } + + if (!Array.isArray(option)) option = [optionToSelect]; await el.selectOption(option); return this._waitForAction(); diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index f435fc852..9b1dee520 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -15,6 +15,9 @@ const { deleteDir } = require('../../lib/utils'); const Secret = require('../../lib/secret'); global.codeceptjs = require('../../lib'); +const dataFile = path.join(__dirname, '/../data/app/db'); +const formContents = require('../../lib/utils').test.submittedData(dataFile); + let I; let page; let FS; @@ -438,6 +441,15 @@ describe('Playwright', function () { })); }); + describe('#selectOption', () => { + it('should select option by label and partial option text', async () => { + await I.amOnPage('/form/select'); + await I.selectOption('Select your age', '21-'); + await I.click('Submit'); + assert.equal(formContents('age'), 'adult'); + }); + }); + describe('#_locateClickable', () => { it('should locate a button to click', () => I.amOnPage('/form/checkbox') .then(() => I._locateClickable('Submit'))