• Appium-doctor 检测Xcode未安装问题


           最近在闲暇之余想学习一下手机自动化,在网上查看了一下相关的文档,最终决定学习Appium。这学习任何东西首先就是要配置环境,于是找到了一篇文章(http://www.2cto.com/kf/201404/293681.html),按上面的步骤一步步地安装。中间没有出现任何问题,可是到了最后检测安装情况的时候,运行appium-doctor检测时,却出现了“Xcode is not installed.”的错误提示。可是不应该啊,我已经安装过xcode了,这不科学!

           于是就上网上查询解决办法,可是网上都是说如何搭建appium环境的,要么就是如何编写测试用例的,没有可用的办法。实在没有办法了,只好去查看出appium-doctor文件了,看一下它是如何检测的。

    问题排查

    (1)查看appium-doctor文件,查找mac系统中环境检测的代码。

    #vi appium-doctor

    发现代码里判断IOS相关的是有一个js文件来完成的,具体路径是:../lib/doctor/ios.js

    (2)检测ios.js文件

    经查找,发现ios.js文件在以下路径中:

    /usr/local/lib/node_modules/appium/lib/doctor/ios.js

    打开这个文件,找到如下代码: 

    IOSChecker.prototype.checkForXcode function (cb) {
      var msg;
      exec("xcode-select --print-path", maxBuffer524288}, function (err, stdout) {
        if (err === null) {
          var xcodePath stdout.replace(" ", "");
          if (fs.existsSync(xcodePath)) {
            this.log.pass("Xcode is installed at xcodePath, cb);
          else {
            msg "Xcode is not installed.";
            this.log.fail(msg);
            this.log.promptToFix("Xcode is not installed.", function () {
              this.installXcode(cb);
            }.bind(this), function () {
              cb(msg, msg);
            });
          }
        else {
          msg "Xcode is not installed: err;
          this.log.fail(msg);
          this.log.promptToFix("Xcode is not installed.", function () {
            this.installXcode(cb);
          }.bind(this), function () {
            cb(msg, msg);
          });
        }
      }.bind(this));

    在这段代码中有输出“Xcode is not installed”,所以问题应该在这段代码中。

       于是添加调试信息 this.log.fail(msg),将需要查看的信息打印出来。

    (3)问题分析:

    A, xcode-select --print-path在终端执行的结果是/Developer,应该是Xcode的一个路径。

    B,fs.existsSync(xcodePath)返回结果为False,查看了一下existsSync()函数的功能,是node.js的一个判断文件或路径是否存在的意思。

    C,根据上述分析,应该是Xcode的路径不正确,于是查看了一下/Developer,果然没有这个文件夹。

    D,查找我本机Xcode安装的路径,得到如下信息:

    我本机的Developer文件夹应该在:/Applications/Xcode.app/Contents/Developer.

    E,现在需要把Xcode的路径设置成这个才对,于是查看了一下xcode-select命令的用法:

    bash-3.2# xcode-select

    Usage: xcode-select -print-path

       or: xcode-select -switch

       or: xcode-select -version

    Arguments:

       -print-path                     Prints the path of the current Xcode folder

       -switch      Sets the path for the current Xcode folder

       -version                        Prints xcode-select version information

    -switch参数就是切换命令,执行下面的命令:

    bash-3.2# xcode-select –switch /Applications/Xcode.app/Contents/Developer.

    (4)环境检测

    经上面的一系列操作后,再次检测环境是否配置完成:

    bash-3.2# appium-doctor
    Running iOS Checks
     Xcode is installed at /Applications/Xcode.app/Contents/Developer
     Xcode Command Line Tools are installed.
     DevToolsSecurity is enabled.
     The Authorization DB is set up properly.
     Node binary found at /usr/local/bin/node
     iOS Checks were successful.

    如上信息显示,Appium ios测试环境安装环境。

    ----夫英雄者,胸怀大志,腹有良谋,有包藏宇宙之机,吞吐天地之志者也。
  • 相关阅读:
    巧妙使用栈结构,解决面试中的算法问题
    还在为兼容性测试发愁?让我们用Python来轻松搞定吧
    天天使用Appium,但是你真的理解Appium的工作原理吗
    学会这些Jmeter插件,才能设计出复杂性能测试场景
    Dubbo接口不知道怎么测?教你三行代码实现dubbo接口测试
    Python接口自动化必知必会Requests库
    是时候升级你的Junit了,Junit5超详细实战
    486. 预测赢家
    309. 最佳买卖股票时机含冷冻期 (无限次买入+买入有1天冷冻期)
    347. 前 K 个高频元素 (优先队列 c++)
  • 原文地址:https://www.cnblogs.com/eagleking0318/p/6521017.html
Copyright © 2020-2023  润新知