Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Corsaro committed Dec 10, 2024
1 parent d6e64c3 commit 79248e9
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26466.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 26466, "Button is not released on unload", PlatformAffected.WinRT)]
public partial class Issue26466 : TestContentPage
{
protected override void Init()
{
var button = new Button()
{
Text = "Hello",
AutomationId = "thebutton"
};

var success = new Label
{
Text = "If you see this, the test has passed",
AutomationId = "success"
};

var layout = new Microsoft.Maui.Controls.StackLayout();
layout.Children.Add(button);

button.Pressed += (s, e) =>
{
layout.Children.Remove(button);
};

button.Released += (s, e) =>
{
layout.Children.Add(success);
};

Content = layout;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#if WINDOWS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue26466 : _IssuesUITest
{
const string ButtonId = "thebutton";
const string SuccessId = "success";

public Issue26466(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Button is not released on unload";

[Test]
[Category(UITestCategories.Button)]
public async Task SwitchColorTest()
{
App.WaitForElement(ButtonId);
App.ClickPress(ButtonId);

await Task.Delay(200);

// Button should be unloaded, so we should see the success label
App.WaitForElement(SuccessId);
}
}
}
#endif
18 changes: 18 additions & 0 deletions src/TestUtils/src/UITest.Appium/Actions/AppiumMouseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class AppiumMouseActions : ICommandExecutionGroup
const string DoubleClickCommand = "doubleClick";
const string DoubleClickCoordinatesCommand = "doubleClickCoordinates";
const string LongPressCommand = "longPress";
const string ClickPressCommand = "clickPress";

readonly AppiumApp _appiumApp;

Expand All @@ -26,6 +27,7 @@ public class AppiumMouseActions : ICommandExecutionGroup
DoubleClickCommand,
DoubleClickCoordinatesCommand,
LongPressCommand,
ClickPressCommand
};

public AppiumMouseActions(AppiumApp appiumApp)
Expand All @@ -47,6 +49,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
DoubleClickCommand => DoubleClick(parameters),
DoubleClickCoordinatesCommand => DoubleClickCoordinates(parameters),
LongPressCommand => LongPress(parameters),
ClickPressCommand => ClickPress(parameters),
_ => CommandResponse.FailedEmptyResponse,
};
}
Expand Down Expand Up @@ -169,6 +172,21 @@ CommandResponse DoubleClick(IDictionary<string, object> parameters)
return CommandResponse.SuccessEmptyResponse;
}

CommandResponse ClickPress(IDictionary<string, object> parameters)
{
var element = GetAppiumElement(parameters["element"]);

OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Mouse);
var sequence = new ActionSequence(touchDevice, 0);
sequence.AddAction(touchDevice.CreatePointerMove(element, 0, 0, TimeSpan.FromMilliseconds(5)));

sequence.AddAction(touchDevice.CreatePointerDown(PointerButton.TouchContact));
sequence.AddAction(touchDevice.CreatePause(TimeSpan.FromMilliseconds(250)));
_appiumApp.Driver.PerformActions(new List<ActionSequence> { sequence });

return CommandResponse.SuccessEmptyResponse;
}

CommandResponse DoubleClickCoordinates(float x, float y)
{
OpenQA.Selenium.Appium.Interactions.PointerInputDevice touchDevice = new OpenQA.Selenium.Appium.Interactions.PointerInputDevice(PointerKind.Mouse);
Expand Down
14 changes: 14 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ public static void RightClick(this IApp app, string element)
});
}

/// <summary>
/// Performs a mouse down/press on the matched element, without a matching release
/// </summary>
/// <param name="app"></param>
/// <param name="element"></param>
public static void ClickPress(this IApp app, string element)
{
var uiElement = FindElement(app, element);
uiElement.Command.Execute("clickPress", new Dictionary<string, object>()
{
{ "element", uiElement }
});
}

public static string? GetText(this IUIElement element)
{
var response = element.Command.Execute("getText", new Dictionary<string, object>()
Expand Down

0 comments on commit 79248e9

Please sign in to comment.