Xcode9.0+appium1.6.5真机环境运行app及遇坑知多少

来源:互联网 发布:济南大学网络教学平台 编辑:程序博客网 时间:2024/06/05 20:08

Mac下把appium自动化环境搭建好后,进行真机测试时会碰到相当多的坑,

 

下面给大家一一列出来并附上解决方法。

 

一、selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not initialize ideviceinstaller; make sure it is installed and works on your system

 

这是没有安装ideviceinstaller导致。

 

解决方法:

1.解决方法在终端执行,先安装brew

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

 

2.装好brew后,在执行下面指令装ideviceinstaller:

 

brew install  ideviceinstaller

 

二、

selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find Automation.tracetemplate in any of the followinglocations /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate,/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate

 

报错原因是没有安装Automation.tracetemplate模块。我用的是appium1.5.3 、Xcode8。

Xcode8移除了UI Automation

 

解决方法:

装个桌面版的appium 1.6.5可以解决这个问题。到我的网盘下载。

链接:http://pan.baidu.com/s/1qYPYGd2  密码:f2o7

 

查看自带的appium-xcuitest-driver版本,npm list查看,版本如果不是2.5.3或更新请卸载再装(自带的版本太老会导致app launch不起来,一直在等待)

卸载:npm uninstall appium-xcuitest-driver

安装:npm install appium-xcuitest-driver@2.5.3

 

三、通过指令安装brew install libimobiledevice

四、通过指令安装npm install -g ios-deploy

 

不安装会报以下错误:

[XCUITest] Could notinitialize ios-deploy make sure it is installed and works on your system

五、指令安装gem install xcpretty这可以使xcode输出更合理

六、 指令安装npm i -g webpack 

 

这和WebDriverAgent相关,没有这个 会报错:Unable to create new remotesession

 

七、selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Unable to launch WebDriverAgent because of xcodebuild failure: xcodebuild failed with code 65

 

WebDriverAgent报错,需要安装。

解决方法:

1.必须先安装Carthage,执行指令:brew installCarthage

 

2.安装WebDriverAgent:

ž   cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent(自己的appium路径在哪就去哪找)

先执行mkdir -pResources/WebDriverAgent.bundle

再执行sh ./Scripts/bootstrap.sh(执行这个指令前最好链接vpn不然等待非常久)

ž   编译WebDriverAgent.xcodeproj(以上这个是安装自带的,大家不要装

 

自带的webdriveragent有问题,自己下一个,不然用自带的在xcode上编译报各种错误。。。搞死你。。。。 我这里被折腾了1天多。。。。各种百度各种谷歌。按下面解决:

ž   cd ~

ž  git clone https://github.com/facebook/WebDriverAgent.git

ž  cd WebDriverAgent

ž  mkdir -p Resources/WebDriverAgent.bundle

ž   sh ./Scripts/bootstrap.sh

ž   然后进入到appium-xcuitest-driver路径

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

ž  rm –rf WebDriverAgent(移除自带的,当然如果没有安装自带的就不用执行这个指令)

ž  ln –s ~/WebDriverAgent WebDriverAgent(引用自己下载的webdriveragent)

ž   编译WebDriverAgent.xcodeproj

编译要修改的地方:

1.   在xcode添加开发者账号:


2.   设置WebDriverAgentLib-General选项:


3.   设置WebDriverAgentLib-Build Settings选项


这里面的Product Bundle Identifler一定要改一下,不能完全一样。可以把facebook改成自己的名字拼音

 

4.   设置WebDriverAgentRunner---General和Build Settings选项

和设置webdriveragentlig的一样,就不截图。

1.   General里选择signing里勾选Automatically manage signing选项,并且选上自己的开发账号。

 

2.   Build Settings里修改一下Bundle Identifier的名称即可。

 

 

接下来就是连接真机编译,真机编译后要安装到手机,安装到手机有两种方法:

一、用指令

 cd /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent

执行:

    xcodebuild -projectWebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'id=真机的udid'test

 

二、在Xcode里面执行test安装

 

安装过程会王手机里安装一个webdriveragent的app,无图标,打开一般都是黑色。

安装过程会出现自动打开和退出这个app的现象。

之后就可以运行python代码了。

 

注:如果按以上执行还不行就换个usb口,小的就是换了个usb口就可以运行真机上的app了。切记切记!!

 

QQ交流群610845268

原创粉丝点击