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

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM