-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Make
WebView.CaptureAsync()
work (#23474)
- Loading branch information
Showing
6 changed files
with
131 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Controls/tests/TestCases.HostApp/Issues/Issue14825.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
xmlns:local="clr-namespace:Maui.Controls.Sample.Issues" | ||
x:Class="Maui.Controls.Sample.Issues.Issue14825" | ||
x:DataType="local:Issue14825"> | ||
|
||
<VerticalStackLayout> | ||
<Label Text="WebView"/> | ||
<WebView x:Name="myWebView" WidthRequest="400" HeightRequest="150"> | ||
<WebView.Source> | ||
<HtmlWebViewSource> | ||
<HtmlWebViewSource.Html> | ||
<![CDATA[ | ||
<html> | ||
<body> | ||
<H1>.NET MAUI</H1> | ||
<p>Welcome to WebView. 👍</p> | ||
</body> | ||
</html> | ||
]]> | ||
</HtmlWebViewSource.Html> | ||
</HtmlWebViewSource> | ||
</WebView.Source> | ||
</WebView> | ||
|
||
<VerticalStackLayout x:Name="screenshotResult" AutomationId="screenshotResult"/> | ||
|
||
<Button AutomationId="Capture" Text="Capture" Clicked="CaptureButton_Clicked"/> | ||
|
||
<Label AutomationId="TestInstructions" Margin="0,30,0,0" FontAttributes="Bold" | ||
Text="Instructions: Click the capture button and expect a WebView screenshot to appear."/> | ||
</VerticalStackLayout> | ||
</ContentPage> |
26 changes: 26 additions & 0 deletions
26
src/Controls/tests/TestCases.HostApp/Issues/Issue14825.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#nullable enable | ||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 14825, "Capture WebView screenshot", PlatformAffected.UWP)] | ||
public partial class Issue14825 : ContentPage | ||
{ | ||
public Issue14825() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private async void CaptureButton_Clicked(object sender, EventArgs e) | ||
{ | ||
IScreenshotResult? result = await myWebView.CaptureAsync(); | ||
|
||
if (result != null) | ||
{ | ||
// Intentionally no "using" because ImageSource requires a valid stream. | ||
Stream stream = await result.OpenReadAsync(ScreenshotFormat.Png, 100); | ||
|
||
screenshotResult.Add(new Label() { Text = $"Your screenshot ({myWebView.Width}x{myWebView.Height}):" }); | ||
screenshotResult.Add(new Image() { Source = ImageSource.FromStream(() => stream), WidthRequest = myWebView.Width, HeightRequest = myWebView.Height }); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue14825.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#if WINDOWS | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue14825 : _IssuesUITest | ||
{ | ||
public override string Issue => "Capture WebView screenshot"; | ||
|
||
public Issue14825(TestDevice device) : base(device) | ||
{ | ||
} | ||
|
||
[Test] | ||
[Category(UITestCategories.WebView)] | ||
public void ValidateWebViewScreenshot() | ||
{ | ||
App.WaitForElement("TestInstructions"); | ||
|
||
// Click the capture button to capture a WebView screenshot. | ||
App.Click("Capture"); | ||
|
||
VerifyScreenshot(); | ||
} | ||
} | ||
#endif |
Binary file added
BIN
+17.3 KB
...ols/tests/TestCases.WinUI.Tests/snapshots/windows/ValidateWebViewScreenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters