Is there any way to close and reconnect to my app in Xamarin UITest?
In my test case I want close and reconnect my Android app.
Is there any way to close and reconnect to my app in Xamarin UITest?
In my test case I want close and reconnect my Android app.
Depending upon what you mean by "close", but here are a couple of ways...
In the MainActivty
of your Xamarin.Forms
Android app, add some UITest
backdoors:
[Export("HardExitBackdoor")]
public void HardExitBackdoor()
{
Log.Info("UITest", "Finish");
Finish();
}
[Export("BackgroundBackdoor")]
public void BackgroundBackdoor()
{
Log.Info("UITest", "MoveTaskToBack");
MoveTaskToBack(true);
}
Now in your test, you can "exit" your app and "restart" it:
[Test]
public void HardRestartApp()
{
app.Invoke("HardExitBackdoor");
BeforeEachTest();
WelcomeTextIsDisplayed();
}
[Test]
public void BackgroundedApp()
{
app.Invoke("BackgroundBackdoor");
BeforeEachTest();
WelcomeTextIsDisplayed();
}
[Test]
public void SoftRestartApp()
{
for (var i = 0; i < 10; i++)
app.Back();
BeforeEachTest();
WelcomeTextIsDisplayed();
}
Android/Java and Calabash/Ruby
public class MainActivity extends Activity {
~~~~
public void HardExitBackdoor() {
Log.w(TAG, "finish");
finish();
}
~~~~
}
To invoke this method in Ruby/calabash-android:
backdoor "HardExitBackdoor"