让Appium支持xcdoe6及其以上版本

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">Appium是个新东西,支持原生的APP自动化测试,基于Android和iOS提供的SDK,最近apple发布了最新的Xcode,今天不小心更新了,再次使用appium的inspector时各种报错,于是一步步的进行修改源码。</span>

由于Xcode6修改了模拟器的路径,所以导致其定位出现问题,大家只要修改ios.js即可。将该文件下载后直接替换即可。


对于dmg文件安装的Appium其路径应该是:
/Applications/Appium.app/Contents/Resources/node_modules/appium/lib/devices/ios


如果是通过brew安装的,其路径应该是:

/usr/local/lib/node_modules/appium/lib/devices/ios


修改方法如下:

总共修改三个函数,IOS.prototype.detectTraceTemplate,IOS.prototype.setDeviceAndLaunchSimulator,IOS.prototype.getDeviceString

下面依次介绍:

detectTraceTemplate,定位模拟器,加一层判断即可

修改前:

var xcodeTraceTemplatePath = path.resolve(xcodeFolderPath,
          "../Applications/Instruments.app/Contents/PlugIns",
          "AutomationInstrument.bundle/Contents/Resources",
          "Automation.tracetemplate");

修改后:

if (this.iOSSDKVersion >= 8.0){
	  var xcodeTraceTemplatePath = path.resolve(xcodeFolderPath,
          "../Applications/Instruments.app/Contents/PlugIns",
          "AutomationInstrument.xrplugin/Contents/Resources",
          "Automation.tracetemplate"); 
	}else{
	  var xcodeTraceTemplatePath = path.resolve(xcodeFolderPath,
          "../Applications/Instruments.app/Contents/PlugIns",
          "AutomationInstrument.bundle/Contents/Resources",
          "Automation.tracetemplate");
	}

setDeviceAndLaunchSimulator,设置模拟器,同样是加一层判断

修改前:

var iosSimPath = path.resolve(this.xcodeFolder, "Platforms/iPhoneSimulator.platform/Developer/Applications" +
        "/iPhone Simulator.app/Contents/MacOS/iPhone Simulator");

修改后:

if(this.iOSSDKVersion >= 8.0){
      var iosSimPath = path.resolve(this.xcodeFolder, "Applications" +
        "/iOS Simulator.app/Contents/MacOS/iOS Simulator");
    }else{
      var iosSimPath = path.resolve(this.xcodeFolder, "Platforms/iPhoneSimulator.platform/Developer/Applications" +
        "/iPhone Simulator.app/Contents/MacOS/iPhone Simulator");
    }

getDeviceString,得到最终调用的模拟器的字符串,决定了版本和平台,增加一个session类型

修改前:

var CONFIG_FIX = {
      'iPhone - Simulator - iOS 7.1': 'iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1',
      'iPad - Simulator - iOS 7.1': 'iPad Retina (64-bit) - Simulator - iOS 7.1'
    };


修改后:

var CONFIG_FIX = {
      'iPhone - Simulator - iOS 7.1': 'iPhone Retina (4-inch 64-bit) - Simulator - iOS 7.1',
      'iPad - Simulator - iOS 7.1': 'iPad Retina (64-bit) - Simulator - iOS 7.1',
      'iPhone - Simulator - iOS 8.0':'iPhone 5 (8.0 Simulator) [115FA3C5-C872-4890-B52E-E66198AE0347]'
    };

这个地方有多个选择,你可以把所有版本的模拟器都加进去,这个我就不演示了!

Xcode6的所有模拟器版本如下:

["iPad 2 (8.0 Simulator) [26104C23-7E2E-4420-ACDD-CBD3BF897135]","iPad Air (8.0 Simulator) [A537E2A7-C17F-47D6-88BD-603890D4192A]","iPad Retina (8.0 Simulator) [DDE4A7FB-9D01-4EB5-B626-9B015E38A11A]","iPhone 4s (8.0 Simulator) [168868E6-7D82-42EA-9165-3463A6B29D44]","iPhone 5 (8.0 Simulator) [115FA3C5-C872-4890-B52E-E66198AE0347]","iPhone 5s (8.0 Simulator) [01DA0B1D-00C1-46D9-A1B2-7B5A844BCE53]","iPhone 6 (8.0 Simulator) [A1B88000-B813-4C07-8A7E-A12C57FF175F]","iPhone 6 Plus (8.0 Simulator) [9683736E-2429-4BDD-914A-9E6B76A3E0ED]"]

增加的时候,注意key值的指定,例如,我只增加了一个键“iPhone - Simulator - iOS 8.0“,这样在对应deviceName时,就对应了iPhone,并且,platform version 对应了8.0

设置截图


注意,上面的截图中,Force Device 直接填写 “iPhone”就可以,但是Platform Version 必须填写“8.0”,不要选择下来按钮了,因为里面最大的就是7.1.


最后,以上方法只是在不重新编译github上的Appium源码的情况下,做了一下适配而已,大牛们,可以自己把源码下载下来,修改一下源码再重新编译一下就OK了。

本人菜鸟,不太懂object-c,在官网下载了源码后,用Xcode编译时,有好几处报错,头文件中好像缺少了几个声明,懒得改了,所以就偷懒了,直接改的js文件。

如果有大牛重新编译了,麻烦分享一下,哈哈!

如果,不想自己修改,可以直接去下载我上传的js文件,在这里

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值