From 6ca7798242af44b2842426b52b04d7cccd681d44 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 22 Nov 2023 12:53:19 +0100 Subject: [PATCH 1/2] improvement(playwright): support partial string for option --- lib/helper/Playwright.js | 9 ++++++++- test/helper/Playwright_test.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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..9a0f3bdda 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.only('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')) From ab3be431c2240c9a929cc381d0dc094af25cc8b0 Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Wed, 22 Nov 2023 12:58:21 +0100 Subject: [PATCH 2/2] remove .only --- test/helper/Playwright_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index 9a0f3bdda..9b1dee520 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -442,7 +442,7 @@ describe('Playwright', function () { }); describe('#selectOption', () => { - it.only('should select option by label and partial option text', async () => { + 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');