Skip to content

Commit 81c7841

Browse files
committed
Added UITest
1 parent f36c359 commit 81c7841

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
<Using Include="Microsoft.Maui.Controls.CustomAttributes" />
7777
</ItemGroup>
7878

79+
<ItemGroup>
80+
<ProjectReference Include="..\..\..\Essentials\src\Essentials.csproj" />
81+
</ItemGroup>
82+
7983
<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />
8084

8185
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<controls:TestContentPage xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
3+
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
x:Class="Maui.Controls.Sample.Issues.Issue30010">
6+
<Grid RowDefinitions="Auto,*">
7+
<Label Text="Issue 30010" FontAttributes="Bold" Margin="12" />
8+
9+
<ScrollView Grid.Row="1">
10+
<StackLayout Padding="12,0,12,12" Spacing="6">
11+
12+
<WebView>
13+
<WebView.Source>
14+
<HtmlWebViewSource>
15+
<HtmlWebViewSource.Html>
16+
<![CDATA[
17+
<HTML>
18+
<BODY>
19+
<H1>.NET MAUI</H1>
20+
<P>Welcome to WebView 👍.</P>
21+
</BODY>
22+
</HTML>
23+
]]>
24+
</HtmlWebViewSource.Html>
25+
</HtmlWebViewSource>
26+
</WebView.Source>
27+
</WebView>
28+
29+
<Button AutomationId="TakeScreenshotButton" Text="Take Screenshot" Command="{Binding ScreenshotCommand}" />
30+
31+
<Image AutomationId="ResultImage" Source="{Binding Image}" />
32+
33+
</StackLayout>
34+
</ScrollView>
35+
</Grid>
36+
</controls:TestContentPage>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System.Windows.Input;
2+
3+
namespace Maui.Controls.Sample.Issues
4+
{
5+
6+
[Issue(IssueTracker.Github, 30010, "Loading the captured screenshot from webview content to Image control does not visible", PlatformAffected.Android)]
7+
public partial class Issue30010 : TestContentPage
8+
{
9+
public Issue30010()
10+
{
11+
InitializeComponent();
12+
}
13+
14+
protected override void Init()
15+
{
16+
BindingContext = new Issue30010ViewModel();
17+
}
18+
}
19+
20+
class Issue30010ViewModel : BindableObject
21+
{
22+
ImageSource _screenshot;
23+
24+
public Issue30010ViewModel()
25+
{
26+
ScreenshotCommand = new Command(async () => await CaptureScreenshot(), () => Screenshot.IsCaptureSupported);
27+
}
28+
29+
public ICommand ScreenshotCommand { get; }
30+
31+
public ImageSource Image
32+
{
33+
get => _screenshot;
34+
set
35+
{
36+
_screenshot = value;
37+
OnPropertyChanged();
38+
}
39+
}
40+
41+
async Task CaptureScreenshot()
42+
{
43+
var mediaFile = await Screenshot.CaptureAsync();
44+
var stream = await mediaFile.OpenReadAsync(ScreenshotFormat.Png);
45+
46+
Image = ImageSource.FromStream(() => stream);
47+
}
48+
}
49+
}

src/Controls/tests/TestCases.HostApp/MauiProgram.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public static MauiApp CreateMauiApp()
3131
.Issue18720TimePickerAddMappers()
3232
.Issue25436RegisterNavigationService();
3333

34+
appBuilder.ConfigureEssentials();
35+
3436
#if IOS || MACCATALYST
3537

3638
appBuilder.ConfigureCollectionViewHandlers();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#if ANDROID
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue30010 : _IssuesUITest
9+
{
10+
public Issue30010(TestDevice device) : base(device)
11+
{
12+
}
13+
14+
public override string Issue =>
15+
"Loading the captured screenshot from webview content to Image control does not visible";
16+
17+
[Test]
18+
[Category(UITestCategories.WebView)]
19+
public void Issue30010_TakeScreenshotFunctionality()
20+
{
21+
App.WaitForElement("TakeScreenshotButton");
22+
App.Tap("TakeScreenshotButton");
23+
24+
Thread.Sleep(500); // Pause briefly to allow the screenshot operation to complete
25+
26+
VerifyScreenshot("Issue30010TakeScreenshotFunctionality");
27+
}
28+
}
29+
#endif

0 commit comments

Comments
 (0)