Skip to content

fix 3968 #3969

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

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 27 additions & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,33 @@ class Playwright extends Helper {
await el.blur(options);
return this._waitForAction();
}
/**
* {{> isElementChecked }}
* @param {object} See https://playwright.dev/docs/api/class-locator#locator-is-checked
* @return {Promise<boolean>}
*
*/

async isElementChecked(locator, options = {}) {
const el = await this._locateElement(locator);
const type = await el.getAttribute('type');

if (type === 'checkbox' || type === 'radio') {
return el.isChecked(options);
}
throw new Error('Element is not a checkbox or radio input');
}
/**
* {{> isElementDisabled }}
* @param {object} See https://playwright.dev/docs/api/class-locator#locator-is-disabled
* @return {Promise<boolean>}
*
*/

async isElementDisabled(locator, options = {}) {
const el = await this._locateElement(locator);
return el.isDisabled(options);
}

/**
* {{> dragAndDrop }}
Expand Down
13 changes: 13 additions & 0 deletions test/data/app/view/invisible_elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,18 @@
<button style="display:none;">Hello World</button>
<button>Hello World</button>
<button style="display:none;">Hello World</button>
<input type="radio" id="html" name="fav_language" value="HTML" checked>
<label for="html">HTML</label><br>
<input type="radio" id="css" name="fav_language" value="CSS">
<label for="css">CSS</label><br>
<input type="checkbox" id="js" name="fav_language" value="JS" checked>
<label for="js">JS</label><br>
<input type="checkbox" id="ts" name="fav_language" value="TS">
<label for="ts">TS</label><br>
<input id="basic" name="fav_language" value="Basic">
<label for="basic">Basic</label><br>
<input type="checkbox" id="fortran" name="fav_language" value="Fortran" disabled>
<label for="fortran">Fortran</label><br>
</body>
</html>

25 changes: 25 additions & 0 deletions test/helper/Playwright_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ describe('Playwright', function () {
await I.click('Hello World');
});
});
it('check isElementChecked', async () => {
await I.amOnPage('/invisible_elements');
let result = await I.isElementChecked({ id: 'html' });
assert.equal(result, true);
result = await I.isElementChecked({ id: 'css' });
assert.equal(result, false);
result = await I.isElementChecked({ id: 'js' });
assert.equal(result, true);
result = await I.isElementChecked({ id: 'ts' });
assert.equal(result, false);
try {
result = await I.isElementChecked({ id: 'basic' });
} catch (e) {
assert.equal(e.message, 'Element is not a checkbox or radio input');
}
});
describe('#isElementDisabled', () => {
it('check isElementDisabled', async () => {
await I.amOnPage('/invisible_elements');
let result = await I.isElementDisabled({ id: 'fortran' });
assert.equal(result, true);
result = await I.isElementDisabled({ id: 'basic' });
assert.equal(result, false);
});
});

describe('#waitForFunction', () => {
it('should wait for function returns true', () => {
Expand Down