Appium Mac 命令行安装
试过很多方法都失败,打算用命令行方式安装。
准备工作:
从 https://github.com/appium/appium下载appium版本的源码(.tar)
0. 安装brew(如果已经安装可以跳过这步)
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
https://brew.sh/index_zh-cn.html: 按照官网提示在命令行执行ruby脚本(mac自带ruby)
1. 命令行安装node:
brew install node
2. cd 到 appium.tar的解压后的路径
3. 安装appium
npm install -g ./appium
安装后界面:
nalideMacBook-Pro:appium-1.6. nali$ npm install -g appium
npm WARN deprecated babel-core@5.8.: Babel is no longer being maintained. Upgrade to Babel .
npm WARN deprecated minimatch@2.0.: Please update to minimatch 3.0. or higher to avoid a RegExp DoS issue
npm WARN deprecated line-numbers@0.2.: Copy its ~ LOC directly into your code instead.
/usr/local/bin/appium -> /usr/local/lib/node_modules/appium/build/lib/main.js > appium-chromedriver@2.11. install /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver
> node install-npm.js info Chromedriver Install Installing Chromedriver version '2.28' for platform 'mac' and architecture ''
info Chromedriver Install Opening temp file to write chromedriver_mac64 to...
info Chromedriver Install Downloading https://chromedriver.storage.googleapis.com/2.28/chromedriver_mac64.zip...
info Chromedriver Install Writing binary content to /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/--1hmuws9.6gxs/chromedriver_mac64.zip...
info Chromedriver Install Extracting /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/--1hmuws9.6gxs/chromedriver_mac64.zip to /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/--1hmuws9.6gxs/chromedriver_mac64
info Chromedriver Install Creating /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac...
info Chromedriver Install Copying unzipped binary, reading from /var/folders/gs/1rvd4dj94gn10btdfzmq50680000gn/T/--1hmuws9.6gxs/chromedriver_mac64/chromedriver...
info Chromedriver Install Writing to /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver...
info Chromedriver Install /usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/chromedriver/mac/chromedriver successfully put in place > appium-selendroid-driver@1.6. install /usr/local/lib/node_modules/appium/node_modules/appium-selendroid-driver
> node ./bin/install.js dbug AndroidDriver Getting Java version
info AndroidDriver Java version is: 1.8.0_144
info Selendroid Ensuring /usr/local/lib/node_modules/appium/node_modules/appium-selendroid-driver/selendroid/download exists ……
4. 命令行运行appium 检查是否能够启动
nalideMacBook-Pro:appium-1.6. nali$ appium
[Appium] Welcome to Appium v1.6.5
[Appium] Appium REST http interface listener started on 0.0.0.0:
5. 验证的第二种方式,安装appium-doctor.
Appium 安装过程中也会遇到下面的error问题,但是不影响。后续解决
切换到appium-doctor的目录 npm install -g appium-doctor # 装好之后 检测一下iOS的环境有没有配置好 如果不加--ios 则检测Android和iOS
appium-doctor --ios # 它提示我缺少Xcode Command Line Tools和Carthage,那就补上
xcode-select --install
brew install carthage
7. 其他库:
brew install libimobiledevice --HEAD
npm install -g ios-deploy # for iOS +gem install xcpretty #对真机需要xcpretty
gem 安装速度慢可以更换镜像源
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
第一次运行配置
不配置会出现xcodebuild exited with code '65' and signal 'null'错误
8. WebDriverAgent相关(大坑)【dmg 模式适用】
iOS 10+使用的是XCUITest,Appium使用的模块是appium-xcuitest-driver,其中引用了Facebook提供的WDA方案来驱动iOS的测试。
装Appium Desktop的时候,它里面带了一个WebDriverAgent,但是这个自带的是有问题的!会造成不能使用Inspector,卡了很久!从Facebook那里自己clone一份才是王道:
cd ~
git clone https://github.com/facebook/WebDriverAgent.git
cd WebDriverAgent
mkdir -p Resources/WebDriverAgent.bundle
./Scripts/bootstrap.sh # 开始下载并编译 编译不应该报错 cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/
rm -rf WebDriverAgent # 把自带的删掉
ln -s ~/WebDriverAgent WebDriverAgent # 用facebook的原版替换回去
经过了baidu和google,用以上方法解决了不能Inspect的问题。
在使用Appium时,需要把WDA装到真机上,然后又会遇到证书的问题,我也不是很明白,总之跟provisioning profile有关。
用Xcode打开目录下的WebDriverAgent.xcodeproj,对于WebDriverAgentLib 和 WebDriverAgentRunner,勾选“Automatically manage signing”,把Team改成公司的,Bundle Identifier改成公司的证书可以接受的名字,具体可以参考官方文档操作,不懂的找开发同学协助。

然后就可以把WebDriverAgentLib和WebDriverAgentRunner都编译到真机运行一下了。正常来说,会在桌面生成一个没图标的WebDriverAgentRunner,点开之后不会有什么反应,这就对了。
终于把环境搭好了,感动啊。
写测试脚本
1. Appium server capabilities
要让App跑起来,还需要了解Appium server capabilities,它告诉Appium服务器很多信息,例如开哪个App、手机的系统/版本、在哪台设备上跑(真机还是模拟器等)等。
给出我用到的一些参数(in Python),其他capabilities请参考官方文档。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# -*- coding: utf-8 -*-
from time import sleep
from appium import webdriver
desired_caps = {}
desired_caps['automationName'] = 'XCUITest' # Xcode8.2以上无UIAutomation,需使用XCUITest
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '10.3.2'
desired_caps['deviceName'] = 'iPhone 7 Plus'
desired_caps['bundleId'] = '需要启动的bundle id, 去问开发者'
desired_caps['udid'] = '真机的udid 可在Xcode或iTunes里查看'
desired_caps['newCommandTimeout'] = 3600 # 1 hour
# 打开Appium服务器,start server后,尝试启动被测App
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
sleep(60)
driver.quit()
|
如果能跑起来,就是正常的,不然看一下报什么错。
2. Inspector
能跑起来只是第一步,更重要的是如何定位元素。
Inspector的使用方法很简单,之前运行driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)之后,连接就已经建立好了,只需在浏览器进入http://localhost:8100/inspector即可,之后就可以使用熟悉的driver.find_element_by_xxx方法来定位元素啦。

后记
Selenium的坑
后来又遇到了一点坑,例如使用send_keys方法时,报
Message: Parameters were incorrect. We wanted {“required”:[“value”]} and you sent [“text”,”sessionId”,”id”,”value”]
错误,google了一下发现是selenium新版导致的问题,降级后解决:
|
1
2
|
pip uninstall selenium
pip install selenium==3.3.1
|
手势操作
由于XCUI的原因,之前的一些手势操作如swipe、pinch、TouchAction等都不能用了,可以参考这篇官方文档,使用driver.execute_script方法代替。如
|
1
2
|
driver.execute_script('mobile: scroll', {'direction': 'down'}) # 向下滚动
driver.execute_script('mobile: dragFromToForDuration', {'duration': 0, 'fromX': 374, 'fromY': 115, 'toX': 200, 'toY': 100}) # 从右往左拖
|
对于直接用坐标的,还要注意逻辑分辨率的问题,如iPhone 7 Plus的逻辑分辨率是414×736。
最后
刚接触iOS的Appium,之后肯定还会遇到问题,会继续更新本文。
更新,最近更新到了Appium Desktop 1.1,里面带了1.6.5的Appium,使用起来暂时未发现明显区别。
附上一些参考:
1. http://www.cocoachina.com/ios/20170112/18518.html
2. http://blog.sina.com.cn/s/blog_b5a76ebd0102wuce.html
3. https://github.com/appium/appium/blob/master/docs/en/appium-setup/real-devices-ios.md
4. http://blog.csdn.net/achang21/article/details/70877583
5. https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
6. https://github.com/appium/python-client
7. https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/appium-bindings.md
8. https://github.com/facebook/WebDriverAgent/issues/537
9. https://github.com/facebook/WebDriverAgent/wiki/Using-the-Inspector
Appium Mac 命令行安装的更多相关文章
- mac 命令行安装软件
第一步需要在mac上安装brew工具 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/mas ...
- Mac 命令行安装 dmg文件
1.安装dmg文件 hdiutil attach jdk-9.0.1_osx-x64_bin.dmg 会挂载在 /Volumes 目录下 2.安装pkg文件(可以 man installer 查看命令 ...
- Mac 命令行安装mysql homebrew 安装mysql后,如何配置mysql
非常好 强力推荐 这个是我最新并且一直推崇的方法:1.安装:sunyichaodeMacBook-Pro:~ sunyichao$ brew install mysql2.开启mysql:mysql. ...
- mac 命令行 安装 需要管理员 权限
Please try running this command again as root/Administrator. sudo chown -R $USER /usr/local
- win10下使用命令行安装配置appium环境
安装列表 安卓sdk目录,即ANDROID_HOME设置 关于sdk的安装配置此处略,参考之前文章<Appium+Java(一) Windows环境搭建篇> node运行环境 appium ...
- mac下使用命令行安装、卸载ipa包、查看日志
mac下使用命令行安装.卸载ipa包.查看日志 https://www.cnblogs.com/lily1989/p/8383916.html
- appium windows 命令行中运行以及targetSdkVersionFromManifest failed的解决
启动appium服务,可以通过appium.exe可执行文件启动,也可以通过命令行启动.appium.exe启动需要通过安装可执行文件,命令行启动需要通过npm安装appium.可执行文件启动方式如下 ...
- mac命令行对复杂ipa包重新签名
最近在做ios的自动化平台,需要通过命令行安装卸载ipa包 好了问题来,别人上传的ipa包,很可能是开发签名了只能在特定手机上安装的测试ipa包,那我们如何将其安装在我们的自动化的iphone上呢? ...
- 命令行安装kvm虚拟机、桥接网络、用virt-manager管理
宿主机CentOS Linux release 7.2.1511 (Core),内核3.10.0-327.el7.x86_64 1.配置宿主机网络桥接 想让虚拟机有自己的ip且外网可访问,需要在安装虚 ...
随机推荐
- 开发指南专题六:JEECG微云高速开发平台代码生成
开发指南专题六:JEECG微云高速开发平台代码生 1.1. 代码生成扫描路径配置 用代码生成器生成代码后.须要进行相关配置配置,扫描注入control.service.entity等; 具体操作过程例 ...
- Parcel.js + Vue 2.x 极速零配置打包体验
继 Browserify.Webpack 之后,又一款打包工具 Parcel 横空出世 Parcel.js 的官网有这样的自我介绍 “极速零配置Web应用打包工具” 简单接触了一下,单从效率上来说,确 ...
- 在Azure Container Service创建Kubernetes(k8s)群集运行ASP.NET Core跨平台应用程序
引子 在此前的一篇文章中,我介绍了如何在本地docker环境中运行ASP.NET Core跨平台应用程序(http://www.cnblogs.com/chenxizhang/p/7148657.ht ...
- 优化Webpack构建性能的几点建议
Webpack 作为目前最流行的前端构建工具之一,在 vue/react 等 Framework 的生态圈中都占据重要地位.在开发现代 Web 应用的过程中,Webpack 和我们的开发过程和发布过程 ...
- 数据库——MySQL——>Java篇
MySQL MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是 ...
- JavaScript基础5——关于ECMAscript的函数
ECMAScript的函数概述(一般定义到<head>标签之间) (1)定义函数,JavaScript一般有三种定义函数方法: *第一种是使用function语句定义函数(静态方法) fu ...
- Python学习日记:day9--------函数
初识函数 1,自定义函数 s ='内容' #自定义函数 def my_len():#自定义函数没有参数 i =0 for k in s: i+=1 print(i) return i #返回值 my_ ...
- mkpasswd 随机密码生成
root@op-admin:~# mkpasswd -l -n usage: mkpasswd [args] [user] where arguments are: -l # (length of p ...
- layer遮罩层 简单的遮罩层
在这里提供一个简单layer遮罩层,想深入了解可以进入 layer官网 多多学习哦. 先看下HTML页面代码 <!DOCTYPE html> <html lang="en& ...
- 从一个word文件中读取所有的表格和标题(2)
上一篇文章主要讲了从word底层xml中获取表格和标题的方法,但是存在一个问题:word文件必须是docx格式的.如果为doc格式的,可以有两种解决方案: 一.把doc文件转换成docx格式文件,用上 ...