Skip to content

Commit 51f7eb2

Browse files
authored
fix: seeattributesonelements throws error (#4073)
1 parent 6c57921 commit 51f7eb2

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/helper/Playwright.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,8 @@ class Playwright extends Helper {
21682168
let chunked = chunkArray(attrs, values.length);
21692169
chunked = chunked.filter((val) => {
21702170
for (let i = 0; i < val.length; ++i) {
2171-
if (!val[i].includes(values[i])) return false;
2171+
// if the attribute doesn't exist, returns false as well
2172+
if (!val[i] || !val[i].includes(values[i])) return false;
21722173
}
21732174
return true;
21742175
});

lib/helper/Puppeteer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,8 @@ class Puppeteer extends Helper {
18231823
for (let i = 0; i < val.length; ++i) {
18241824
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(values[i], 10);
18251825
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
1826-
if (!_actual.includes(_expected)) return false;
1826+
// if the attribute doesn't exist, returns false as well
1827+
if (!_actual || !_actual.includes(_expected)) return false;
18271828
}
18281829
return true;
18291830
});

test/helper/webapi.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,19 @@ module.exports.tests = function () {
13741374
e.message.should.include('all elements (a) to have attributes {"qa-id":"test","href":"/info"}');
13751375
}
13761376
});
1377+
1378+
it('should return error when using non existing attribute', async function () {
1379+
if (isHelper('TestCafe') || isHelper('WebDriver')) this.skip();
1380+
1381+
try {
1382+
await I.amOnPage('https://github.com/codeceptjs/CodeceptJS/');
1383+
await I.seeAttributesOnElements({ css: 'a[href="/team"]' }, {
1384+
disable: true,
1385+
});
1386+
} catch (e) {
1387+
e.message.should.include('expected all elements ({css: a[href="/team"]}) to have attributes {"disable":true} "0" to equal "1"');
1388+
}
1389+
});
13771390
});
13781391

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

0 commit comments

Comments
 (0)