appium 重新启动apk

在旧版本的appium,重新启动apk,调用startActivity方法可以随意启动一个app,并传入一个package name 和启动activity name的名称。语句如下:

driver.startActivity(this.packageName, this.activityName);

 

更新到新版本后,这种方法无法再使用 查阅帮助文档,startActivity修改为:

default void startActivity(Activity activity)
This method should start arbitrary activity during a test. If the activity belongs to another application, that application is started and the activity is opened.

Usage:


Activity activity = new Activity("app package goes here", "app activity goes here"); activity.setWaitAppPackage("app wait package goes here"); activity.setWaitAppActivity("app wait activity goes here"); driver.startActivity(activity);

 

如果要启动一个app ,先要设置启动后等待的activity 和packagename 的名称。

其中 new Activity("app package goes here", "app activity goes here")中的activity 名称可以通过 aapt dump badging  xxxx.apk

setWaitAppActivity 中的activity name 就是设置apk 重启后进入的页面的activity name。可以通过在自动化进入重启apk后进入的初始化页面,打印下driver.currentActivity() 获取。 System.out.println(driver.currentActivity()); 

setWaitAppActivity可以如果设置错误,自动化重启apk后,appium日志会有提示正确的activity name 

[debug] [ADB] Running 'D:\env\android-sdk\platform-tools\adb.exe' with args: ["-P",5037,"-s","Y9K0214B13002052","shell","dumpsys","window","windows"]
[debug] [ADB] Found package: 'com.xxxx.xxxx' and fully qualified activity name : 'net.wequick.small.A20'
[debug] [ADB] Incorrect package and activity. Retrying.
[debug] [ADB] Getting focused package and activity
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected

把这个提示的activity 放进去帮助文档的代码,可执行示例代码如下:

        appPackage = "com.xxxx.xxxx";
        appActivity = "com.xxxx.xxxx.LoadingActivity";
        Activity activity = new Activity(appPackage,appActivity);
        String waitActivity ="net.wequick.small.A20";
        activity.setAppWaitActivity(waitActivity);
        activity.setAppWaitPackage(appPackage);
        activity.setStopApp(false);

        driver.startActivity(activity);

 

 

 

posted @ 2017-12-13 14:34  testway  阅读(3534)  评论(2编辑  收藏  举报