通过Appium给iOS应用自动化执行脚本

一、简单介绍 // Introduce

背景需求就是想通过Python等脚本自动化执行触发iOS App中的一些动作

大致了解了一下,通过Appium可能是不错的方式

安装过程十分坎坷,过程中看的文档也写的不是特别清楚,踩了不少坑,总结一下在Mac上通过脚本控制iOS App的安装以及开发过程

二、安装 // Install

2.1 安装appium前置依赖

  • 安装brew(省略)

  • 安装nodejs (省略)

  • 安装npm(省略)

  • 安装Xcode

    • 可从App Store搜索安装

  • 安装Xcode Command Line Tools

    xcode-select --install
    # 如果执行后报错 xcode-select: error: command line tools are already installed, use "Software Update" to install updates
    # 请执行
    xcode-select –switch /Applications/Xcode.app/Contents/Developer
    # 验证
    xcodebuild -version
  • 安装其他依赖

    brew install libimobiledevice --HEAD
    brew install carthage
    npm install -g ios-deploy
    gem install xcpretty

2.2 安装appium

2.3 检测安装

可以忽略这部分optional的依赖检测

2.4 安装appium-inspector

可视化操作App元素

GitHub: https://github.com/appium/appium-inspector

安装包下载:https://github.com/appium/appium-inspector/releases

2.5 安装WDA

2.5.1 Clone WDA项目

2.5.2 xcode打开

clone之后直接使用xcode打开 WebDriverAgent.xcodeproj

2.5.3 配置Bundle相关信息

Team直接选个人Team

Bundle Identifier随便填一个,如 com.xxx.wda.runner,xxx随便填一个

2.5.4 配置scheme

scheme选择WebDriverAgentRunner

2.5.5 连接手机配置destination

数据线连接上电脑就会显示自己的手机了

手机需要开启开发者模式,在设置 -> 安全隐私 中开启即可

2.5.6 测试

点击测试后就会触发编译,成功后手机上会安装对应的应用

2.6 启动appium

2.7 启动appium-inspector

界面化操作app,方便通过鼠标获取位置元素等

2.8 使用Python脚本自动化执行(optional)

2.8.1 安装Python环境

省略...

2.8.2 SDK介绍

  • sdk中提供的find_element等接口可以通过XPATH等获取指定元素,获取指定元素后可以进行点击或其他动作

  • sdk中提供了一些模拟的动作,如点击、长按的动作

Refer: https://www.browserstack.com/guide/touch-actions-in-appium#toc3

2.8.9 执行脚本

三、总结 // Summary

版本信息 // Version

上述过程中软件版本如下,可供参考

引用 // Refer

  • 主要参考:https://www.jianshu.com/p/ae0959d19665?utm_campaign=maleskine...&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

  • 坑点排除:https://blog.csdn.net/xlyrh/article/details/108410738

  • Appium: https://appium.io/docs/en/2.1/guides/caps/

  • WDA原理:https://www.cnblogs.com/guowenrui/p/16990067.html

  • Appium Ruby Console: https://debugtalk.com/post/build-app-automated-test-platform-from-0-to-1-Appium-interrogate-iOS-UI/

  • 获取iOS App Bundle ID: https://commandnotfound.cn/tools/ios-app-bundle-id?id=414245413

  • Apple 基础应用 Bundle ID List: https://support.apple.com/zh-cn/guide/deployment/depece748c41/web

Extra Info

  • 命令行操作连接设备 idb: https://github.com/appium/appium-idb

最后更新于