Skip to content

Commit ff81e2a

Browse files
authored
improvement(playwright): support partial string for option (#4016)
1 parent 6f0062f commit ff81e2a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/helper/Playwright.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,8 +1765,15 @@ class Playwright extends Helper {
17651765
const el = els[0];
17661766

17671767
await highlightActiveElement.call(this, el);
1768+
let optionToSelect = '';
17681769

1769-
if (!Array.isArray(option)) option = [option];
1770+
try {
1771+
optionToSelect = await el.locator('option', { hasText: option }).textContent();
1772+
} catch (e) {
1773+
optionToSelect = option;
1774+
}
1775+
1776+
if (!Array.isArray(option)) option = [optionToSelect];
17701777

17711778
await el.selectOption(option);
17721779
return this._waitForAction();

test/helper/Playwright_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const { deleteDir } = require('../../lib/utils');
1515
const Secret = require('../../lib/secret');
1616
global.codeceptjs = require('../../lib');
1717

18+
const dataFile = path.join(__dirname, '/../data/app/db');
19+
const formContents = require('../../lib/utils').test.submittedData(dataFile);
20+
1821
let I;
1922
let page;
2023
let FS;
@@ -438,6 +441,15 @@ describe('Playwright', function () {
438441
}));
439442
});
440443

444+
describe('#selectOption', () => {
445+
it('should select option by label and partial option text', async () => {
446+
await I.amOnPage('/form/select');
447+
await I.selectOption('Select your age', '21-');
448+
await I.click('Submit');
449+
assert.equal(formContents('age'), 'adult');
450+
});
451+
});
452+
441453
describe('#_locateClickable', () => {
442454
it('should locate a button to click', () => I.amOnPage('/form/checkbox')
443455
.then(() => I._locateClickable('Submit'))

0 commit comments

Comments
 (0)