Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: further unify Puppeteer-Firefox tests with Puppeteer #3931

Merged
merged 2 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/assets/frames/nested-frames.html
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<title>Woof-Woof</title>
3 changes: 3 additions & 0 deletions test/assets/wrappedlink.html
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn’t this one work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is split into two tests: the Symbol one is now on line 68

});
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
Original file line number Diff line number Diff line change
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.

14 changes: 7 additions & 7 deletions test/keyboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
await page.keyboard.sendCharacter('a');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a');
});
it_fails_ffox('should report shiftKey', async({page, server}) => {
it_fails_firefox('should report shiftKey', async({page, server}) => {
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
const codeForKey = {'Shift': 16, 'Alt': 18, 'Meta': 91, 'Control': 17};
Expand All @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}