问题
您好。
我在C#中有一个类来验证我的应用程序是否已安装在我的设备中。
当我的设备安装了应用程序时,一切正常。但是,当我的设备没有安装应用程序时,系统会给出以下错误消息:
消息:
测试方法MYAPP.Main.RunTest.RunAllTests抛出异常: System.InvalidOperationException:未知的服务器端错误 处理命令时发生。原始错误:找不到 在设备上打包com.android.MyApp
如何使用和声明IsAppInstalled?
我正在使用VS 2017社区。 p>
环境
详情
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();
}
}
}