Appium [已解决]IOS 无法启动_inspector_1.3.4_Xcode6.1_10.10

Vincent · 2015年01月07日 · 最后由 恒温 回复于 2016年03月21日 · 2115 次阅读

谢谢大家,最近在学习 IOS 的 Appium,在最新的版本和环境上无法启动 inspector,提示的错误也很费解如下:

error: Failed to start an Appium session, err was: Error: Could not find a device to launch. You requested 'iPhone 5s (449AC674-9FB8-431E-8617-846161A5587B) (8.1 Simulator)', but the available devices were: ["iPad 2 (8.1 Simulator) [AF06F02D-230E-498C-BE43-AD9F9A752D1B]","iPad Air (8.1 Simulator) [70E8C80C-C125-4F86-9FF2-3C333B6CB9B9]","iPad Retina (8.1 Simulator) [527B469C-9F55-4105-B50A-472387A0C374]","iPhone 4s (8.1 Simulator) [9C0101B8-78F1-44DD-AB8D-B5121B4143D2]","iPhone 5 (8.1 Simulator) [EDB96171-ED64-4AAB-BC47-09968149F726]","iPhone 5s (8.1 Simulator) [449AC674-9FB8-431E-8617-846161A5587B]","iPhone 6 (8.1 Simulator) [7D28AC65-D4B3-4FFD-957A-CF2DDFC69D21]","iPhone 6 Plus (8.1 Simulator) [B0F7D960-4FEB-4BA0-8B38-97ED5A6C7825]"]

这个错误中提到我的模拟器无法启动,但是在它给予的提示中,又包含了我所使用的模拟器 ID,搜寻了许久还是没有得到答案,请大家帮忙看看,任何想法或者思路都欢迎提供,谢谢!

共收到 7 条回复 时间 点赞

Error: Could not find a device to launch. You requested 'iPhone 5s (449AC674-9FB8-431E-8617-846161A5587B) (8.1 Simulator)',

又是一个看不懂日志的同学。这是因为你选择了 iPhone 5s (449AC674-9FB8-431E-8617-846161A5587B) 。
然后呢, appium 的 ios.js 里面傻 x 的代码,给你加了一个 (8.1 Simulator)。 然后在你的 instruments -s device 里面返回的一个 devices 数组,一个个去匹配。 结果你返回的是没有 (8.1 Simulator) 的,所以都对不上。这些就悲剧了。所以你就来问问题了。给你看看代码:

这个是加 (8.1 Simulator)

var reqVersion = opts.platformVersion || opts.iOSSDKVersion;
  if (opts.iOSSDKVersion >= 8) {
    iosDeviceString += " (" + reqVersion + " Simulator)";
  }

整个函数是这样的:

IOS.getDeviceStringFromOpts = function (opts) {
  logger.debug("Getting device string from opts: " + JSON.stringify({
    forceIphone: opts.forceIphone,
    forceIpad: opts.forceIpad,
    xcodeVersion: opts.xcodeVersion,
    iOSSDKVersion: opts.iOSSDKVersion,
    deviceName: opts.deviceName,
    platformVersion: opts.platformVersion
  }));
  var isiPhone = opts.forceIphone || opts.forceIpad === null || (opts.forceIpad !== null && !opts.forceIpad);
  var isTall = isiPhone;
  var isRetina = opts.xcodeVersion[0] !== '4';
  var is64bit = false;
  var deviceName = opts.deviceName;
  var fixDevice = true;
  if (deviceName && deviceName[0] === '=') {
    return deviceName.substring(1);
  }
  logger.debug("fixDevice is " + (fixDevice ? "on" : "off"));
  if (deviceName) {
    var device = deviceName.toLowerCase();
    if (device.indexOf("iphone") !== -1) {
      isiPhone = true;
    } else if (device.indexOf("ipad") !== -1) {
      isiPhone = false;
    }
    if (deviceName !== opts.platformName) {
      isTall = isiPhone && (device.indexOf("4-inch") !== -1);
      isRetina =  (device.indexOf("retina") !== -1);
      is64bit = (device.indexOf("64-bit") !== -1);
    }
  }

  var iosDeviceString = isiPhone ? "iPhone" : "iPad";
  if (opts.xcodeVersion[0] === '4') {
    if (isiPhone && isRetina) {
      iosDeviceString += isTall ? " (Retina 4-inch)" : " (Retina 3.5-inch)";
    } else {
      iosDeviceString += isRetina ? " (Retina)" : "";
    }
  } else if (opts.xcodeVersion[0] === '5') {
    iosDeviceString += isRetina ? " Retina" : "";
    if (isiPhone) {
      if (isRetina && isTall) {
        iosDeviceString += is64bit ? " (4-inch 64-bit)" : " (4-inch)";
      } else if (deviceName.toLowerCase().indexOf("3.5") !== -1) {
        iosDeviceString += " (3.5-inch)";
      }
    } else {
      iosDeviceString += is64bit ? " (64-bit)" : "";
    }
  } else if (opts.xcodeVersion[0] === '6') {
    iosDeviceString = opts.deviceName ||
      (isiPhone ? "iPhone Simulator" : "iPad Simulator");
  }
  var reqVersion = opts.platformVersion || opts.iOSSDKVersion;
  if (opts.iOSSDKVersion >= 8) {
    iosDeviceString += " (" + reqVersion + " Simulator)";
  } else if (opts.iOSSDKVersion >= 7.1) {
    iosDeviceString += " - Simulator - iOS " + reqVersion;
  }
  if (fixDevice) {
    // Some device config are broken in 5.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',
      'iPad Simulator (8.0 Simulator)': 'iPad 2 (8.0 Simulator)',
      'iPad Simulator (8.1 Simulator)': 'iPad 2 (8.1 Simulator)',
      'iPad Simulator (8.2 Simulator)': 'iPad 2 (8.2 Simulator)',
      'iPad Simulator (7.1 Simulator)': 'iPad 2 (7.1 Simulator)',
      'iPhone Simulator (8.2 Simulator)': 'iPhone 6 (8.2 Simulator)',
      'iPhone Simulator (8.1 Simulator)': 'iPhone 6 (8.1 Simulator)',
      'iPhone Simulator (8.0 Simulator)': 'iPhone 6 (8.0 Simulator)',
      'iPhone Simulator (7.1 Simulator)': 'iPhone 5s (7.1 Simulator)'
    };
    if (CONFIG_FIX[iosDeviceString]) {
      var oldDeviceString = iosDeviceString;
      iosDeviceString = CONFIG_FIX[iosDeviceString];
      logger.debug("Fixing device. Changed from: \"" + oldDeviceString +
                   "\" to: \"" + iosDeviceString + "\"");
    }
  }
  logger.debug("Final device string is: '" + iosDeviceString + "'");
  return iosDeviceString;
};

所以,基本上你只要在 Force Device 那里扔个字符串 iPhone 就可以了。

谢谢 果然如此, 但还需要加上 iPhone 的型号 比如 iPhone 5S 就好。

#1 楼 @lihuazhang 需要被测手机的对应虚拟机下载好了才能跑起来吗?

#1 楼 @lihuazhang 找遍整个目录,没找到这个 ios.js。Appium 1.5 版本的。确实是因为加的字段不对。。。

#4 楼 @da_sheng 1.5 模块化了。代码在依赖的模块中。

#5 楼 @lihuazhang 那我再找找吧

#6 楼 @da_sheng 你直接填写好了 不一定要下拉选择啊

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册