Skip to content

Commit 9abf4ad

Browse files
authored
fix(webapi): see attributes on elements (#4147)
1 parent 0bcb3d2 commit 9abf4ad

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

lib/helper/Playwright.js

+2
Original file line numberDiff line numberDiff line change
@@ -2188,6 +2188,8 @@ class Playwright extends Helper {
21882188
let chunked = chunkArray(attrs, values.length);
21892189
chunked = chunked.filter((val) => {
21902190
for (let i = 0; i < val.length; ++i) {
2191+
// the attribute could be a boolean
2192+
if (typeof val[i] === 'boolean') return val[i] === values[i];
21912193
// if the attribute doesn't exist, returns false as well
21922194
if (!val[i] || !val[i].includes(values[i])) return false;
21932195
}

lib/helper/Puppeteer.js

+2
Original file line numberDiff line numberDiff line change
@@ -1842,6 +1842,8 @@ class Puppeteer extends Helper {
18421842
for (let i = 0; i < val.length; ++i) {
18431843
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(values[i], 10);
18441844
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
1845+
// the attribute could be a boolean
1846+
if (typeof _actual === 'boolean') return _actual === _expected;
18451847
// if the attribute doesn't exist, returns false as well
18461848
if (!_actual || !_actual.includes(_expected)) return false;
18471849
}

lib/helper/WebDriver.js

+2
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,8 @@ class WebDriver extends Helper {
16311631
for (let i = 0; i < val.length; ++i) {
16321632
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
16331633
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
1634+
// the attribute could be a boolean
1635+
if (typeof _actual === 'boolean') return _actual === _expected;
16341636
if (_actual !== _expected) return false;
16351637
}
16361638
return true;

test/data/app/view/index.php

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
<a href="/spinner" qa-id = "test" qa-link = "test">Spinner</a>
2626
</div>
2727

28+
<div id="area5" qa-id = "test">
29+
<input qa-id = "test" qa-link = "test" disabled>Hidden input</a>
30+
</div>
31+
2832
A wise man said: "debug!"
2933

3034
<?php print_r($_POST); ?>

test/helper/webapi.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -1319,8 +1319,8 @@ module.exports.tests = function () {
13191319
});
13201320

13211321
describe('#seeAttributesOnElements', () => {
1322-
it.skip('should check attributes values for given element', async function () {
1323-
if (isHelper('TestCafe')) this.skip();
1322+
it('should check attributes values for given element', async function () {
1323+
if (isHelper('TestCafe') || isHelper('WebDriver')) this.skip();
13241324

13251325
try {
13261326
await I.amOnPage('/info');
@@ -1387,6 +1387,19 @@ module.exports.tests = function () {
13871387
e.message.should.include('expected all elements ({css: a[href="/team"]}) to have attributes {"disable":true} "0" to equal "1"');
13881388
}
13891389
});
1390+
1391+
it('should verify the boolean attribute', async function () {
1392+
if (isHelper('TestCafe') || isHelper('WebDriver')) this.skip();
1393+
1394+
try {
1395+
await I.amOnPage('/');
1396+
await I.seeAttributesOnElements('input', {
1397+
disabled: true,
1398+
});
1399+
} catch (e) {
1400+
e.message.should.include('expected all elements (input) to have attributes {"disabled":true} "0" to equal "1"');
1401+
}
1402+
});
13901403
});
13911404

13921405
describe('#seeCssPropertiesOnElements', () => {

0 commit comments

Comments
 (0)