Appium Appium+Python3+iOS 真机环境搭建

王小喜 · 2018年07月01日 · 最后由 haha269 回复于 2019年09月02日 · 2435 次阅读

前言
Appium 是一个自动化测试开源工具,支持 iOS 平台和 Android 平台上的原生应用,web 应用和混合应用。

本次环境配置相关:
macOS:10.13.4
Appium-desktop:1.6.1
Xcode:9.3.1


一、环境配置

1、 安装 homebrew:

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、 安装libimobiledevice

$ brew install libimobiledevice --HEAD

3、 安装 carthage:

$ brew install carthage

4、安装 node:

$ brew install node

5、安装 npm:

$ brew install npm

6、安装 ios-deploy:

$ npm install -g ios-deploy

8、安装 xcpretty:

$ gem install xcpretty

9、安装 appium,appium-doctor

进入官网,下载Appium-1.6.1.dmg,安装即可。

当然你可以使用命令:npm install -g appium 来安装 appium,但是后面就会各种报错!!(别问我是怎么知道的,我搞了 2 天。)

$ npm install -g appium-doctor

10、使用 appium-doctor 检查 Appium iOS 环境环境

appium-doctor --ios

info AppiumDoctor Appium Doctor v.1.4.3
info AppiumDoctor ### Diagnostic starting ###
info AppiumDoctor  ✔ The Node.js binary was found at: /usr/local/bin/node
info AppiumDoctor  ✔ Node version is 10.1.0
info AppiumDoctor  ✔ Xcode is installed at: /Applications/Xcode.app/Contents/Developer
info AppiumDoctor  ✔ Xcode Command Line Tools are installed.
info AppiumDoctor  ✔ DevToolsSecurity is enabled.
info AppiumDoctor  ✔ The Authorization DB is set up properly.
info AppiumDoctor  ✔ Carthage was found at: /usr/local/bin/carthage
info AppiumDoctor  ✔ HOME is set to: /Users/wangjuan
info AppiumDoctor ### Diagnostic completed, no fix needed. ###
info AppiumDoctor
info AppiumDoctor Everything looks good, bye!
info AppiumDoctor

二、安装 WebDriverAgent
1、进入 appium 安装目录下 WebDriverAgent 文件夹,具体路径参照自己的路径,可以通过 find 命令查找

cd /Applications/Appium.app/Contents/Resources/app
/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

2、在 WebDriverAgent 目录下执行以下命令

mkdir -p Resources/WebDriverAgent.bundle

sh ./Scripts/bootstrap.sh

3、编译 WebDriverAgent.xcodeproj
Xcode 打开当前目录下的 WebDriverAgent.xcodeproj 文件WebDriverAgent.xcodeproj.png

注意⚠️:进入项目后要编辑一些内容,请无比按照步骤全部修改。步骤见下图!!

1、TARGETS->WebDriverAgentLib 的 Bundle Identifier 更改为自己命名的 Identifier。(所有 Identifier 注意保持一致!!)

2、TARGETS->WebDriverAgentLib 的 Signing 选择使用个人的证书。

image.png

3、TARGETS->WebDriverAgentRunner 的 Signing 选择使用个人的证书。

image.png

4、PROJECT->WebDriverAgent 的 Product Bundle Identifier 更改为自己命名的 Identifier。(所有 Identifier 注意保持一致!!)

image.png

5、TARGETS->WebDriverAgentLib 的 Product Bundle Identifier 更改为自己命名的 Identifier。(所有 Identifier 注意保持一致!!)

image.png

6、TARGETS->WebDriverAgentRunner 的 Product Bundle Identifier 更改为自己命名的 Identifier。(所有 Identifier 注意保持一致!!)

image.png

7、Device 选择已连接的测试机

8、点击 build 按钮来测试,按照步骤设置后,可 build succeeded~

image.png

9、测试机上安装证书,执行以下命令:
xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=测试机的 udid' test

如果没有报错证明安装成功,同时手机上会安装一个 WebDriverAgent 软件。需要在手机设置->通用->设备管理->信任开发者。如下图:image.pngimage.png


三、Appium Client 端
Appium Client 有 Ruby,Python,Java 三个版本,可自行选择自己喜欢的安装即可,本次只针对 Python 版安装:

pip install Appium-Python-Client


以上,接下来可以定位元素,推荐使用App Inspector,开始 iOS 自动化之旅吧~~

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 17 条回复 时间 点赞


这是什么问题啊

18楼 已删除
wtnhz 回复

谢谢女大神!

李晔 回复

windows 不能 可以装个黑苹果试试

问一个肤浅的问题,windows 能搭 IOS 的环境吗??


请问这是什么问题啊

17楼 已删除
王小喜 回复

你好,我用模拟器没有问题,真机 wda 也装上了,但是 start Session 报错
An unknown server-side error occurred while processing the command. Original error: Could not create simulator with name 'appiumTest-夏赟', device type id '夏赟' and runtime id '11.4'. Reason: 'simctl error running 'create': Invalid device type: 夏赟'

bruceBingo 回复

1、可以使用 ruby 单元测试的框架,来整理维护你的用例
2、断言部分,我认为是与功能测试一样的验证方式,你的用例需要验证什么,你就转化成脚本就可以了
3、尝试自己封装一些方法,建立简单的框架,慢慢进步。

liuxin 回复

我这下载的好正常,要不给你分享一个

wtnhz 回复

我这的觉得 appium desktop 好用

不知楼主是否经历过和我一样的瓶颈期,我现在初步的环境搭建好了,Appium+Ruby+ios 真机,也知道如何去定位元素和形成基本的测试脚本,但是仅止于此,我完全不知道如何系统化的去编写测试用例和管理用例,比如用例中如何加入断言,我想执行哪里就执行哪里,后期的用例的简单维护,以及如何生成测试报告都无所适从。因为不是开发,对代码的了解也很有限,完全不知道如何通过工程方式去实现我的自动化,由于用的是 Mac,开发工具是 Xcode,所以能够参考的资料非常有限,在这里真诚希望楼主或者论坛大神能够给出一个思路,十分感谢!

wtnhz 回复

我快撑不住了 这个环境 前前后后也搞了一个星期了 我试了 1.6.1 和 1.6.2 的时候下到一半的时候就特慢 我以为是网速慢 后来一看就是没有访问权限说是

liuxin 回复

我 window 用 appium 1.46 那个版本 想往上升级 怎么都是失败。。我都怀疑人生了 现在只好用 appium desktop

npm install -g appium 来安装 appium. 各种报错,搞了好几天,搞到怀疑人生!可是我下载 appium 1.61dmg 下载到一半说没有访问权限 要哭

linpengcheng 回复

还是妹子 心细,整理的图文合一。清晰明了。

老马 回复

我也是点来点去就点成了

WebDriverAgent 相关签名设置,可以说是 目前比较正确的操作姿势了。。。。 说实话。到现在我也没弄明白这个签名的先后步骤 会对成功和失败有什么影响。 都是鼓捣来鼓捣去 就鼓捣好了。。。

扫盲贴,楼主辛苦了!虽然 appium 我已经用了 2 年了还是要对楼主说声谢谢!

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册