This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
UI Testing Guidelines
DeanFaizal edited this page Mar 4, 2019
·
4 revisions
UI Testing is implemented using the Page Object Pattern (POP) where each page corresponds to a Page class in the UITest Project.
Nuget: https://www.nuget.org/packages/Xamarin.UITest.POP
Sample: https://github.com/xamarin-automation-service/uitest-pop-example
Best practices and tips: https://blog.xamarin.com/best-practices-tips-xamarin-uitest/
Channel 9 Video for best practices and tips: https://channel9.msdn.com/Shows/XamarinShow/Best-Practices-for-User-Interface-Automation
Let's go through the steps for adding a UITest to toggle a Switch Element on a page named HomePage as an example:
- Add a UI Test project to your solution
- Add the POP Nuget package referenced above to the project
- Add AutomationId values for Elements in the page to be tested and for the page itself. In this case:
AutomationId="HomePage"
on the main Grid, andAutomationId="LightModeSwitch"
on the Switch - Create the page class for the page to be tested. Eg:
HomePage.cs
inheriting fromBasePage
. Override the abstract trait property with a PlatformQuery the name of the page on each platform:
protected override PlatformQuery Trait => new PlatformQuery
{
Android = x => x.Marked(nameof(HomePage)),
iOS = x => x.Marked(nameof(HomePage))
};
- Create a
using alias directive
for query like so:
using Query = System.Func<Xamarin.UITest.Queries.AppQuery, Xamarin.UITest.Queries.AppQuery>;
- Add the query for the Switch in the constructor
public HomePage()
{
LightModeSwitch = x => x.Marked(nameof(LightModeSwitch));
}
- Create the method for a simple UI operation
public void SetLightMode()
{
app.WaitForElement(LightModeSwitch);
app.Tap(LightModeSwitch);
app.Screenshot("Toggled light mode");
}
- Add a Tests.cs class that inherits from
BaseTestFixture
and add the Test Fixture
[Test]
public void SetLightMode()
{
new HomePage()
.SetLightMode();
}
- Go to
View > Test
in Visual Studio and Run the UI Test