Skip to content

Commit c2ca7e6

Browse files
authored
fix: waitNumberOfVisibleElements always failed when passing num as 0 (#4274)
1 parent b1f94cc commit c2ca7e6

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

lib/helper/Playwright.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2472,7 +2472,7 @@ class Playwright extends Helper {
24722472
async waitNumberOfVisibleElements(locator, num, sec) {
24732473
const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
24742474
locator = new Locator(locator, 'css');
2475-
await this.context;
2475+
24762476
let waiter;
24772477
const context = await this._getContext();
24782478
if (locator.isCSS()) {

lib/helper/Puppeteer.js

-1
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,6 @@ class Puppeteer extends Helper {
20902090
async waitNumberOfVisibleElements(locator, num, sec) {
20912091
const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout;
20922092
locator = new Locator(locator, 'css');
2093-
await this.context;
20942093
let waiter;
20952094
const context = await this._getContext();
20962095
if (locator.isCSS()) {

test/helper/Playwright_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ describe('Playwright', function () {
249249
.then(() => I.waitNumberOfVisibleElements('.title', 2, 3))
250250
.then(() => I.see('Hello'))
251251
.then(() => I.see('World')));
252+
253+
it('should wait for 0 number of visible elements', async () => {
254+
await I.amOnPage('/form/wait_invisible');
255+
await I.waitNumberOfVisibleElements('#step_1', 0);
256+
});
252257
});
253258

254259
describe('#moveCursorTo', () => {

test/helper/Puppeteer_test.js

+12-8
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,14 @@ describe('Puppeteer', function () {
193193
});
194194

195195
describe('#waitNumberOfVisibleElements', () => {
196-
it('should wait for a specified number of elements on the page', () => I.amOnPage('/info')
197-
.then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 3))
198-
.then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 2, 0.1))
199-
.then(() => {
200-
throw Error('It should never get this far');
201-
})
202-
.catch((e) => {
196+
it('should wait for a specified number of elements on the page', async () => {
197+
try {
198+
await I.amOnPage('/info');
199+
await I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 3);
200+
} catch (e) {
203201
e.message.should.include('The number of elements (//div[@id = "grab-multiple"]//a) is not 2 after 0.1 sec');
204-
}));
202+
}
203+
});
205204

206205
it('should wait for a specified number of elements on the page using a css selector', () => I.amOnPage('/info')
207206
.then(() => I.waitNumberOfVisibleElements('#grab-multiple > a', 3))
@@ -217,6 +216,11 @@ describe('Puppeteer', function () {
217216
.then(() => I.waitNumberOfVisibleElements('.title', 2, 3))
218217
.then(() => I.see('Hello'))
219218
.then(() => I.see('World')));
219+
220+
it('should wait for 0 number of visible elements', async () => {
221+
await I.amOnPage('/form/wait_invisible');
222+
await I.waitNumberOfVisibleElements('#step_1', 0);
223+
});
220224
});
221225

222226
describe('#moveCursorTo', () => {

test/helper/WebDriver_devtools_test.js

+5
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,11 @@ describe('WebDriver - Devtools Protocol', function () {
532532
.then(() => wd.see('Hello'))
533533
.then(() => wd.see('World'));
534534
});
535+
536+
it('should wait for 0 number of visible elements', async () => {
537+
await wd.amOnPage('/form/wait_invisible');
538+
await wd.waitNumberOfVisibleElements('#step_1', 0);
539+
});
535540
});
536541

537542
describe('#waitForVisible', () => {

0 commit comments

Comments
 (0)