Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(playwright): support partial string for option #4016

Merged
merged 2 commits into from
Nov 29, 2023
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