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);

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值