Skip to content

Commit

Permalink
chore: further unify Puppeteer-Firefox tests with Puppeteer (#3931)
Browse files Browse the repository at this point in the history
This patch:
* unifies assets between tests
* enables a few puppeteer tests on Puppeteer-Firefox

Drive-by: beautify failing output of `expect.toEqual` matcher.

References #3889
  • Loading branch information
aslushnikov committed Feb 6, 2019
1 parent c3b6619 commit 6887ad8
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions test/assets/frames/nested-frames.html
Expand Up @@ -21,5 +21,5 @@
return 'kazakh';
}
</script>
<iframe src='./two-frames.html'></iframe>
<iframe src='./frame.html'></iframe>
<iframe src='./two-frames.html' name='2frames'></iframe>
<iframe src='./frame.html' name='aframe'></iframe>
4 changes: 2 additions & 2 deletions test/assets/frames/two-frames.html
Expand Up @@ -9,5 +9,5 @@
flex-shrink: 1;
}
</style>
<iframe src='./frame.html'></iframe>
<iframe src='./frame.html'></iframe>
<iframe src='./frame.html' name='uno'></iframe>
<iframe src='./frame.html' name='dos'></iframe>
2 changes: 1 addition & 1 deletion test/assets/input/keyboard.html
Expand Up @@ -13,7 +13,7 @@
log('Keydown:', event.key, event.code, event.which, modifiers(event));
});
textarea.addEventListener('keypress', event => {
log('Keypress:', event.key, event.code, event.which, event.keyCode, event.charCode, modifiers(event));
log('Keypress:', event.key, event.code, event.which, event.charCode, modifiers(event));
});
textarea.addEventListener('keyup', event => {
log('Keyup:', event.key, event.code, event.which, modifiers(event));
Expand Down
1 change: 1 addition & 0 deletions test/assets/title.html
@@ -0,0 +1 @@
<title>Woof-Woof</title>
3 changes: 3 additions & 0 deletions test/assets/wrappedlink.html
Expand Up @@ -26,4 +26,7 @@
<a href='#clicked'>123321</a>
</div>
<script>
document.querySelector('a').addEventListener('click', () => {
window.__clicked = true;
});
</script>
17 changes: 4 additions & 13 deletions test/evaluation.spec.js
Expand Up @@ -158,9 +158,8 @@ module.exports.addTests = function({testRunner, expect}) {
it('should properly serialize null fields', async({page}) => {
expect(await page.evaluate(() => ({a: undefined}))).toEqual({});
});
it_fails_ffox('should return undefined for non-serializable objects', async({page, server}) => {
it('should return undefined for non-serializable objects', async({page, server}) => {
expect(await page.evaluate(() => window)).toBe(undefined);
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
});
it('should fail for circular object', async({page, server}) => {
const result = await page.evaluate(() => {
Expand Down Expand Up @@ -206,17 +205,9 @@ module.exports.addTests = function({testRunner, expect}) {
expect(error).toBeTruthy();
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created');
});
it_fails_ffox('should simulate a user gesture', async({page, server}) => {
await page.evaluate(playAudio);
// also test evaluating strings
await page.evaluate(`(${playAudio})()`);

function playAudio() {
const audio = document.createElement('audio');
audio.src = 'data:audio/wav;base64,UklGRiQAAABXQVZFZm10IBAAAAABAAEARKwAAIhYAQACABAAZGF0YQAAAAA=';
// This returns a promise which throws if it was not triggered by a user gesture.
return audio.play();
}
it('should simulate a user gesture', async({page, server}) => {
const result = await page.evaluate(() => document.execCommand('copy'));
expect(result).toBe(true);
});
it_fails_ffox('should throw a nice error after a navigation', async({page, server}) => {
const executionContext = await page.mainFrame().executionContext();
Expand Down
10 changes: 8 additions & 2 deletions test/frame.spec.js
Expand Up @@ -68,9 +68,15 @@ module.exports.addTests = function({testRunner, expect}) {
});

describe('Frame Management', function() {
it_fails_ffox('should handle nested frames', async({page, server}) => {
it('should handle nested frames', async({page, server}) => {
await page.goto(server.PREFIX + '/frames/nested-frames.html');
expect(utils.dumpFrames(page.mainFrame())).toBeGolden('nested-frames.txt');
expect(utils.dumpFrames(page.mainFrame())).toEqual([
'http://localhost:<PORT>/frames/nested-frames.html',
' http://localhost:<PORT>/frames/two-frames.html (2frames)',
' http://localhost:<PORT>/frames/frame.html (uno)',
' http://localhost:<PORT>/frames/frame.html (dos)',
' http://localhost:<PORT>/frames/frame.html (aframe)'
]);
});
it('should send events when frames are manipulated dynamically', async({page, server}) => {
await page.goto(server.EMPTY_PAGE);
Expand Down
5 changes: 0 additions & 5 deletions test/golden-chromium/nested-frames.txt

This file was deleted.

5 changes: 0 additions & 5 deletions test/golden-chromium/reconnect-nested-frames.txt

This file was deleted.

12 changes: 6 additions & 6 deletions test/keyboard.spec.js
Expand Up @@ -85,7 +85,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await keyboard.down('!');
// Shift+! will generate a keypress
if (modifierKey === 'Shift')
expect(await page.evaluate(() => getResult())).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']\nKeypress: ! Digit1 33 33 33 [' + modifierKey + ']');
expect(await page.evaluate(() => getResult())).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']\nKeypress: ! Digit1 33 33 [' + modifierKey + ']');
else
expect(await page.evaluate(() => getResult())).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']');

Expand All @@ -111,28 +111,28 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await keyboard.up('Meta');
expect(await page.evaluate(() => getResult())).toBe('Keyup: Meta MetaLeft 91 []');
});
it_fails_ffox('should send proper codes while typing', async({page, server}) => {
it('should send proper codes while typing', async({page, server}) => {
await page.goto(server.PREFIX + '/input/keyboard.html');
await page.keyboard.type('!');
expect(await page.evaluate(() => getResult())).toBe(
[ 'Keydown: ! Digit1 49 []',
'Keypress: ! Digit1 33 33 33 []',
'Keypress: ! Digit1 33 33 []',
'Keyup: ! Digit1 49 []'].join('\n'));
await page.keyboard.type('^');
expect(await page.evaluate(() => getResult())).toBe(
[ 'Keydown: ^ Digit6 54 []',
'Keypress: ^ Digit6 94 94 94 []',
'Keypress: ^ Digit6 94 94 []',
'Keyup: ^ Digit6 54 []'].join('\n'));
});
it_fails_ffox('should send proper codes while typing with shift', async({page, server}) => {
it('should send proper codes while typing with shift', async({page, server}) => {
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
await keyboard.down('Shift');
await page.keyboard.type('~');
expect(await page.evaluate(() => getResult())).toBe(
[ 'Keydown: Shift ShiftLeft 16 [Shift]',
'Keydown: ~ Backquote 192 [Shift]', // 192 is ` keyCode
'Keypress: ~ Backquote 126 126 126 [Shift]', // 126 is ~ charCode
'Keypress: ~ Backquote 126 126 [Shift]', // 126 is ~ charCode
'Keyup: ~ Backquote 192 [Shift]'].join('\n'));
await keyboard.up('Shift');
});
Expand Down
8 changes: 7 additions & 1 deletion test/launcher.spec.js
Expand Up @@ -339,7 +339,13 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
const browser = await puppeteer.connect({browserWSEndpoint});
const pages = await browser.pages();
const restoredPage = pages.find(page => page.url() === server.PREFIX + '/frames/nested-frames.html');
expect(utils.dumpFrames(restoredPage.mainFrame())).toBeGolden('reconnect-nested-frames.txt');
expect(utils.dumpFrames(restoredPage.mainFrame())).toEqual([
'http://localhost:<PORT>/frames/nested-frames.html',
' http://localhost:<PORT>/frames/two-frames.html (2frames)',
' http://localhost:<PORT>/frames/frame.html (uno)',
' http://localhost:<PORT>/frames/frame.html (dos)',
' http://localhost:<PORT>/frames/frame.html (aframe)',
]);
expect(await restoredPage.evaluate(() => 7 * 8)).toBe(56);
await browser.close();
});
Expand Down
4 changes: 2 additions & 2 deletions test/page.spec.js
Expand Up @@ -940,8 +940,8 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device

describe('Page.title', function() {
it('should return the page title', async({page, server}) => {
await page.goto(server.PREFIX + '/input/button.html');
expect(await page.title()).toBe('Button test');
await page.goto(server.PREFIX + '/title.html');
expect(await page.title()).toBe('Woof-Woof');
});
});

Expand Down
9 changes: 6 additions & 3 deletions test/utils.js
Expand Up @@ -128,13 +128,16 @@ const utils = module.exports = {
/**
* @param {!Frame} frame
* @param {string=} indentation
* @return {string}
* @return {Array<string>}
*/
dumpFrames: function(frame, indentation) {
indentation = indentation || '';
let result = indentation + frame.url().replace(/:\d{4}\//, ':<PORT>/');
let description = frame.url().replace(/:\d{4}\//, ':<PORT>/');
if (frame.name())
description += ' (' + frame.name() + ')';
const result = [indentation + description];
for (const child of frame.childFrames())
result += '\n' + utils.dumpFrames(child, ' ' + indentation);
result.push(...utils.dumpFrames(child, ' ' + indentation));
return result;
},

Expand Down
2 changes: 1 addition & 1 deletion utils/testrunner/Matchers.js
Expand Up @@ -126,5 +126,5 @@ function stringify(value) {
return result;
}

return JSON.stringify(stabilize(null, value), stabilize);
return JSON.stringify(stabilize(null, value), stabilize, 2);
}

0 comments on commit 6887ad8

Please sign in to comment.