From 433b485d60667c606996cb3d9257b248a17d8f3a Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 3 Feb 2020 23:43:19 +0300 Subject: [PATCH 1/3] fix(Puppeteer): #waitForText - Cannot read property 'innerText' of null --- lib/helper/Puppeteer.js | 2 +- test/data/app/controllers.php | 6 ++++++ test/data/app/index.php | 1 + test/data/app/view/redirect_long.php | 17 +++++++++++++++++ test/helper/Puppeteer_test.js | 6 ++++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/data/app/view/redirect_long.php diff --git a/lib/helper/Puppeteer.js b/lib/helper/Puppeteer.js index c7feb452d..0c9e93e0e 100644 --- a/lib/helper/Puppeteer.js +++ b/lib/helper/Puppeteer.js @@ -1898,7 +1898,7 @@ class Puppeteer extends Helper { }, { timeout: waitTimeout }, locator.value, text, $XPath.toString()); } } else { - waiter = contextObject.waitForFunction(text => document.body.innerText.indexOf(text) > -1, { timeout: waitTimeout }, text); + waiter = contextObject.waitForFunction(text => document.body && document.body.innerText.indexOf(text) > -1, { timeout: waitTimeout }, text); } return waiter.catch((err) => { diff --git a/test/data/app/controllers.php b/test/data/app/controllers.php index 1ef696c7d..f41b8afa2 100755 --- a/test/data/app/controllers.php +++ b/test/data/app/controllers.php @@ -24,6 +24,12 @@ function GET() { } } +class redirect_long { + function GET() { + include __DIR__.'/view/redirect_long.php'; + } +} + class redirect4 { function GET() { header('Location: /search?ln=test@gmail.com&sn=testnumber'); diff --git a/test/data/app/index.php b/test/data/app/index.php index f21251dab..cb53b6604 100755 --- a/test/data/app/index.php +++ b/test/data/app/index.php @@ -15,6 +15,7 @@ '/redirect' => 'redirect', '/redirect2' => 'redirect2', '/redirect3' => 'redirect3', + '/redirect_long' => 'redirect_long', '/redirect4' => 'redirect4', '/redirect_params' => 'redirect_params', '/redirect_interval' => 'redirect_interval', diff --git a/test/data/app/view/redirect_long.php b/test/data/app/view/redirect_long.php new file mode 100644 index 000000000..a744f04d1 --- /dev/null +++ b/test/data/app/view/redirect_long.php @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/test/helper/Puppeteer_test.js b/test/helper/Puppeteer_test.js index fc150d1d9..ec92e49d1 100644 --- a/test/helper/Puppeteer_test.js +++ b/test/helper/Puppeteer_test.js @@ -649,6 +649,12 @@ describe('Puppeteer', function () { .then(() => I.see('button was clicked', '#message'))); }); + describe('#waitForText', () => { + it('should wait for text after load body', () => I.amOnPage('/redirect_long') + .then(() => I.waitForText('Hi there and greetings!', 5)) + ); + }) + describe('#waitForValue', () => { it('should wait for expected value for given locator', () => I.amOnPage('/info') .then(() => I.waitForValue('//input[@name= "rus"]', 'Верно')) From 08f472190aeefff5b0e2c27a12b229e4b12ad2d1 Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Mon, 3 Feb 2020 23:46:56 +0300 Subject: [PATCH 2/3] fix comment --- test/helper/Puppeteer_test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/helper/Puppeteer_test.js b/test/helper/Puppeteer_test.js index ec92e49d1..0e3f15d01 100644 --- a/test/helper/Puppeteer_test.js +++ b/test/helper/Puppeteer_test.js @@ -651,9 +651,8 @@ describe('Puppeteer', function () { describe('#waitForText', () => { it('should wait for text after load body', () => I.amOnPage('/redirect_long') - .then(() => I.waitForText('Hi there and greetings!', 5)) - ); - }) + .then(() => I.waitForText('Hi there and greetings!', 5))); + }); describe('#waitForValue', () => { it('should wait for expected value for given locator', () => I.amOnPage('/info') From 9c3856a07c14e040d189abe0a26da27a56c56e84 Mon Sep 17 00:00:00 2001 From: Vorobeyko Date: Sun, 9 Feb 2020 19:46:44 +0300 Subject: [PATCH 3/3] fix comments --- test/helper/Puppeteer_test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/helper/Puppeteer_test.js b/test/helper/Puppeteer_test.js index 0e3f15d01..9313e2d8c 100644 --- a/test/helper/Puppeteer_test.js +++ b/test/helper/Puppeteer_test.js @@ -650,8 +650,10 @@ describe('Puppeteer', function () { }); describe('#waitForText', () => { - it('should wait for text after load body', () => I.amOnPage('/redirect_long') - .then(() => I.waitForText('Hi there and greetings!', 5))); + it('should wait for text after load body', async () => { + await I.amOnPage('/redirect_long'); + await I.waitForText('Hi there and greetings!', 5); + }); }); describe('#waitForValue', () => {