Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jun 6, 2024
1 parent d2b85d5 commit 026da41
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Maui.Controls.Sample;
using NUnit.Framework;
using OpenQA.Selenium.Appium;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;

Expand All @@ -18,62 +17,58 @@ protected override void NavigateToGallery()
App.NavigateToGallery("Alerts Gallery");
}

// TODO: UI testing alert code is not yet implemented on Windows.
#if !WINDOWS
[Test]
public void AlertCancel()
{
if (Device == TestDevice.Windows)
Assert.Ignore("UI testing alert code is not yet implemented on Windows.");

var test = Test.Alerts.AlertCancel;

var remote = new EventViewContainerRemote(UITestContext, test);
remote.GoTo(test.ToString());

var textBeforeClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (none)", textBeforeClick);
ClassicAssert.AreEqual($"Event: {test} (none)", textBeforeClick);

remote.TapView();

var alert = App.WaitForElement(() => App.GetAlert());
Assert.NotNull(alert);
ClassicAssert.NotNull(alert);

var alertText = alert.GetAlertText();
CollectionAssert.Contains(alertText, "Alert Title Here");
CollectionAssert.Contains(alertText, "Alert Message Here");

var buttons = alert.GetAlertButtons();
CollectionAssert.IsNotEmpty(buttons);
Assert.True(buttons.Count == 1, $"Expected 1 buttonText, found {buttons.Count}.");
ClassicAssert.True(buttons.Count == 1, $"Expected 1 buttonText, found {buttons.Count}.");

var cancel = buttons.First();
Assert.AreEqual("CANCEL", cancel.GetText());
ClassicAssert.AreEqual("CANCEL", cancel.GetText());

cancel.Click();

App.WaitForNoElement(() => App.GetAlert());

var textAfterClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
ClassicAssert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
}

[Test]
[TestCase(Test.Alerts.AlertAcceptCancelClickAccept, "ACCEPT")]
[TestCase(Test.Alerts.AlertAcceptCancelClickCancel, "CANCEL")]
public void AlertAcceptCancel(Test.Alerts test, string buttonText)
{
if (Device == TestDevice.Windows)
Assert.Ignore("UI testing alert code is not yet implemented on Windows.");

var remote = new EventViewContainerRemote(UITestContext, test);
remote.GoTo(test.ToString());

var textBeforeClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (none)", textBeforeClick);
ClassicAssert.AreEqual($"Event: {test} (none)", textBeforeClick);

remote.TapView();

var alert = App.WaitForElement(() => App.GetAlert());
Assert.NotNull(alert);
ClassicAssert.NotNull(alert);

var alertText = alert.GetAlertText();
CollectionAssert.Contains(alertText, "Alert Title Here");
Expand All @@ -83,7 +78,7 @@ public void AlertAcceptCancel(Test.Alerts test, string buttonText)
.Select(b => (Element: b, Text: b.GetText()))
.ToList();
CollectionAssert.IsNotEmpty(buttons);
Assert.True(buttons.Count == 2, $"Expected 2 buttons, found {buttons.Count}.");
ClassicAssert.True(buttons.Count == 2, $"Expected 2 buttons, found {buttons.Count}.");
CollectionAssert.Contains(buttons.Select(b => b.Text), "ACCEPT");
CollectionAssert.Contains(buttons.Select(b => b.Text), "CANCEL");

Expand All @@ -93,7 +88,7 @@ public void AlertAcceptCancel(Test.Alerts test, string buttonText)
App.WaitForNoElement(() => App.GetAlert());

var textAfterClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
ClassicAssert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
}

[Test]
Expand All @@ -102,19 +97,16 @@ public void AlertAcceptCancel(Test.Alerts test, string buttonText)
[TestCase(Test.Alerts.ActionSheetClickDestroy, "DESTROY")]
public void ActionSheetClickItem(Test.Alerts test, string itemText)
{
if (Device == TestDevice.Windows)
Assert.Ignore("UI testing alert code is not yet implemented on Windows.");

var remote = new EventViewContainerRemote(UITestContext, test);
remote.GoTo(test.ToString());

var textBeforeClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (none)", textBeforeClick);
ClassicAssert.AreEqual($"Event: {test} (none)", textBeforeClick);

remote.TapView();

var alert = App.WaitForElement(() => App.GetAlert());
Assert.NotNull(alert);
ClassicAssert.NotNull(alert);

var alertText = alert.GetAlertText();
CollectionAssert.Contains(alertText, "Action Sheet Title Here");
Expand All @@ -123,7 +115,7 @@ public void ActionSheetClickItem(Test.Alerts test, string itemText)
.Select(b => (Element: b, Text: b.GetText()))
.ToList();
CollectionAssert.IsNotEmpty(buttons);
Assert.True(buttons.Count == 5, $"Expected 5 buttons, found {buttons.Count}.");
ClassicAssert.True(buttons.Count == 5, $"Expected 5 buttons, found {buttons.Count}.");
CollectionAssert.Contains(buttons.Select(b => b.Text), "CANCEL");
CollectionAssert.Contains(buttons.Select(b => b.Text), "DESTROY");
CollectionAssert.Contains(buttons.Select(b => b.Text), "ITEM 1");
Expand All @@ -136,7 +128,8 @@ public void ActionSheetClickItem(Test.Alerts test, string itemText)
App.WaitForNoElement(() => App.GetAlert());

var textAfterClick = remote.GetEventLabel().GetText();
Assert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
ClassicAssert.AreEqual($"Event: {test} (SUCCESS 1)", textAfterClick);
}
#endif
}
}
1 change: 1 addition & 0 deletions src/TestUtils/src/UITest.Appium/AppiumCatalystApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public AppiumCatalystApp(Uri remoteAddress, IConfig config)
{
_commandExecutor.AddCommandGroup(new AppiumCatalystMouseActions(this));
_commandExecutor.AddCommandGroup(new AppiumCatalystTouchActions(this));
_commandExecutor.AddCommandGroup(new AppiumAppleAlertActions(this));
}

public override ApplicationState AppState
Expand Down

0 comments on commit 026da41

Please sign in to comment.