Is there a method to close and Reconnect an app in Xamarin Android UITest?

走远了吗. 提交于 2019-12-08 13:11:51

问题


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.


回答1:


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();
}

Update:

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"


来源:https://stackoverflow.com/questions/38099395/is-there-a-method-to-close-and-reconnect-an-app-in-xamarin-android-uitest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!