Skip to content

fix(webapi): see attributes on elements #4147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,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 @@ -1825,6 +1825,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 @@ -1612,6 +1612,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