Skip to content

Commit

Permalink
fix: seeattributesonelements throws error (#4073)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Dec 20, 2023
1 parent 6c57921 commit 51f7eb2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2168,7 +2168,8 @@ class Playwright extends Helper {
let chunked = chunkArray(attrs, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
if (!val[i].includes(values[i])) return false;
// if the attribute doesn't exist, returns false as well
if (!val[i] || !val[i].includes(values[i])) return false;
}
return true;
});
Expand Down
3 changes: 2 additions & 1 deletion lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,8 @@ class Puppeteer extends Helper {
for (let i = 0; i < val.length; ++i) {
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(values[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
if (!_actual.includes(_expected)) return false;
// if the attribute doesn't exist, returns false as well
if (!_actual || !_actual.includes(_expected)) return false;
}
return true;
});
Expand Down
13 changes: 13 additions & 0 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,19 @@ module.exports.tests = function () {
e.message.should.include('all elements (a) to have attributes {"qa-id":"test","href":"/info"}');
}
});

it('should return error when using non existing attribute', async function () {
if (isHelper('TestCafe') || isHelper('WebDriver')) this.skip();

try {
await I.amOnPage('https://github.com/codeceptjs/CodeceptJS/');
await I.seeAttributesOnElements({ css: 'a[href="/team"]' }, {
disable: true,
});
} catch (e) {
e.message.should.include('expected all elements ({css: a[href="/team"]}) to have attributes {"disable":true} "0" to equal "1"');
}
});
});

describe('#seeCssPropertiesOnElements', () => {
Expand Down

0 comments on commit 51f7eb2

Please sign in to comment.