问题
How to close and relaunch app in Xamarin.UI Test ? I want to restart app for each scenario in feature .
Platform: android
There is no quit() or close() session methods like we have in appium.
回答1:
Calling ConfigureApp.Android.StartApp()
in your test will launch a new session of your application for you to interact with (just make sure to save the new object).
However, with the use of NUnit, methods tagged with [Setup]
will run automatically before every method tagged with[Test]
. That means most test suites only use the ConfigureApp.Android.StartApp()
method once, in [Setup]
.
回答2:
Given you are on your are using Xamarin UI Test project,
You can use Finish()
to close the application,
or
MoveTaskToBack(true)
to minimize the application.
So that you can call them from your Test.cs, you'll need to write myBackdoorClose and myBackdoorMinimize functions (since Finish()
and MoveTaskToBack(true)
are only available in the App.cs context). How to do that, read here!
回答3:
You can actually use Xamarin.UITest.ConfigureApp.Android.StartApp(AppDataMode.DoNotClear)
in your test. It will close the app and restart it without clearing the app's data, all while the test keeps running.
This is a cross-platform solution; you can use Xamarin.UITest.ConfigureApp.iOS.StartApp...
too.
来源:https://stackoverflow.com/questions/42089998/xamarin-uitest-how-to-close-app-instance