mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
40
test/test.js
40
test/test.js
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user