Test the 'networkidle' navigation logic

This patch adds a test to verify that navigation properly waits for the
network to become idle.

References #10
This commit is contained in:
Andrey Lushnikov
2017-06-27 22:02:46 -07:00
committed by GitHub
parent d5a91650ae
commit 5ed71fcb8f
4 changed files with 106 additions and 0 deletions

View File

@@ -43,6 +43,7 @@ describe('Puppeteer', function() {
beforeEach(SX(async function() {
page = await browser.newPage();
staticServer.reset();
GoldenUtils.addMatchers(jasmine);
}));
@@ -112,6 +113,45 @@ describe('Puppeteer', function() {
let success = await page.navigate(EMPTY_PAGE);
expect(success).toBe(true);
}));
it('should wait for network idle to succeed navigation', SX(async function() {
let responses = [];
// Hold on a bunch of requests without answering.
staticServer.setRoute('/fetch-request-a.js', (req, res) => responses.push(res));
staticServer.setRoute('/fetch-request-b.js', (req, res) => responses.push(res));
staticServer.setRoute('/fetch-request-c.js', (req, res) => responses.push(res));
let fetchResourcesRequested = Promise.all([
staticServer.waitForRequest('/fetch-request-a.js'),
staticServer.waitForRequest('/fetch-request-b.js'),
staticServer.waitForRequest('/fetch-request-c.js'),
]);
// Navigate to a page which loads immediately and then does a bunch of
// requests via javascript's fetch method.
let navigationPromise = page.navigate(STATIC_PREFIX + '/networkidle.html', {
minTime: 50 // Give page time to request more resources dynamically.
});
// Track when the navigation gets completed.
let navigationFinished = false;
navigationPromise.then(() => navigationFinished = true);
// Wait for the page's 'load' event.
await new Promise(fulfill => page.once('load', fulfill));
expect(navigationFinished).toBe(false);
// Wait for all three resources to be requested.
await fetchResourcesRequested;
// Expect navigation still to be not finished.
expect(navigationFinished).toBe(false);
// Respond to all requests.
for (let response of responses) {
response.statusCode = 404;
response.end(`File not found`);
}
let success = await navigationPromise;
// Expect navigation to succeed.
expect(success).toBe(true);
}));
});
describe('Page.setInPageCallback', function() {