C#Appium IsAppInstalled错误:无法找到包

时间:2018-06-05 14:30:46

标签: c# android appium

问题

您好。

我在C#中有一个类来验证我的应用程序是否已安装在我的设备中。

当我的设备安装了应用程序时,一切正常。但是,当我的设备没有安装应用程序时,系统会给出以下错误消息:

消息:

  

测试方法MYAPP.Main.RunTest.RunAllTests抛出异常:   System.InvalidOperationException:未知的服务器端错误   处理命令时发生。原始错误:找不到   在设备上打包com.android.MyApp

如何使用和声明IsAppInstalled?

我正在使用VS 2017社区。

环境

  • 展示问题的Appium版本(或git版本):Appium 驱动程序v4.0.30319
  • 未出现此问题的最新Appium版本(如果适用): 相同
  • 用于运行Appium的桌面操作系统/版本:Windows 10 Pro
  • Node.js版本(除非使用Appium.app | exe):Node.js v10.1.0
  • 正在测试的移动平台/版本:Android 8.0
  • 真实设备或模拟器/模拟器:真实设备Samsung S9
  • Appium CLI或Appium.app | exe:Appium Server v1.8.0

详情

My Capabilities:

public class CapDeviceConfig{

    public DesiredCapabilities CapDeviceConfigOptions(){
        //set the capabilities (https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md)

        DesiredCapabilities cap = new DesiredCapabilities();
        cap.SetCapability("automationName", "Appium"); // Which automation engine to use
        cap.SetCapability("platformName", "Android"); // Which mobile OS platform to use
        cap.SetCapability("platformVersion", "8.0.0"); // Mobile OS version
        cap.SetCapability("deviceName", "starlte"); // The kind of mobile device or emulator to use // S9
        cap.SetCapability("udid", "2270048324037ece"); // Unique device identifier of the connected physical device
        cap.SetCapability("appPackage", "com.android.MyApp");
        cap.SetCapability("appActivity", "md5ab6683a3e3c3f0bd6864e3305b4e45c6.SplashScreenActivity");    
        cap.SetCapability("noReset", "True"); // Don't reset app state before this session.
        cap.SetCapability("printPageSourceOnFindFailure", "True"); // When a find operation fails, print the current page source.
        return cap;
    }
}

链接到Appium日志

https://gist.github.com/pbmzbr/b0638a0237c7d846de2e94000163c1f6

代码重现问题

public class AppInstallVerification{

            //Creating instance for Appium driver
            AppiumDriver<AndroidElement> driverCheck;

            CapDeviceConfig cap = new CapDeviceConfig();

            EnrollmentTests enrollmentTests = new EnrollmentTests();

            InstallApp install = new InstallApp();

            public void IsAppInstalled(){

                cap.CapDeviceConfigOptions();
                driverCheck = new AndroidDriver<AndroidElement>(new Uri("http://127.0.0.1:4723/wd/hub"), cap.CapDeviceConfigOptions());

                if (driverCheck.IsAppInstalled("com.android.MyApp"))
                {
                    Console.WriteLine("App is installed!");
                    enrollmentTests.CodeApplied();
                }
                else
                {
                    Console.WriteLine("App is not installed!");
                    install.InstallingApp();
                }            
            }
        }

0 个答案:

没有答案