无法使用appium启动活动

9avjhtql  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(301)

我正在尝试使用appium android驱动程序启动一个透明的活动,并传递一些可选的意图参数。它总是失败,状态为500,并且无论我设置了多少abdexectimeout功能值,命令都会超时。
示例代码:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName", "UiAutomator2");
capabilities.setCapability("app", "/path/to/app.apk");
capabilities.setCapability("appActivity", "com.myapp.home.splash.SplashActivity");
capabilities.setCapability("appPackage", "com.myapp.app");
capabilities.setCapability("udid","e76dcaaqs");
capabilities.setCapability("avdLaunchTimeout", 300000);
capabilities.setCapability("useKeystore", false);
capabilities.setCapability("autoGrantPermissions",true);
capabilities.setCapability("automationName", "UiAutomator2");
capabilities.setCapability("skipUnlock", true);
capabilities.setCapability("androidInstallTimeout", 180000);
capabilities.setCapability("adbExecTimeout", 60000);
capabilities.setCapability("ignoreHiddenApiPolicyError", true);
capabilities.setCapability("deviceName", "Oppo Reno");
capabilities.setCapability("appWaitForLaunch", false);
AndroidDriver<MobileElement> driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
Activity activity = new Activity("com.myapp.app", "com.myapp.instrumentation.persistence.preferences.PreferencesOverrideActivity");
String intentParam = "--es \"overrideData\" '[{\"pref_name\": \"MyPref\",\"overrides\": " +
        "[{\"key\": \"mykey\",\"value\": \"" + obj.getValue() + "\",\"type\": \"string\"}],\"clear\": false}]'";
activity.setOptionalIntentArguments(intentParam);
//            activity.setStopApp(true);
try {
    Thread.sleep(5000);
} catch (InterruptedException e) {
    e.printStackTrace();
}
driver.startActivity(activity);
driver.launchApp();

} catch (OperationFailedException | MalformedURLException e) {
e.printStackTrace();
}

输出日志
[w3c(146a80b7)]调用appiumdriver.startactivity(),并使用参数:[“com.myapp.app”、“com.myapp.instrumentation.persistence.preferences.preferencesoverrideactivity”、“com.myapp.app.app”、“com.myapp.home.splash.splashactivity”、“”、“”、“--es“overridedata”[{“pref_name”:“mypreferences”、“overrides”:[{“key”:“mykey”:“mykey”,“value”:“myvalue”:“myvalue”:“type”:“string”},“clear”:false}]'[androiddriver]启动包'com.myapp.app'和活动'com.myapp.instrumentation.persistence.preferences.preferencesoverrideactivity'[adb]running'/users/user1/library/android/sdk/platform tools/adb-p 5037-s e15adapa shell am start-w-ncom.myapp.app/com.myapp.instrumentation.persistence.preferences.preferencesoverrideactivity-s--es“overridedata”“[{”pref_name:“mypreferences”,“overrides:[{”key:“mykey”,“value:“myvalue”,“type:“string”}],“clear”:false}]“[instrumentation]instrumentation\u结果:shortmsg=进程崩溃[检测]检测\u代码:0[检测]进程已退出,代码为0
奇怪的是,即使进程崩溃,偏好数据也会更新。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题