Add tests for all public methods on Page (#62)
This commit is contained in:
parent
ff4a389274
commit
739c1566a9
@ -285,8 +285,8 @@ class Page extends EventEmitter {
|
|||||||
fitWindow: false
|
fitWindow: false
|
||||||
}),
|
}),
|
||||||
this._client.send('Emulation.setVisibleSize', {
|
this._client.send('Emulation.setVisibleSize', {
|
||||||
width: width / zoom,
|
width: Math.floor(width / zoom),
|
||||||
height: height / zoom,
|
height: Math.floor(height / zoom),
|
||||||
})
|
})
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
3
test/assets/tamperable.html
Normal file
3
test/assets/tamperable.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<script>
|
||||||
|
window.result = window.injected;
|
||||||
|
</script>
|
62
test/test.js
62
test/test.js
@ -14,6 +14,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
let fs = require('fs');
|
||||||
let path = require('path');
|
let path = require('path');
|
||||||
let Browser = require('../lib/Browser');
|
let Browser = require('../lib/Browser');
|
||||||
let SimpleServer = require('./SimpleServer');
|
let SimpleServer = require('./SimpleServer');
|
||||||
@ -678,6 +679,67 @@ describe('Puppeteer', function() {
|
|||||||
]);
|
]);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Page.addScriptTag', function() {
|
||||||
|
it('should work', SX(async function() {
|
||||||
|
await page.navigate(EMPTY_PAGE);
|
||||||
|
await page.addScriptTag('/injectedfile.js');
|
||||||
|
expect(await page.evaluate(() => __injected)).toBe(42);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.url', function() {
|
||||||
|
it('should work', SX(async function() {
|
||||||
|
expect(await page.url()).toBe('about:blank');
|
||||||
|
await page.navigate(EMPTY_PAGE);
|
||||||
|
expect(await page.url()).toBe(EMPTY_PAGE);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.viewportSize', function() {
|
||||||
|
it('should get the proper viewport size', SX(async function() {
|
||||||
|
expect(page.viewportSize()).toEqual({width: 400, height: 300});
|
||||||
|
await page.setViewportSize({width: 123, height: 456});
|
||||||
|
expect(page.viewportSize()).toEqual({width: 123, height: 456});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.evaluateOnInitialized', function() {
|
||||||
|
it('should evaluate before anything else on the page', SX(async function() {
|
||||||
|
await page.evaluateOnInitialized(function(){
|
||||||
|
window.injected = 123;
|
||||||
|
});
|
||||||
|
await page.navigate(STATIC_PREFIX + '/tamperable.html');
|
||||||
|
expect(await page.evaluate(() => window.result)).toBe(123);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.printToPDF', function() {
|
||||||
|
let outputFile = __dirname + '/assets/output.pdf';
|
||||||
|
afterEach(function() {
|
||||||
|
fs.unlinkSync(outputFile);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should print to pdf', SX(async function() {
|
||||||
|
await page.navigate(STATIC_PREFIX + '/grid.html');
|
||||||
|
await page.printToPDF(outputFile);
|
||||||
|
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.plainText', function() {
|
||||||
|
it('should return the page text', SX(async function(){
|
||||||
|
await page.setContent('<div>the result text</div>');
|
||||||
|
expect(await page.plainText()).toBe('the result text');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Page.title', function() {
|
||||||
|
it('should return the page title', SX(async function(){
|
||||||
|
await page.navigate(STATIC_PREFIX + '/input/button.html');
|
||||||
|
expect(await page.title()).toBe('Button test');
|
||||||
|
}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Since Jasmine doesn't like async functions, they should be wrapped
|
// Since Jasmine doesn't like async functions, they should be wrapped
|
||||||
|
Loading…
Reference in New Issue
Block a user