Skip to content

Commit

Permalink
Add page.screenshot viewport clipping test (#1320)
Browse files Browse the repository at this point in the history
* Add page.screenshot viewport clipping test

* Refactor
  • Loading branch information
kblok authored Nov 2, 2019
1 parent dbdbdfb commit 4e6d984
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/PuppeteerSharp.Tests/PageTests/ScreenshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@ await page.SetViewportAsync(new ViewPortOptions
}
}

[Fact]
public async Task ShouldClipElementsToTheViewport()
{
using (var page = await Context.NewPageAsync())
{
await page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 });
await page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
var screenshot = await page.ScreenshotDataAsync(new ScreenshotOptions
{
Clip = new Clip
{

X = 50,
Y = 600,
Width = 100,
Height = 100
}
});
Assert.True(ScreenshotHelper.PixelMatch("screenshot-offscreen-clip.png", screenshot));
}
}

[Fact]
public async Task ShouldRunInParallel()
{
Expand Down Expand Up @@ -148,12 +170,12 @@ public async Task ShouldRunInParallelInMultiplePages()
var pageTasks = new List<Task<Page>>();
for (var i = 0; i < n; i++)
{
Func<Task<Page>> func = async () =>
async Task<Page> func()
{
var page = await Context.NewPageAsync();
await page.GoToAsync(TestConstants.ServerUrl + "/grid.html");
return page;
};
}

pageTasks.Add(func());
}
Expand Down

0 comments on commit 4e6d984

Please sign in to comment.