-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Reenable test ported from Xamarin.UITest #25624
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,71 @@ | ||
using NUnit.Framework; | ||
#if TEST_FAILS_ON_WINDOWS | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues | ||
{ | ||
public class Issue3809 : _IssuesUITest | ||
{ | ||
const string SetPagePadding = "Set Page Padding"; | ||
const string SafeAreaText = "Safe Area Enabled: "; | ||
const string PaddingLabel = "paddingLabel"; | ||
const string SafeAreaAutomationId = "SafeAreaAutomation"; | ||
|
||
public Issue3809(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "SetUseSafeArea is wiping out Page Padding "; | ||
|
||
// TODO: The _ variables need to be AutomationId values | ||
//void AssertSafeAreaText(string text) | ||
//{ | ||
// var element = | ||
// RunningApp | ||
// .WaitForFirstElement(_safeAreaAutomationId); | ||
|
||
// element.AssertHasText(text); | ||
//} | ||
|
||
//[Test] | ||
//[Category(UITestCategories.Layout)] | ||
//public void SafeAreaInsetsBreaksAndroidPadding() | ||
//{ | ||
// // ensure initial paddings are honored | ||
// AssertSafeAreaText($"{_safeAreaText}{true}"); | ||
// var element = App.WaitForFirstElement(_paddingLabel); | ||
void AssertSafeAreaText(string text) | ||
{ | ||
var element = App.WaitForFirstElement(SafeAreaAutomationId); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step 2: Rename RunningApp to App. |
||
// bool usesSafeAreaInsets = false; | ||
// if (element.ReadText() != "25, 25, 25, 25") | ||
// usesSafeAreaInsets = true; | ||
ClassicAssert.AreEqual(element.GetText(), text); | ||
} | ||
|
||
// Assert.AreNotEqual(element.ReadText(), "0, 0, 0, 0"); | ||
// if (!usesSafeAreaInsets) | ||
// Assert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
[Test] | ||
[Category(UITestCategories.Layout)] | ||
[Category(UITestCategories.Page)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step 3: Add Category. Without a category, the project test project will not compile. If the category is relevant to all tests in a class, you can also put it on the class. |
||
public void SafeAreaInsetsBreaksAndroidPadding() | ||
{ | ||
// Ensure initial paddings are honored | ||
AssertSafeAreaText($"{SafeAreaText}{true}"); | ||
var element = App.WaitForFirstElement(PaddingLabel); | ||
|
||
// // disable Safe Area Insets | ||
// App.Tap(_safeAreaAutomationId); | ||
// AssertSafeAreaText($"{_safeAreaText}{false}"); | ||
// element = App.WaitForFirstElement(_paddingLabel); | ||
bool usesSafeAreaInsets = false; | ||
if (element.ReadText() != "25, 25, 25, 25") | ||
usesSafeAreaInsets = true; | ||
|
||
// Assert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
ClassicAssert.AreNotEqual(element.ReadText(), "0, 0, 0, 0"); | ||
if (!usesSafeAreaInsets) | ||
ClassicAssert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
|
||
// // enable Safe Area insets | ||
// App.Tap(_safeAreaAutomationId); | ||
// AssertSafeAreaText($"{_safeAreaText}{true}"); | ||
// element = App.WaitForFirstElement(_paddingLabel); | ||
// Assert.AreNotEqual(element.ReadText(), "0, 0, 0, 0"); | ||
// Disable Safe Area Insets | ||
App.Tap(SafeAreaAutomationId); | ||
AssertSafeAreaText($"{SafeAreaText}{false}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step 4: Find replacement methods in Appium. See the reference table from the PR. We already have a lot of helper methods to interact with the UI through Appium. You can find those under src\TestUtils\src\UITest.Appium. If you do think there is no alternative, please reach out and lets see if we need to add something. |
||
element = App.WaitForFirstElement(PaddingLabel); | ||
|
||
// if (!usesSafeAreaInsets) | ||
// Assert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
ClassicAssert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
|
||
// Enable Safe Area insets | ||
App.Tap(SafeAreaAutomationId); | ||
AssertSafeAreaText($"{SafeAreaText}{true}"); | ||
element = App.WaitForFirstElement(PaddingLabel); | ||
ClassicAssert.AreNotEqual(element.ReadText(), "0, 0, 0, 0"); | ||
|
||
// // Set Padding and then disable safe area insets | ||
// App.Tap(_setPagePadding); | ||
// App.Tap(_safeAreaAutomationId); | ||
// AssertSafeAreaText($"{_safeAreaText}{false}"); | ||
// element = App.WaitForFirstElement(_paddingLabel); | ||
// Assert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
if (!usesSafeAreaInsets) | ||
ClassicAssert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
|
||
//} | ||
// Set Padding and then disable safe area insets | ||
App.Tap(SetPagePadding); | ||
App.Tap(SafeAreaAutomationId); | ||
AssertSafeAreaText($"{SafeAreaText}{false}"); | ||
element = App.WaitForFirstElement(PaddingLabel); | ||
ClassicAssert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step 5: Make test work! Obvious, right? Run it locally as much as you can and make sure the tests pass. Then push them up to a pull request and see if they run there and pass there too. Apply good practices:
|
||
} | ||
} | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the UI tests using Xamarin.UITest from Xamarin.Forms have been ported to .NET MAUI. The goal is to have all existing Xamarin.Forms tests running alongside everything created in .NET MAUI. However, a number of tests are commented. Let's review the steps required to enable them.
Step 1: Uncomment the code.