Demonstration based on this sample, to show how different UI elements can be tested with App Center: https://github.com/xamarin/xamarin-forms-samples/tree/master/FormsGallery
Перейти к файлу
Kent Green f25a62062d Update FormsGallery.Android.csproj 2020-12-03 15:26:13 -08:00
FormsGallery Update FormsGallery.Android.csproj 2020-12-03 15:26:13 -08:00
FormsGallery.UITest remove test project references from Xamarin.UITest 2020-12-03 09:37:37 -08:00
.gitignore Update .gitignore 2020-06-10 18:51:13 -07:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2019-12-11 13:51:19 -08:00
FormsGallery.sln add debug upload command 2020-12-03 09:08:19 -08:00
LICENSE Initial LICENSE commit 2019-12-11 13:51:22 -08:00
Metadata.xml add sample code 2020-06-10 15:56:36 -07:00
README.md Update README.md 2020-12-03 13:20:40 -08:00
SECURITY.md Initial SECURITY.md commit 2019-12-11 13:51:23 -08:00
android.sh Update android.sh 2020-12-03 13:49:41 -08:00
ios.sh add debug upload command 2020-12-03 09:08:19 -08:00
msft_README.md add sample code 2020-06-10 15:56:36 -07:00

README.md

Main branch project build status

  • Android: Build status
  • iOS: Build status

Packages

If the sample hasn't been updated for awhile and hits strange errors, it's highly recommended to try updating the following packages:

  • Xamarin.UITest in the Xamarin.UITest project
  • Xamarin Test Cloud Agent in the iOS project
  • Xamarin.Forms in the iOS & Android project

Please file an issue if there's a problem either updating the packages, or you hit strange errors after hitting them.

FormsGallery Xamarin.UITest sample

This sample displays all the views, cells, layouts, and pages available in Xamarin.Forms, one per page; and some basic Xamarin.UITest interactions with those elements.

General Xamarin.UITest project structure

AppInitializer

This is a fairly standard format for enabling cross-platform Android & iOS testing. It's essentially using the default Visual Studio Mac template for a cross-platform UITest, except for line 35:

Environment.SetEnvironmentVariable("UITEST_FORCE_IOS_SIM_RESTART", "1");

This environment variable is used so that when testing on a local iOS simulator, the app is always restarted. This is required to work around a local testing bug in the current stable version of Xamarin.UITest (at the time of writing this).

Multiple Test Fixtures

Each of these .cs files is a separate Test Fixture, which are named based on the grouped related elements in the underlying Xamarin.Forms app navigation:

  • Cells.cs
  • LayoutsWithMultipleChildren.cs
  • LayoutsWithSingleContent.cs
  • Pages.cs
  • ViewsForEditingText.cs
  • ViewsForPresentation.cs
  • ViewsForSettingValues.cs
  • ViewsThatDisplayCollections.cs
  • ViewsThatInitiateCommands.cs

HelperMethods.cs

This file contains methods which are shared across each and every Test Fixture listed above, to handle common shared logic and/or especially complex testing scenarios.

TestFixture required SetUp method

This includes a required [SetUp] method called "BeforeEachTest()", which is executed before each [Test]: https://github.com/King-of-Spades/appcenter-Xamarin.Forms-Gallery-Demo/blob/main/FormsGallery/FormsGallery.UITest/HelperMethods.cs#L100-L104

OpenPage(string page, int pageType)

  • page - pass a case-sensitive string for Xamarin.UITest to find on the main page of the app. UITest will tap the element to open the page or scroll down on the view if it's not found to see if it appears and then can tap it.
  • pageType - Selects either "C# Pages" or "XAML Pages" in the UI before finding the specific page searched for.

Source: https://github.com/King-of-Spades/appcenter-Xamarin.Forms-Gallery-Demo/blob/main/FormsGallery/FormsGallery.UITest/HelperMethods.cs#L14-L31

SetDatePicker(DateTime date)

This method Invokes native Android & iOS methods on their respective platforms in order to update the DatePicker values.

  • date - Takes a standard "DateTime" value, though the method only works with Month, Day & Year; because those are what the Forms DatePickers are set up to work with.

Source: https://github.com/King-of-Spades/appcenter-Xamarin.Forms-Gallery-Demo/blob/main/FormsGallery/FormsGallery.UITest/HelperMethods.cs#L34-L57

Called by ViewsforSettingValues.cs -> [Test] DatePicker(): https://github.com/King-of-Spades/appcenter-Xamarin.Forms-Gallery-Demo/blob/main/FormsGallery/FormsGallery.UITest/ViewsForSettingValues.cs#L81-L93

SetTimePicker (int hour, int minute, bool am)

Unlike SetDatePicker this method can't directly accept a DateTime, because it would require setting a day, month, & year when only the hour, minute & am/pm values are actually needed. This is worked around by using DateTime.Now within the method itself so that it can be handled in a somewhat similar fashion to the companion SetDatePicker method.

Called by ViewsforSettingValues.cs -> [Test] TimePicker(): https://github.com/King-of-Spades/appcenter-Xamarin.Forms-Gallery-Demo/blob/main/FormsGallery/FormsGallery.UITest/ViewsForSettingValues.cs#L95-L107