test: fix flaky test (#2650)

When launching browser with a default URL, the page is not necessarily
loaded when we're reaching into it.
This commit is contained in:
Andrey Lushnikov 2018-05-31 16:39:49 -07:00 committed by GitHub
parent 0ba72df67d
commit 1c0ecc3d9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -282,8 +282,11 @@ module.exports.addTests = function({testRunner, expect, PROJECT_ROOT, defaultBro
const options = Object.assign({}, defaultBrowserOptions); const options = Object.assign({}, defaultBrowserOptions);
options.args = [customUrl].concat(options.args); options.args = [customUrl].concat(options.args);
const browser = await puppeteer.launch(options); const browser = await puppeteer.launch(options);
const pages = (await browser.pages()).map(page => page.url()); const pages = await browser.pages();
expect(pages).toEqual([customUrl]); expect(pages.length).toBe(1);
if (pages[0].url() !== customUrl)
await pages[0].waitForNavigation();
expect(pages[0].url()).toBe(customUrl);
await browser.close(); await browser.close();
}); });
}); });