3.8 KiB
UI Testing
Introduction
Currently we are using Appium to facilitate UI automation for Windows, Catalyst, iOS, and Android.
Appium relies on different implementations called drivers
for each platform that have different behaviors/functions.
- Windows - WinAppDriver
- Catalyst - mac2
- iOS - XCUITest
- Android - UIAutomator2
Creating a new test
The sample project
The project that is used for UI Tests is located here: src\Controls\tests\TestCases.HostApp\Controls.TestCases.HostApp.csproj
There are two types of tests you can add, Issue and Gallery.
Adding a new Issue
This will be the majority of new tests added which will be primarily for testing functionality and adding regression tests.
You will need to create some kind of UI to test against, which will go in the Controls.Sample.UITests project. Create a new class and attribute it with [Issue]
and derive from TestContentPage
.
Then in the Controls.AppiumTests project add a new class that derives from _IssuesUITest
and add your test.
You can use the example for the sample project here and the example for the corresponding test here.
Adding a GalleryPage
Gallery tests are to make it easier to run the same set of tests on controls, if you are creating a new control you would want to add a new gallery page.
We have some base classes you can derive from to make setting this up easier: CoreGalleryPage and ContentViewGalleryPage
All controls you intend to interact with need to set the 'AutomationId' property as this will be what you use to query for the element.
Once you have created your GalleryPage, add it to CorePageView so that it will show up on the main page at launch.
Adding the test
The project that hosts the tests is located here: src\Controls\tests\TestCases.Shared.Tests\Controls.TestCases.Shared.Tests.csproj
This project is using NUnit
All tests should derive from UITestBase
and should override FixtureSetup/FixtureTeardown
to navigate to the specific UI you want to test and navigate back when finished.
protected override void FixtureSetup()
{
base.FixtureSetup();
App.NavigateToGallery(DragAndDropGallery);
}
protected override void FixtureTeardown()
{
base.FixtureTeardown();
App.NavigateBack();
}
The test will have access to gestures/interactions through the App
property.
App.WaitForElement("btnLogin");
App.EnterText("entryUsername", "user@email.com");
App.EnterText("entryPassword", "Password");
App.Tap("btnLogin");
var lblStatus = App.WaitForElement("lblStatus").FirstOrDefault();
var text = lblStatus?.Text;
Assert.IsNotNull(text);
Assert.IsTrue(text.StartsWith("Logging in", StringComparison.CurrentCulture));
Running tests
Please see the wiki for setting up/running tests.
Known Issues
- iOS doesn't support nested accessibility elements which will make some elements unreachable