Skip to content

Commit 1fb146c

Browse files
hatufaccikobenguyent
authored andcommitted
fix 3968
1 parent 2bc2a8b commit 1fb146c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

lib/helper/Playwright.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,33 @@ class Playwright extends Helper {
993993
await el.blur(options);
994994
return this._waitForAction();
995995
}
996+
/**
997+
* {{> isElementChecked }}
998+
* @param {object} See https://playwright.dev/docs/api/class-locator#locator-is-checked
999+
* @return {Promise<boolean>}
1000+
*
1001+
*/
1002+
1003+
async isElementChecked(locator, options = {}) {
1004+
const el = await this._locateElement(locator);
1005+
const type = await el.getAttribute('type');
1006+
1007+
if (type === 'checkbox' || type === 'radio') {
1008+
return el.isChecked(options);
1009+
}
1010+
throw new Error('Element is not a checkbox or radio input');
1011+
}
1012+
/**
1013+
* {{> isElementDisabled }}
1014+
* @param {object} See https://playwright.dev/docs/api/class-locator#locator-is-disabled
1015+
* @return {Promise<boolean>}
1016+
*
1017+
*/
1018+
1019+
async isElementDisabled(locator, options = {}) {
1020+
const el = await this._locateElement(locator);
1021+
return el.isDisabled(options);
1022+
}
9961023

9971024
/**
9981025
* {{> dragAndDrop }}

test/data/app/view/invisible_elements.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,18 @@
77
<button style="display:none;">Hello World</button>
88
<button>Hello World</button>
99
<button style="display:none;">Hello World</button>
10+
<input type="radio" id="html" name="fav_language" value="HTML" checked>
11+
<label for="html">HTML</label><br>
12+
<input type="radio" id="css" name="fav_language" value="CSS">
13+
<label for="css">CSS</label><br>
14+
<input type="checkbox" id="js" name="fav_language" value="JS" checked>
15+
<label for="js">JS</label><br>
16+
<input type="checkbox" id="ts" name="fav_language" value="TS">
17+
<label for="ts">TS</label><br>
18+
<input id="basic" name="fav_language" value="Basic">
19+
<label for="basic">Basic</label><br>
20+
<input type="checkbox" id="fortran" name="fav_language" value="Fortran" disabled>
21+
<label for="fortran">Fortran</label><br>
1022
</body>
1123
</html>
24+

test/helper/Playwright_test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ describe('Playwright', function () {
117117
await I.click('Hello World');
118118
});
119119
});
120+
it('check isElementChecked', async () => {
121+
await I.amOnPage('/invisible_elements');
122+
let result = await I.isElementChecked({ id: 'html' });
123+
assert.equal(result, true);
124+
result = await I.isElementChecked({ id: 'css' });
125+
assert.equal(result, false);
126+
result = await I.isElementChecked({ id: 'js' });
127+
assert.equal(result, true);
128+
result = await I.isElementChecked({ id: 'ts' });
129+
assert.equal(result, false);
130+
try {
131+
result = await I.isElementChecked({ id: 'basic' });
132+
} catch (e) {
133+
assert.equal(e.message, 'Element is not a checkbox or radio input');
134+
}
135+
});
136+
describe('#isElementDisabled', () => {
137+
it('check isElementDisabled', async () => {
138+
await I.amOnPage('/invisible_elements');
139+
let result = await I.isElementDisabled({ id: 'fortran' });
140+
assert.equal(result, true);
141+
result = await I.isElementDisabled({ id: 'basic' });
142+
assert.equal(result, false);
143+
});
144+
});
120145

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

0 commit comments

Comments
 (0)