Skip to content

Commit

Permalink
improvement(playwright): support partial string for option (#4016)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Nov 29, 2023
1 parent 6f0062f commit ff81e2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,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();
Expand Down
12 changes: 12 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit ff81e2a

Please sign in to comment.