diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index 15f2aab0a..b2aeb9d15 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -2472,7 +2472,7 @@ class Playwright extends Helper { async waitNumberOfVisibleElements(locator, num, sec) { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout; locator = new Locator(locator, 'css'); - await this.context; + let waiter; const context = await this._getContext(); if (locator.isCSS()) { diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index 8ee9e0561..2bb8edac8 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -2090,7 +2090,6 @@ class Puppeteer extends Helper { async waitNumberOfVisibleElements(locator, num, sec) { const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout; locator = new Locator(locator, 'css'); - await this.context; let waiter; const context = await this._getContext(); if (locator.isCSS()) { diff --git a/test/helper/Playwright_test.js b/test/helper/Playwright_test.js index f2680b9b8..ce33e210d 100644 --- a/test/helper/Playwright_test.js +++ b/test/helper/Playwright_test.js @@ -249,6 +249,11 @@ describe('Playwright', function () { .then(() => I.waitNumberOfVisibleElements('.title', 2, 3)) .then(() => I.see('Hello')) .then(() => I.see('World'))); + + it('should wait for 0 number of visible elements', async () => { + await I.amOnPage('/form/wait_invisible'); + await I.waitNumberOfVisibleElements('#step_1', 0); + }); }); describe('#moveCursorTo', () => { diff --git a/test/helper/Puppeteer_test.js b/test/helper/Puppeteer_test.js index c23e906dc..a22187e7f 100644 --- a/test/helper/Puppeteer_test.js +++ b/test/helper/Puppeteer_test.js @@ -193,15 +193,14 @@ describe('Puppeteer', function () { }); describe('#waitNumberOfVisibleElements', () => { - it('should wait for a specified number of elements on the page', () => I.amOnPage('/info') - .then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 3)) - .then(() => I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 2, 0.1)) - .then(() => { - throw Error('It should never get this far'); - }) - .catch((e) => { + it('should wait for a specified number of elements on the page', async () => { + try { + await I.amOnPage('/info'); + await I.waitNumberOfVisibleElements('//div[@id = "grab-multiple"]//a', 3); + } catch (e) { e.message.should.include('The number of elements (//div[@id = "grab-multiple"]//a) is not 2 after 0.1 sec'); - })); + } + }); it('should wait for a specified number of elements on the page using a css selector', () => I.amOnPage('/info') .then(() => I.waitNumberOfVisibleElements('#grab-multiple > a', 3)) @@ -217,6 +216,11 @@ describe('Puppeteer', function () { .then(() => I.waitNumberOfVisibleElements('.title', 2, 3)) .then(() => I.see('Hello')) .then(() => I.see('World'))); + + it('should wait for 0 number of visible elements', async () => { + await I.amOnPage('/form/wait_invisible'); + await I.waitNumberOfVisibleElements('#step_1', 0); + }); }); describe('#moveCursorTo', () => { diff --git a/test/helper/WebDriver_devtools_test.js b/test/helper/WebDriver_devtools_test.js index b0b4329bb..92298f406 100644 --- a/test/helper/WebDriver_devtools_test.js +++ b/test/helper/WebDriver_devtools_test.js @@ -532,6 +532,11 @@ describe('WebDriver - Devtools Protocol', function () { .then(() => wd.see('Hello')) .then(() => wd.see('World')); }); + + it('should wait for 0 number of visible elements', async () => { + await wd.amOnPage('/form/wait_invisible'); + await wd.waitNumberOfVisibleElements('#step_1', 0); + }); }); describe('#waitForVisible', () => {