From 09c8152023510d5a0a5bd77f24832e5d93f3e2cb Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Sat, 30 Dec 2023 09:29:31 +0200 Subject: [PATCH] Add some UI tests Done: iOS/macOS/Android. TODO: Windows --- .../Concepts/AlertsGalleryPage.cs | 96 ++++++++++++ .../CoreViews/CorePageView.cs | 1 + .../samples/Controls.Sample.UITests/Test.cs | 10 ++ src/Controls/src/Core/Page/Page.cs | 2 +- .../Tests/Concepts/AlertsGalleryTests.cs | 142 ++++++++++++++++++ .../Actions/AppiumAndroidAlertActions.cs | 95 ++++++++++++ .../Actions/AppiumAppleAlertActions.cs | 88 +++++++++++ .../src/UITest.Appium/AppiumAndroidApp.cs | 1 + .../src/UITest.Appium/AppiumCatalystApp.cs | 1 + .../src/UITest.Appium/AppiumIOSApp.cs | 1 + .../src/UITest.Appium/HelperExtensions.cs | 75 ++++++++- 11 files changed, 507 insertions(+), 5 deletions(-) create mode 100644 src/Controls/samples/Controls.Sample.UITests/Concepts/AlertsGalleryPage.cs create mode 100644 src/Controls/tests/UITests/Tests/Concepts/AlertsGalleryTests.cs create mode 100644 src/TestUtils/src/UITest.Appium/Actions/AppiumAndroidAlertActions.cs create mode 100644 src/TestUtils/src/UITest.Appium/Actions/AppiumAppleAlertActions.cs diff --git a/src/Controls/samples/Controls.Sample.UITests/Concepts/AlertsGalleryPage.cs b/src/Controls/samples/Controls.Sample.UITests/Concepts/AlertsGalleryPage.cs new file mode 100644 index 000000000000..d4756fc656b0 --- /dev/null +++ b/src/Controls/samples/Controls.Sample.UITests/Concepts/AlertsGalleryPage.cs @@ -0,0 +1,96 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Maui.Controls; + +namespace Maui.Controls.Sample +{ + internal class AlertsGalleryPage : CoreGalleryBasePage + { + protected override void Build() + { + // ALERTS + + // Test with a single button alert that can be dismissed by tapping the button + Add(Test.Alerts.AlertCancel, async t => + { + await DisplayAlert( + "Alert Title Here", + "Alert Message Here", + "CANCEL"); + t.ReportSuccessEvent(); + }); + + // Test alert with options to Accept or Cancel, Accept is the correct option + Add(Test.Alerts.AlertAcceptCancelClickAccept, async t => + { + var result = await DisplayAlert( + "Alert Title Here", + "Alert Message Here", + "ACCEPT", "CANCEL"); + if (result) + t.ReportSuccessEvent(); + else + t.ReportFailEvent(); + }); + + // Test alert with options to Accept or Cancel, Cancel is the correct option + Add(Test.Alerts.AlertAcceptCancelClickCancel, async t => + { + var result = await DisplayAlert( + "Alert Title Here", + "Alert Message Here", + "ACCEPT", "CANCEL"); + if (result) + t.ReportFailEvent(); + else + t.ReportSuccessEvent(); + }); + + // ACTION SHEETS + + // Test action sheet with items and Cancel, Item 2 is the correct option + Add(Test.Alerts.ActionSheetClickItem, async t => + { + var result = await DisplayActionSheet( + "Action Sheet Title Here", + "CANCEL", "DESTROY", + "ITEM 1", "ITEM 2", "ITEM 3"); + if (result == "ITEM 2") + t.ReportSuccessEvent(); + else + t.ReportFailEvent(); + }); + + // Test action sheet with items and Cancel, Cancel is the correct option + Add(Test.Alerts.ActionSheetClickCancel, async t => + { + var result = await DisplayActionSheet( + "Action Sheet Title Here", + "CANCEL", "DESTROY", + "ITEM 1", "ITEM 2", "ITEM 3"); + if (result == "CANCEL") + t.ReportSuccessEvent(); + else + t.ReportFailEvent(); + }); + + // Test action sheet with items and Cancel, Destroy is the correct option + Add(Test.Alerts.ActionSheetClickDestroy, async t => + { + var result = await DisplayActionSheet( + "Action Sheet Title Here", + "CANCEL", "DESTROY", + "ITEM 1", "ITEM 2", "ITEM 3"); + if (result == "DESTROY") + t.ReportSuccessEvent(); + else + t.ReportFailEvent(); + }); + } + + ExpectedEventViewContainer