Appium学习

Capability设置

  • app apk 地址

  • appPackage 包名

  • appActivity Activity 名字

    • adb logcat | grep ActivityManager
    • adb shell dumpsys activity activities | grep mFocusedActivity
    • aapt dumpsys badging com.android.chrome.apk | grep ‘launchable-activity’
  • automationName 默认使用uiautomator2(andorid默认使用uiautomator2,ios默认使用XCUTest)

  • noReset fullReset是否在测试前后重置相关环境(例如首次打开弹窗,或者登录信息)

    • 雪球的首次启动弹框功能,noReset=True,noReset=false情况

      1
      capabilities.setCapability("noReset", "true");
  • unicodeKeyBoard resetKeyBoard是否需要输入非英文之外的语言并在测试完成后重置输入法

    • 举例输入中文,阿里巴巴
  • 官方文档:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md

  • dontStopAppOnReset首次启动的时候,不停止app(可以调试或者运行的时候提升运行速度)

  • skipDeviceInitialization 跳过安装,权限设置等操作(可以调试或者运行的时候提升运行速度)

Appium元素定位

  • 常用两种定位方式Id,AccessibilityId
    • driver.findElementById(resource-id)
    • driver.findElementByAccessibilityId(content-desc)

三种经典等待方式

  • 强制等待
    • sleep 不推荐
  • 隐式等待(全局性)
    • 设置一个超时时间,服务端appium会在给定的时间内,不停的查找,默认值是0
    • 用法:driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    • 在服务端等待
  • 显示等待(等待某个元素)
    • wait = new WebDriverWait(driver, 10, 1);
    • wait.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.id(“com.android.settings:id/title”)));
    • 客户端等待