Skip to content

Commit

Permalink
fix(webapi): see attributes on elements (#4147)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent committed Jan 23, 2024
1 parent 0bcb3d2 commit 9abf4ad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,8 @@ class Playwright extends Helper {
let chunked = chunkArray(attrs, values.length);
chunked = chunked.filter((val) => {
for (let i = 0; i < val.length; ++i) {
// the attribute could be a boolean
if (typeof val[i] === 'boolean') return val[i] === values[i];
// if the attribute doesn't exist, returns false as well
if (!val[i] || !val[i].includes(values[i])) return false;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,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);
// the attribute could be a boolean
if (typeof _actual === 'boolean') return _actual === _expected;
// if the attribute doesn't exist, returns false as well
if (!_actual || !_actual.includes(_expected)) return false;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,8 @@ class WebDriver extends Helper {
for (let i = 0; i < val.length; ++i) {
const _actual = Number.isNaN(val[i]) || (typeof values[i]) === 'string' ? val[i] : Number.parseInt(val[i], 10);
const _expected = Number.isNaN(values[i]) || (typeof values[i]) === 'string' ? values[i] : Number.parseInt(values[i], 10);
// the attribute could be a boolean
if (typeof _actual === 'boolean') return _actual === _expected;
if (_actual !== _expected) return false;
}
return true;
Expand Down
4 changes: 4 additions & 0 deletions test/data/app/view/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<a href="/spinner" qa-id = "test" qa-link = "test">Spinner</a>
</div>

<div id="area5" qa-id = "test">
<input qa-id = "test" qa-link = "test" disabled>Hidden input</a>
</div>

A wise man said: "debug!"

<?php print_r($_POST); ?>
Expand Down
17 changes: 15 additions & 2 deletions test/helper/webapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1319,8 +1319,8 @@ module.exports.tests = function () {
});

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

try {
await I.amOnPage('/info');
Expand Down Expand Up @@ -1387,6 +1387,19 @@ module.exports.tests = function () {
e.message.should.include('expected all elements ({css: a[href="/team"]}) to have attributes {"disable":true} "0" to equal "1"');
}
});

it('should verify the boolean attribute', async function () {
if (isHelper('TestCafe') || isHelper('WebDriver')) this.skip();

try {
await I.amOnPage('/');
await I.seeAttributesOnElements('input', {
disabled: true,
});
} catch (e) {
e.message.should.include('expected all elements (input) to have attributes {"disabled":true} "0" to equal "1"');
}
});
});

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

0 comments on commit 9abf4ad

Please sign in to comment.