xamarin UI Test - Unable to load the native APK path that I point to

此生再无相见时 提交于 2020-02-02 06:44:33

问题


I want to run a REPL UI Test on native android APK by referring to the path of the APK with following code.

public void BeforeEachTest()
{
    app = ConfigureApp.Android
          .ApkFile("C:/app-debug.apk")
          .StartApp():
}

public void AppLaunches()
{
    app.Repl();
}

But, during running test, it will always load test like below which is not the path that I've set.

Loading tests from testing\Xamarin Testing\AndroidTest\AndroidTest\bin\Debug\AndroidTest.dll

the REPL console is not opening and my selected APKis not being test, and there are no error messages, what should I do?

I have not found any related solution.

I've installed: NUnit {2.6.4}, NUnit3TestAdapter {3.7.0}, NUnitTestAdapter{2.0.0} and Xamarin.UITest {2.0.5.1591-dev}


回答1:


You will notice the // syntax in the below pathing works for my UI tests. Why dont you try C://whateverfolderyourapkisin/app-debug.apk.

 if (platform == Platform.Android)
        {

            var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            path = path.Substring(6);
            path = path.Replace("UITest", "My_AppFolder_PCL\\My_AppFolder_PCL.Droid");
            path = path + "/com.mycompany.myapp.apk";
            path = path.Replace("\\", "//");



            return ConfigureApp
                .Android
                .EnableLocalScreenshots()
                .ApkFile(path)
                .StartApp();
        }



回答2:


A more elegant way to do it:

 if (platform == Platform.Android)
 {

            var path = System.AppDomain.CurrentDomain.BaseDirectory;

            path = Directory.GetParent(path).Parent.Parent.Parent.FullName;
            path = Path.Combine(path, "Droid/bin/Release/app-Signed.apk");

            return ConfigureApp
                .Android
                .EnableLocalScreenshots()
                .ApkFile (path)
                .StartApp();
 }


来源:https://stackoverflow.com/questions/42216636/xamarin-ui-test-unable-to-load-the-native-apk-path-that-i-point-to

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