Skip to content

Commit

Permalink
Test - Add DevToolsClientFacts.CanCaptureScreenshot
Browse files Browse the repository at this point in the history
- Capture screenshot, load data and confirm width/height match browser
  • Loading branch information
amaitland committed Jun 21, 2021
1 parent ff19eaa commit 42ffee0
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion CefSharp.Test/DevTools/DevToolsClientFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
using CefSharp.DevTools.Browser;
using CefSharp.DevTools.Emulation;
Expand All @@ -28,6 +31,31 @@ public DevToolsClientFacts(ITestOutputHelper output, CefSharpFixture fixture)
this.output = output;
}

[Fact]
public async Task CanCaptureScreenshot()
{
using (var browser = new ChromiumWebBrowser("www.google.com"))
{
await browser.LoadUrlAsync();

using (var devToolsClient = browser.GetDevToolsClient())
{
var response = await devToolsClient.Page.CaptureScreenshotAsync();

Assert.NotNull(response.Data);
Assert.NotEqual(0, response.Data.Length);

var image = Image.FromStream(new MemoryStream(response.Data));
var size = browser.Size;

Assert.NotNull(image);
Assert.Equal(ImageFormat.Png, image.RawFormat);
Assert.Equal(size.Width, image.Width);
Assert.Equal(size.Height, image.Height);
}
}
}

[Fact]
public void CanConvertDevToolsObjectToDictionary()
{
Expand All @@ -49,7 +77,6 @@ public void CanConvertDevToolsObjectToDictionary()
Assert.Equal("fullscreen", (string)dict["windowState"]);
}


[Fact]
public async Task CanGetDevToolsProtocolVersion()
{
Expand Down

0 comments on commit 42ffee0

Please sign in to comment.