Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
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