MAC自动化环境搭建
UI自动化环境搭建
第一阶段:配置appium环境
硬件配置
mac系统电脑
java环境
sunjiedeMacBook-Air:~ vicent$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
brew
sunjiedeMacBook-Air:~ vicent$ brew -v
Homebrew 1.2.3
Homebrew/homebrew-core (git revision aa923; last commit 2017-06-23)
安装node:brew install node
安装appium:npm install –g appium
安装xcode、android sdk
创建bash_profile文件
touch .bash_profile
vi .bash_profile
打开bash_profile文件配置ANDROID_HOME和JAVA_HOME
export ANDROID_HOME="/Users/guowenxie/Documents/adt-bundle-mac-x86_64-20140702/sdk" 填写你自己的地址
export JAVA_HOME=$(/usr/libexec/java_home)
source .bash_profile
第二阶段:获取控件定位
1、安装app-inspector
a)先安装macaca
卸载原有的macaca:
1、npm uninstall macaca-cli -g
2、npm cache clean
安装:npm install macaca-cli -g
安装完成后,检查环境是否正常,终端输入:macaca doctor
只要全部显示为绿色为环境正常,若不正常,哪项显示为红色相应的解决,可以网上找一下资料,还是挺全的
b)安装brew:ruby -e "$(curl –fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
c)安装ios-webkit-debug-proxy:brew install ios-webkit-debug-proxy
d)安装macaca-ios:npm i macaca-ios -g
e) Macaca iOS 驱动调整为 USB 通信:brew install usbmuxd
f)安装app-inspector
卸载原有的app-inspector:
1、npm uninstall app-inspector -g
2、npm cache clean
安装:npm i app-inspector -g
安装成功后在终端中输入:
>>>cd /usr/local/lib/node_modules/app-inspector/node_modules/webdriveragent/WebDriverAgent
>>>mkdir -p Resources/WebDriverAgent.bundle
>>>sh ./Scripts/bootstrap.sh -d
若在执行以上3句命令行报错说找不到某些目录时的解决办法:
前往:https://github.com/facebook/WebDriverAgent 打包下载源码;
复制源码中【WebDriverAgentTests文件夹】、【Scripts文件夹】、【Cartfile文件】、【Cartfile.resolved文件】
粘贴到/usr/local/lib/node_modules/app-inspector/node_modules/webdriveragent/WebDriverAgent 目录下
重新执行以上3句命令行
g)安装ios-deploy:brew install ios-deploy
2、:xcode打开app-inspector中的WebDriverAgent工程:
路径为:/usr/local/lib/node_modules/app-inspector/node_modules/.1.0.41@webdriveragent/WebDriverAgent/WebDriverAgent.xcodeproj
1) 重新编绎WebDriverAgentLib:
修改:Bundle id,添加Team,选择WebDriverAgentLib并编辑(如下面3张图)
2)如以上步骤重新编绎WebDriverAgentRunner
3)选择WebDriverAgentUSBClient并编绎
4)按照步骤1)中修改:Bundle id,添加Team,重新编绎IntegrationApp,但是需要添加一步修改Product Name为: WebDriverAgentRunner-Runner
此时选中IntegrationApp并编绎时,可能会报错:找不到info.plist (这个是因为工程中缺少一个目录文件:WebDriverAgentTests)
解决办法:进入appium的安装路径中WebDriverAgent工程(/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/)中拷备该目录文件放到app-inspectorWebDriverAgent工程中
再次编绎,若报错新问题: Main storyboard file base name 相关的问题的问题
解决办法:进入IntegrationApp>info>Custom iOS Target Properties中删除Main storyboard file base name的配置
若遇到其它问题,继续解决,直到可以正确编绎为止
建议:UnitTests、IntegrationTests 也如1)修改:Bundle id,添加Team,操作后最后再编绎 IntegrationApp
3、打开终端,输入 :macaca server --verbose
出现以下内容
sunjiedeMacBook-Air:~ vicent$ macaca server --verbose
************************************
* version 2.0.3 is outdate *
* run: npm i -g macaca-cli@2.0.4 *
************************************
More information: https://macacajs.github.io/changelog.html
>> index.js:18:12 [master] pid:3450 webdriver server start with config:
{ port: 3456,
verbose: true,
always: true,
ip: '10.11.18.157',
host: 'sunjiedeMacBook-Air.local',
loaded_time: '2017-06-26 13:51:12' }
>> middlewares.js:17:10 [master] pid:3450 base middlewares attached
>> router.js:127:10 [master] pid:3450 router set
>> webdriver sdk launched
4、打开终端,输入:app-inspector -u 真机设备UDID --verbose
运行过程中会在手机上安装WebDriverAgent的APP(记得要去信任证书才行,若第一次失败了,信任证书后重新执行终端命令)并启动,稍等一会儿会被置入后台,此时会自动打开一个网页,此时就会显示出当前的设备UI界面
sunjiedeMacBook-Air:~ vicent$ app-inspector -u 95fe7916c490ffc58b7c3ff95e2642009ab0f1ef --verbose
***************************************
* version 2.0.3 is outdate *
* run: npm i -g app-inspector@2.0.6 *
***************************************
>> server.js:16:12 [master] pid:3493 server start with config:
{ port: 5678,
verbose: true,
udid: '95fe7916c490ffc58b7c3ff95e2642009ab0f1ef',
ip: '10.11.18.157',
host: 'sunjiedeMacBook-Air.local',
loaded_time: '2017-06-26 13:53:12' }
>> app-inspector.js:43:12 [master] pid:3493 server start at: http://10.11.18.157:5678
>> xctest-client.js:52:14 [master] pid:3493 project path: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
>> xctestwd start with port: 8001
>> xctest-client.js:224:14 [master] pid:3493 xcode version: 8.3.2
>> XCTestWD version: 1.0.31
>> xctest-client.js:172:14 [master] pid:3493 2017-06-26 13:53:14.414 xcodebuild[3499:285075] IDETestOperationsObserverDebug: Writing diagnostic log for test session to:
/Users/vicent/Library/Developer/Xcode/DerivedData/XCTestWD-evljajykmolwzobrozpobiggeeea/Logs/Test/E7D94522-B4BE-4053-AB67-DA5E0F1763B2/Session-XCTestWDUITests-2017-06-26_135314-wX8vjB.log
>> xctest-client.js:173:14 [master] pid:3493 please check project: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
>> xctest-client.js:172:14 [master] pid:3493 2017-06-26 13:53:14.415 xcodebuild[3499:285021] [MT] IDETestOperationsObserverDebug: (579558DA-9AA1-4CE5-9D5F-7088803FDE27) Beginning test session XCTestWDUITests-579558DA-9AA1-4CE5-9D5F-7088803FDE27 at 2017-06-26 13:53:14.414 with Xcode 8E2002 on target <DVTiOSDevice: 0x7f933a858580> {
deviceSerialNumber: C76R89ZHGRYD
identifier: 95fe7916c490ffc58b7c3ff95e2642009ab0f1ef
deviceClass: iPhone
deviceName: VincePhone
deviceIdentifier: 95fe7916c490ffc58b7c3ff95e2642009ab0f1ef
productVersion: 10.3.2
buildVersion: 14F89
deviceSoftwareVersion: 10.3.2 (14F89)
deviceArchitecture: arm64
deviceTotalCapacity: 60253212672
deviceAvailableCapacity: 22598217728
deviceIsTransient: NO
ignored: NO
deviceIsBusy: NO
deviceIsActivated: YES
deviceActivationState: Activated
isPasscodeLocked: YES
deviceType: <DVTDeviceType:0x7f933a65fb30 Xcode.DeviceType.iPhone>
supportedDeviceFamilies: (
1
)
applications: (null)
provisioningProfiles: (null)
activityProgress: -2
activityTitle:
hasInternalSupport: NO
isSupportedOS: YES
developerDiskMountError: (null)
(null)
bootArgs: <unavailable>
} (10.3.2 (14F89))
>> xctest-client.js:173:14 [master] pid:3493 please check project: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
>> xctest-client.js:172:14 [master] pid:3493 MDMCreateDeltaDirectory:1920 calling MDMDirectoryDiff with:
state->old_bundle: /var/folders/tg/nr44b54n29g821rtyr8tr3540000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/4cc79676076eb780d086ade00486f50b/95fe7916c490ffc58b7c3ff95e2642009ab0f1ef/XCTestWDUITests-Runner.app
state->new_bundle: /Users/vicent/Library/Developer/Xcode/DerivedData/XCTestWD-evljajykmolwzobrozpobiggeeea/Build/Products/Debug-iphoneos/XCTestWDUITests-Runner.app
state->dst_bundle: /var/folders/tg/nr44b54n29g821rtyr8tr3540000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/XCTestWDUITests-Runner.app.ghDWUa/XCTestWDUITests-Runner.app_sparse.ipa/Payload//XCTestWDUITests-Runner.app, binaryDiff flag: FALSE
dst_ipa: /var/folders/tg/nr44b54n29g821rtyr8tr3540000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/XCTestWDUITests-Runner.app.ghDWUa/XCTestWDUITests-Runner.app_sparse.ipa
>> xctest-client.js:173:14 [master] pid:3493 please check project: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
>> xctest-client.js:172:14 [master] pid:3493 __MDMDirectoryDiff_block_invoke.37:1473 calling writeDictToFile with: /var/folders/tg/nr44b54n29g821rtyr8tr3540000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/XCTestWDUITests-Runner.app.ghDWUa/XCTestWDUITests-Runner.app_sparse.ipa/ManifestCache.plist
>> xctest-client.js:173:14 [master] pid:3493 please check project: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
>> xctest-client.js:172:14 [master] pid:3493 writeDictToFile:1278 ==== Successfully wrote Manifest cache to /var/folders/tg/nr44b54n29g821rtyr8tr3540000gn/C/com.apple.DeveloperTools/All/Xcode/EmbeddedAppDeltas/XCTestWDUITests-Runner.app.ghDWUa/XCTestWDUITests-Runner.app_sparse.ipa/ManifestCache.plist
>> xctest-client.js:173:14 [master] pid:3493 please check project: /usr/local/lib/node_modules/app-inspector/node_modules/xctestwd/XCTestWD/XCTestWD.xcodeproj
错误解决:
1) xctest client proxy error with: Error: socket hang up问题:
a)安装usbmuxd:brew install usbmuxd
b)命令行执行:iproxy 8900 8100(或者是8100 8100)
c)启动app-inspecter
若遇到其它问题,继续解决,直到可以正确编绎为止
建议:UnitTests、IntegrationTests 也如1)修改:Bundle id,添加Team,操作后最后再编绎 IntegrationApp