test: fix random tests flakiness (#2770)

These tests were not awaiting `page.evaluate` command, so
page could have been closed before the command returned.
This commit is contained in:
Andrey Lushnikov 2018-06-19 10:35:13 -07:00 committed by GitHub
parent f197d2e208
commit 37dbfc2608
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -53,8 +53,10 @@ module.exports.addTests = function({testRunner, expect, puppeteer}) {
const context = await browser.createIncognitoBrowserContext();
const page = await context.newPage();
await page.goto(server.EMPTY_PAGE);
page.evaluate(url => window.open(url), server.EMPTY_PAGE);
const popupTarget = await utils.waitEvent(browser, 'targetcreated');
const [popupTarget] = await Promise.all([
utils.waitEvent(browser, 'targetcreated'),
page.evaluate(url => window.open(url), server.EMPTY_PAGE)
]);
expect(popupTarget.browserContext()).toBe(context);
await context.close();
});

View File

@ -387,10 +387,10 @@ module.exports.addTests = function({testRunner, expect, puppeteer, DeviceDescrip
});
it('should trigger correct Log', async({page, server}) => {
await page.goto('about:blank');
let message;
page.on('console', event => message = event);
page.evaluate(async url => fetch(url).catch(e => {}), server.EMPTY_PAGE);
await waitEvent(page, 'console');
const [message] = await Promise.all([
waitEvent(page, 'console'),
page.evaluate(async url => fetch(url).catch(e => {}), server.EMPTY_PAGE)
]);
expect(message.text()).toContain('No \'Access-Control-Allow-Origin\'');
expect(message.type()).toEqual('error');
});