mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: further unify Puppeteer-Firefox tests with Puppeteer (#3931)
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
This commit is contained in:
parent
c3b6619432
commit
6887ad881a
@ -21,5 +21,5 @@ async function attachFrame(frameId, url) {
|
|||||||
return 'kazakh';
|
return 'kazakh';
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<iframe src='./two-frames.html'></iframe>
|
<iframe src='./two-frames.html' name='2frames'></iframe>
|
||||||
<iframe src='./frame.html'></iframe>
|
<iframe src='./frame.html' name='aframe'></iframe>
|
||||||
|
@ -9,5 +9,5 @@ body iframe {
|
|||||||
flex-shrink: 1;
|
flex-shrink: 1;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<iframe src='./frame.html'></iframe>
|
<iframe src='./frame.html' name='uno'></iframe>
|
||||||
<iframe src='./frame.html'></iframe>
|
<iframe src='./frame.html' name='dos'></iframe>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
log('Keydown:', event.key, event.code, event.which, modifiers(event));
|
log('Keydown:', event.key, event.code, event.which, modifiers(event));
|
||||||
});
|
});
|
||||||
textarea.addEventListener('keypress', 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 => {
|
textarea.addEventListener('keyup', event => {
|
||||||
log('Keyup:', event.key, event.code, event.which, modifiers(event));
|
log('Keyup:', event.key, event.code, event.which, modifiers(event));
|
||||||
|
1
test/assets/title.html
Normal file
1
test/assets/title.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
<title>Woof-Woof</title>
|
@ -26,4 +26,7 @@ a {
|
|||||||
<a href='#clicked'>123321</a>
|
<a href='#clicked'>123321</a>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
document.querySelector('a').addEventListener('click', () => {
|
||||||
|
window.__clicked = true;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@ -158,9 +158,8 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
it('should properly serialize null fields', async({page}) => {
|
it('should properly serialize null fields', async({page}) => {
|
||||||
expect(await page.evaluate(() => ({a: undefined}))).toEqual({});
|
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(() => window)).toBe(undefined);
|
||||||
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
|
|
||||||
});
|
});
|
||||||
it('should fail for circular object', async({page, server}) => {
|
it('should fail for circular object', async({page, server}) => {
|
||||||
const result = await page.evaluate(() => {
|
const result = await page.evaluate(() => {
|
||||||
@ -206,17 +205,9 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
expect(error).toBeTruthy();
|
expect(error).toBeTruthy();
|
||||||
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created');
|
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}) => {
|
it('should simulate a user gesture', async({page, server}) => {
|
||||||
await page.evaluate(playAudio);
|
const result = await page.evaluate(() => document.execCommand('copy'));
|
||||||
// also test evaluating strings
|
expect(result).toBe(true);
|
||||||
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_fails_ffox('should throw a nice error after a navigation', async({page, server}) => {
|
it_fails_ffox('should throw a nice error after a navigation', async({page, server}) => {
|
||||||
const executionContext = await page.mainFrame().executionContext();
|
const executionContext = await page.mainFrame().executionContext();
|
||||||
|
@ -68,9 +68,15 @@ module.exports.addTests = function({testRunner, expect}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Frame Management', function() {
|
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');
|
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}) => {
|
it('should send events when frames are manipulated dynamically', async({page, server}) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
http://localhost:<PORT>/frames/nested-frames.html
|
|
||||||
http://localhost:<PORT>/frames/two-frames.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
@ -1,5 +0,0 @@
|
|||||||
http://localhost:<PORT>/frames/nested-frames.html
|
|
||||||
http://localhost:<PORT>/frames/two-frames.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
||||||
http://localhost:<PORT>/frames/frame.html
|
|
@ -85,7 +85,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
|
|||||||
await keyboard.down('!');
|
await keyboard.down('!');
|
||||||
// Shift+! will generate a keypress
|
// Shift+! will generate a keypress
|
||||||
if (modifierKey === 'Shift')
|
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
|
else
|
||||||
expect(await page.evaluate(() => getResult())).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']');
|
expect(await page.evaluate(() => getResult())).toBe('Keydown: ! Digit1 49 [' + modifierKey + ']');
|
||||||
|
|
||||||
@ -111,20 +111,20 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
|
|||||||
await keyboard.up('Meta');
|
await keyboard.up('Meta');
|
||||||
expect(await page.evaluate(() => getResult())).toBe('Keyup: Meta MetaLeft 91 []');
|
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.goto(server.PREFIX + '/input/keyboard.html');
|
||||||
await page.keyboard.type('!');
|
await page.keyboard.type('!');
|
||||||
expect(await page.evaluate(() => getResult())).toBe(
|
expect(await page.evaluate(() => getResult())).toBe(
|
||||||
[ 'Keydown: ! Digit1 49 []',
|
[ 'Keydown: ! Digit1 49 []',
|
||||||
'Keypress: ! Digit1 33 33 33 []',
|
'Keypress: ! Digit1 33 33 []',
|
||||||
'Keyup: ! Digit1 49 []'].join('\n'));
|
'Keyup: ! Digit1 49 []'].join('\n'));
|
||||||
await page.keyboard.type('^');
|
await page.keyboard.type('^');
|
||||||
expect(await page.evaluate(() => getResult())).toBe(
|
expect(await page.evaluate(() => getResult())).toBe(
|
||||||
[ 'Keydown: ^ Digit6 54 []',
|
[ 'Keydown: ^ Digit6 54 []',
|
||||||
'Keypress: ^ Digit6 94 94 94 []',
|
'Keypress: ^ Digit6 94 94 []',
|
||||||
'Keyup: ^ Digit6 54 []'].join('\n'));
|
'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');
|
await page.goto(server.PREFIX + '/input/keyboard.html');
|
||||||
const keyboard = page.keyboard;
|
const keyboard = page.keyboard;
|
||||||
await keyboard.down('Shift');
|
await keyboard.down('Shift');
|
||||||
@ -132,7 +132,7 @@ module.exports.addTests = function({testRunner, expect, FFOX}) {
|
|||||||
expect(await page.evaluate(() => getResult())).toBe(
|
expect(await page.evaluate(() => getResult())).toBe(
|
||||||
[ 'Keydown: Shift ShiftLeft 16 [Shift]',
|
[ 'Keydown: Shift ShiftLeft 16 [Shift]',
|
||||||
'Keydown: ~ Backquote 192 [Shift]', // 192 is ` keyCode
|
'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'));
|
'Keyup: ~ Backquote 192 [Shift]'].join('\n'));
|
||||||
await keyboard.up('Shift');
|
await keyboard.up('Shift');
|
||||||
});
|
});
|
||||||
|
@ -339,7 +339,13 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
|
|||||||
const browser = await puppeteer.connect({browserWSEndpoint});
|
const browser = await puppeteer.connect({browserWSEndpoint});
|
||||||
const pages = await browser.pages();
|
const pages = await browser.pages();
|
||||||
const restoredPage = pages.find(page => page.url() === server.PREFIX + '/frames/nested-frames.html');
|
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);
|
expect(await restoredPage.evaluate(() => 7 * 8)).toBe(56);
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
@ -940,8 +940,8 @@ module.exports.addTests = function({testRunner, expect, headless, Errors, Device
|
|||||||
|
|
||||||
describe('Page.title', function() {
|
describe('Page.title', function() {
|
||||||
it('should return the page title', async({page, server}) => {
|
it('should return the page title', async({page, server}) => {
|
||||||
await page.goto(server.PREFIX + '/input/button.html');
|
await page.goto(server.PREFIX + '/title.html');
|
||||||
expect(await page.title()).toBe('Button test');
|
expect(await page.title()).toBe('Woof-Woof');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -128,13 +128,16 @@ const utils = module.exports = {
|
|||||||
/**
|
/**
|
||||||
* @param {!Frame} frame
|
* @param {!Frame} frame
|
||||||
* @param {string=} indentation
|
* @param {string=} indentation
|
||||||
* @return {string}
|
* @return {Array<string>}
|
||||||
*/
|
*/
|
||||||
dumpFrames: function(frame, indentation) {
|
dumpFrames: function(frame, indentation) {
|
||||||
indentation = 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())
|
for (const child of frame.childFrames())
|
||||||
result += '\n' + utils.dumpFrames(child, ' ' + indentation);
|
result.push(...utils.dumpFrames(child, ' ' + indentation));
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -126,5 +126,5 @@ function stringify(value) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(stabilize(null, value), stabilize);
|
return JSON.stringify(stabilize(null, value), stabilize, 2);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user