zoukankan      html  css  js  c++  java
  • 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:envandroid-sdkplatform-toolsadb.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);
     
  • 相关阅读:
    JSP学习笔记(一)
    【转】Key Presses
    【转】Event Driven Programming
    【转】Getting an Image on the Screen
    【转】Setting up SDL 2 on Visual Studio 2019 Community
    Windows定时任务copy到nfs目录
    DLL转存为IL文件及修改后重新生成DLL文件
    【转】Setting up SDL 2 on MinGW
    【转】Setting up SDL 2 on Code::Blocks 12.11
    【转】Setting up SDL on Windows
  • 原文地址:https://www.cnblogs.com/testway/p/8032728.html
Copyright © 2011-2022 走看看