-
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
Conversation
public Issue3809(TestDevice testDevice) : base(testDevice) | ||
{ | ||
} | ||
|
||
public override string Issue => "SetUseSafeArea is wiping out Page Padding "; | ||
|
||
// TODO: The _ variables need to be AutomationId values |
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.
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Step 2: Rename RunningApp to App.
// if (!usesSafeAreaInsets) | ||
// Assert.AreEqual(element.ReadText(), "25, 25, 25, 25"); | ||
[Test] | ||
[Category(UITestCategories.Layout)] |
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.
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.
// element = App.WaitForFirstElement(_paddingLabel); | ||
// Assert.AreNotEqual(element.ReadText(), "0, 0, 0, 0"); | ||
// Disable Safe Area Insets | ||
App.Tap(SafeAreaAutomationId); |
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.
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.
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 comment
The 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:
- Avoid complex XPath queries, they are more expensive than locating elements using AutomationId.
- In a good number of tests you will find Task.Delay(500) or other ways to have a random delay while we wait for the UI to catch up. That will make tests unreliable so please prevent using those and remove them where you can. There are methods
WaitForElement("AutomationId")
andWaitForNoElement("AutomationId")
that will wait for an element to appear or disappear, those are usually good replacements.
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
Description of Change
Reenable test ported from Xamarin.UITest.
Below you can find an equivalent table between Xamarin.UITest and Appium.
App.Back();
App.BackgroundApp();
App.ForegroundApp();
App.ClearText("AutomationId");
App.DismissKeyboard();
bool result = App.IsKeyboardShown();
App.DimissAlert();
App.DoubleTap("AutomationId");
App.DoubleClick("AutomationId");
App.DoubleTapCoordinates(100, 100);
App.DragAnDrop("from", "to");
App.DragCoordinates(0, 0, 100, 100);
App.EnterText("AutomationId", "Text");
App.IncreaseStepper("AutomationId");
App.DecreaseStepper("AutomationId");
App.LongPress("AutomationId");
App.Lock();
App.Unlock();
App.Pan(0, 0, 100, 100);
App.PincToZoomIn("AutomationId");
App.PinchToZoomInCoordinates(100, 100);
App.PincToZoomOut("AutomationId");
App.PinchToZoomOutCoordinates(100, 100);
App.PressEnter();
App.PressVolumeDown();
App.PressVoumeUp();
App.QueryUntilPresent(() => App.WaitForElement("success"));
App.Screenshot("Sample");
App.StartRecording();
App.StopRecording();
App.SetLightMode();
App.SetDarkMode();
App.ToggleWifi();
App.TogleAirplane();
VerifyScreenshot();
App.ScrollDown("CollectionView", ScrollStrategy.Gesture, 0.5);
App.ScrollTo("Item10", true);
App.ScrollUp("CollectionView", ScrollStrategy.Gesture, 0.5);
App.SetOrientationLandscape();
App.SetOrientationPortrait();
App.SetSliderValue("AutomationId", 4);
App.Shake();
App.Tap("AutomationId");
App.TapCoordinates(100, 100);
App.TouchAndHold("AutomationId");
App.TouchAndHoldCoordinates(100, 100);
App.WaitForElement("AutomationId");
App.WaitForNoElement("Selected: Item 1");