scottlima
scottlima

Reputation: 225

Xamarin.uitest how to close app instance

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.

Upvotes: 3

Views: 2387

Answers (3)

bcr
bcr

Reputation: 2073

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.

Upvotes: 1

Valentine Bondar
Valentine Bondar

Reputation: 139

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!

Upvotes: 0

Charles Wang
Charles Wang

Reputation: 46

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].

Upvotes: 1

Related Questions