Skip to content

Commit

Permalink
chore(test): simplify element screenshot tests (puppeteer#2093)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder authored and aslushnikov committed Feb 23, 2018
1 parent 56a475f commit e2b96df
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 84 deletions.
Binary file modified test/golden/screenshot-element-larger-than-viewport.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
88 changes: 4 additions & 84 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2125,105 +2125,25 @@ describe('Page', function() {
expect(screenshot).toBeGolden('screenshot-element-padding-border.png');
});
it('should capture full element when larger than viewport', async({page, server}) => {
// compare with .to-screenshot size
await page.setViewport({width: 500, height: 500});

await page.setContent(`
something above
<style>div.spacer {
border: 2px solid red;
background: red;
height: 600px;
width: 52px;
}
<style>
div.to-screenshot {
border: 2px solid blue;
background: rgba(0, 0, 0, 0.5);
border: 1px solid blue;
width: 600px;
height: 200.5px;
height: 600px;
margin-left: 50px;
transform: scaleY(1.2);
}
::-webkit-scrollbar {
display: none;
}
</style>
<div class="spacer"></div>
<div class="to-screenshot"></div>
<div class="spacer"></div>
`);

await page.evaluate(function() {
window.scrollTo(11, 12);
});

const elementHandle = await page.$('div.to-screenshot');
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden('screenshot-element-larger-than-viewport.png');

expect(await page.evaluate(function() {
return { w: window.innerWidth, h: window.innerHeight };
})).toEqual({ w: 500, h: 500 });
});
it('should screenshot element with scroll container', async({page, server}) => {
// compare with .to-screenshot size
await page.setViewport({width: 500, height: 500});

await page.setContent(`
something above
<style>div.spacer {
border: 2px solid red;
background: red;
height: 600px;
width: 52px;
}
div.container1 {
width: 600px;
height: 600px;
overflow: auto;
}
div.container2 {
width: 620px;
height: 620px;
overflow: auto;
}
div.to-screenshot {
border: 2px solid blue;
background: rgba(0, 0, 0, 0.5);
width: 580px;
height: 580px;
margin-top: 50px;
margin-left: 200px;
margin-right: 50px;
}
::-webkit-scrollbar {
display: none;
}
</style>
<div class="spacer"></div>
<div class="container1">
<div class="container2">
<div class="to-screenshot"></div>
</div>
</div>
<div class="spacer"></div>
`);

await page.evaluate(function() {
window.scrollTo(11, 12);
});

await page.$eval('div.container1', function(element) {
element.scrollTo(100, 0);
});

await page.$eval('div.container2', function(element) {
element.scrollTo(10, 30);
});

const elementHandle = await page.$('div.to-screenshot');
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden('screenshot-element-with-scroll-container.png');
expect(await page.evaluate(() => ({ w: window.innerWidth, h: window.innerHeight }))).toEqual({ w: 500, h: 500 });
});
it('should scroll element into view', async({page, server}) => {
await page.setViewport({width: 500, height: 500});
Expand Down

0 comments on commit e2b96df

Please sign in to comment.