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且外网可访问,需要在安装虚 ...
随机推荐
- 杭电1513Palindrome
Palindrome Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- Ubuntu1204 vim中文乱码解决方法
加入中文字符编码 sudo vi /var/lib/locales/supported.d/local #加入以下的中文字符集 zh_CN.GBK GBK zh_CN.GB2312 GB2312 zh ...
- 机器学习——深度学习(Deep Learning)
Deep Learning是机器学习中一个非常接近AI的领域,其动机在于建立.模拟人脑进行分析学习的神经网络,近期研究了机器学习中一些深度学习的相关知识,本文给出一些非常实用的资料和心得. Key W ...
- 被动式Telnet研究及实现(解决内外网远程维护的困难)-part A
欢迎转载.转载请保留原文链接:http://blog.csdn.net/mikulee/article/details/40149779 项目背景及需求: 近期公司有一个项目: 我们在一个arm主机上 ...
- [UWP]本地化入门
1. 前言 上一篇文章介绍了各种WPF本地化的入门知识,这篇文章介绍UWP本地化的入门知识. 2. 使用resw资源文件实现本地化 在以前的XAML平台,resx资源文件是一种很方便的本地化方案,但在 ...
- 初识homebrew
homebrew是MAC上的一个包管理工具,用于软件安装,非常方便. homebrew安装: 命令行执行: ruby -e "$(curl -fsSL https://raw.githubu ...
- Lua的数学函数
ua5.1中数学库的所有函数如下表: math.pi 为圆周率常量 = 3.14159265358979323846 函数名 函数功能 示例 示例结果 abs 取绝对值 math.abs(-15) ...
- 使用soap实现简单webservice
在网上看到一些关于用soap实现简单webservice的一些知识,简单整理一下希望对大家有所帮助. 可以给大家看一下我的简单实现的列子,Soap,大家可以到Github上自行下载. 首先说一下web ...
- reference file contains errors
一,问题分析 在学习 JavaWeb 的开发,很多时候我们会引用许多 JAR ,以为版本的问题,有时候就会出现这个问题:reference file contains errors (引用文件包含错误 ...
- 历史命令~/.bash_history,查看所有别名alias,命令执行顺序,命令行常用快捷键,输入输出重定向,wc统计字节单词行数
历史命令大小:/etc/profile中字段HISTSIZE=1000 历史命令保存文件:~/.bash_history history -c 清空历史命令 history -w 把历史命令写入~/. ...