Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Include no caret controls for UITests comparing snapshots #27113

Closed
wants to merge 12 commits into from
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Maui.Controls.Sample
{
public class NoCaretEditor : Editor
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Maui.Controls.Sample
{
public class NoCaretEditorHandler
{
public static void RemoveCaret()
{
Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping(nameof(NoCaretEditor), (handler, view) =>
{
if (view is NoCaretEditor)
{
#if ANDROID
handler.PlatformView.SetCursorVisible(false);
#elif IOS
handler.PlatformView.TintColor = UIKit.UIColor.Clear;
#endif
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Maui.Controls.Sample
{
public class NoCaretEntry : Entry
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace Maui.Controls.Sample
{
public class NoCaretEntryHandler
{
public static void RemoveCaret()
{
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(NoCaretEntry), (handler, view) =>
{
if (view is NoCaretEntry)
{
#if ANDROID
handler.PlatformView.SetCursorVisible(false);
#elif IOS
handler.PlatformView.TintColor = UIKit.UIColor.Clear;
#endif
}
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Maui.Controls.Sample
{
public class NoCaretSearchBar : SearchBar
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Maui.Controls.Sample
{
public class NoCaretSearchBarHandler
{
public static void RemoveCaret()
{
Microsoft.Maui.Handlers.SearchBarHandler.Mapper.AppendToMapping(nameof(NoCaretSearchBar), (handler, view) =>
{
if (view is NoCaretSearchBar)
{
#if ANDROID
var editText = Microsoft.Maui.Platform.ViewGroupExtensions.GetFirstChildOfType<Android.Widget.EditText>(handler.PlatformView);
editText.SetCursorVisible(false);
#elif IOS || MACCATALYST
handler.PlatformView.TintColor = UIKit.UIColor.Clear;
#endif
}
});
}
}
}
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26968.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<controls:TestContentPage xmlns:controls="clr-namespace:Maui.Controls.Sample.Issues"
xmlns:local="clr-namespace:Maui.Controls.Sample"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue26968">
<StackLayout
Padding="12">
<local:NoCaretEntry
AutomationId="TestEntry" />
</StackLayout>
</controls:TestContentPage>
17 changes: 17 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26968.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Maui.Controls.Sample.Issues
{

[Issue(IssueTracker.Github, 26968, "Need reliable validation support to ensure the KeyboardType in Appium", PlatformAffected.All)]
public partial class Issue26968 : TestContentPage
{
public Issue26968()
{
InitializeComponent();
}

protected override void Init()
{

}
}
}
7 changes: 5 additions & 2 deletions src/Controls/tests/TestCases.HostApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ public static MauiApp CreateMauiApp()
handlers.AddHandler(typeof(Issue11132Control), typeof(Issue11132ControlHandler));
#endif
});

NoCaretEditorHandler.RemoveCaret();
NoCaretEntryHandler.RemoveCaret();
NoCaretSearchBarHandler.RemoveCaret();

appBuilder.Services.AddTransient<TransientPage>();
appBuilder.Services.AddScoped<ScopedPage>();

return appBuilder.Build();
}
}
Expand Down Expand Up @@ -110,8 +115,6 @@ protected override Window CreateWindow(IActivationState activationState)
#endif

#endif


return window;
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#if TEST_FAILS_ON_WINDOWS // NoCaret Controls not implemented on Windows.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue26968 : _IssuesUITest
{
const string TestEntry = "TestEntry";

public override string Issue => "Need reliable validation support to ensure the KeyboardType in Appium";

public Issue26968(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.Entry)]
public void VerifyNoCaretEntry()
{
App.WaitForElement(TestEntry);
App.Tap(TestEntry);
App.EnterText(TestEntry, "Test");

App.DismissKeyboard();
QueryUntilKeyboardNotPresent(App.IsKeyboardShown);

VerifyScreenshot();
}

static T QueryUntilKeyboardNotPresent<T>(
Func<T> func,
int retryCount = 10,
int delayInMs = 2000)
{
var result = func();

int counter = 0;
while ((result is true) && counter < retryCount)
{
Thread.Sleep(delayInMs);
result = func();
counter++;
}

return result;
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p

CommandResponse IsKeyboardShown(IDictionary<string, object> parameters)
{
return new CommandResponse(_app.Driver.IsKeyboardShown(), CommandResponseResult.Success);
try
{
return new CommandResponse(_app.Driver.IsKeyboardShown(), CommandResponseResult.Success);
}
catch
{
return new CommandResponse(false, CommandResponseResult.Failed);
}
}

protected virtual CommandResponse DismissKeyboard(IDictionary<string, object> parameters)
Expand Down
Loading