From 7048a94a20eaf0853dfb86fb034630f30d60659f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Tue, 12 Jun 2018 23:07:26 +0200 Subject: [PATCH] wait for page load, close #95 --- CHANGELOG.md | 1 + README.md | 5 ++++- lib/mixins/browser_navigation.js | 10 ++++++++++ tests/browser/navigation_load.test.js | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a385cfc9..db30ec0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Request filter and assertion by postBody * RequestMock object with assertion + * Browser.waitForPageLoad * Mocks cleared on close * BeforeClose hook in components * ClearRequestMocks on open option diff --git a/README.md b/README.md index bcaebf21..6ca043c9 100644 --- a/README.md +++ b/README.md @@ -405,6 +405,9 @@ await browser.setViewport({width: 300}); > Unlike Puppeteer setViewport, no parameter is required, as the current values will be used for the new viewport. +**waitForPageLoad()** +Waits until a dom ready event is fired, this method will also wait until Wendigo is ready to perform assertions on the given page. + **focus(selector)** Focus the first element matching the given selector. @@ -989,7 +992,7 @@ browser.requests.assert.responseHeaders({ Asserts that an successful response was received (status is between 200 and 299), or false if false is given. -**postBody(expected, msg?)** +**postBody(expected, msg?)** Asserts that a request contains the given post body (regardless of method). The expected value can be a string, regex or object. ```js diff --git a/lib/mixins/browser_navigation.js b/lib/mixins/browser_navigation.js index 913423a8..377ed039 100644 --- a/lib/mixins/browser_navigation.js +++ b/lib/mixins/browser_navigation.js @@ -27,5 +27,15 @@ module.exports = function BrowserNavigationMixin(s) { config = Object.assign({}, this.page.viewport(), config); return this.page.setViewport(config); } + + waitForPageLoad() { + return this.page.waitForNavigation({ + waitUntil: "domcontentloaded" + }).then(() => { + return this.page.waitFor(() => { + return Boolean(window.WendigoUtils); // Waits until wendigo utils is ready + }); + }); + } }; }; diff --git a/tests/browser/navigation_load.test.js b/tests/browser/navigation_load.test.js index 0c1d8375..d4259e41 100644 --- a/tests/browser/navigation_load.test.js +++ b/tests/browser/navigation_load.test.js @@ -30,4 +30,12 @@ describe("Wait For", function() { await browser.assert.text("p", "html_test"); // Requires WendigoUtils }); + it("Wait For Page Load", async () => { + await browser.open(configUrls.index); + await browser.click("a"); + await browser.waitForPageLoad(); + await browser.assert.global("WendigoUtils"); + await browser.assert.text("p", "html_test"); + }); + });