美文网首页python
Appium 自动化测试 <三、iOS 真机自动化测试与环

Appium 自动化测试 <三、iOS 真机自动化测试与环

作者: 自律改变现状 | 来源:发表于2019-04-11 14:29 被阅读69次

    本文是基于上两篇文章进行操作。
    Appium 自动化测试 <一、安装与 iOS 测试环境的搭建>
    Appium 自动化测试 <二、Appium 与 python 实现 iOS 模拟器自动化测试>

    一、Appium 真机运行与环境搭建

    1. 安装真机运行所需的依赖库--->真机配置官方文档
    终端安装 libimobiledevice

    brew install libimobiledevice --HEAD
    
    安装过程中报错
    hecking for libusbmuxd >= 1.1.0... no
    configure: error: Package requirements (libusbmuxd >= 1.1.0) were not met:
    
    Requested 'libusbmuxd >= 1.1.0' but version of libusbmuxd is 1.0.10
    
    # 参考 https://www.jianshu.com/p/1ec36db7d551
    
    brew update
    brew uninstall --ignore-dependencies libimobiledevice
    brew uninstall --ignore-dependencies usbmuxd
    brew install --HEAD usbmuxd
    brew unlink usbmuxd
    brew link usbmuxd
    brew install --HEAD libimobiledevice
    
    完了之后重新执行 brew install libimobiledevice --HEAD 这下安装成功了。
    
    

    安装 ios-deploy

    #如果是iOS10以上的系统才需要安装
    npm install -g ios-deploy 
    # 或
    brew install ios-deploy
    

    使用命令 appium-doctor --ios 查看是否安装成功


    2. 下载 WebDriverAgent 编译并安装在真机上。
    第一篇文章就已经下载编译过了,Xcode 打开 WebDriverAgent.xcodeproj 文件进行配置后编译.
    配置WebDriverAgentLib和WebDriverAgentRunner的证书

    选择 WebDriverAgentRunner , 连接并选择自己的iOS设备,然后按Cmd+U,或是点击Product->Test


    一切正常,手机上会出现一个无图标的 WebDriverAgent 应用,启动之后又闪退。这是正常现象。
    此时控制台界面可以看到设备的IP。
    拿到打印的IP地址加上/status合成一个url地址
    例如http://0.0.0.0:8100/status,然后浏览器打开。如果出现一串JSON输出,说明WDA安装成功了。
    我的手机并不能打开链接,需要做一个端口转发,将手机上的端口转发到Mac 上。
    打开终端

    # 前面已经安装过了这里就不在安装
    # brew install libimobiledevice
    # 输入命令
    iproxy 8100 8100
    

    执行完命令终端是这样的


    然后在 Mac 电脑浏览器上访问http://localhost:8100/status 确认WDA是否运行成功。

    3. 打开 Appium 启动 inspector session 界面设置所需功能。

    {
      "platformName": "iOS",
      "platformVersion": "12.0",
      "deviceName": "iPhone",
      "newCommandTimeout": "300",
      "bundleId": "BB.AppiumDemo",
      "onReset": true,
      "udid": "89a5d3d6132bae93a0d277aa14483346021b64d2",
      "xcodeOrgId": "AWWU3E4ZVG",
      "xcodeSigningId": "iPhone Developer",
      "automationName": "XCUITest"
    }
    

    相对了模拟器真机这里多了几个:
    udid = 使用iTunes软件查看UDID
    xcodeSigningId 固定填 iPhone Developer
    automationName = XCUITest
    xcodeOrgId = 开发者证书ID 可以从钥匙串中找证书,在显示简介


    启动成功后就会出现检查器界面


    二、Appium + python 真机自动化测试

    根据上篇文章的配置
    Appium 自动化测试 <二、Appium 与 python 实现 iOS 模拟器自动化测试>

    真机自动化测试只需要在添加4个参数就可以了:udid 、xcodeSigningId 、
    automationName 、xcodeOrgId。

    desired_caps = {
        "platformName": "iOS",
        "platformVersion": "12.0",
        "deviceName": "iPhone",
        "newCommandTimeout": "300",
        "bundleId": "BB.AppiumDemo",
        "onReset": True,
        "udid": "89a5d3d6132bae93a0d277aa14483346021b64d2",
        "xcodeOrgId": "AWWU3E4ZVG",
        "xcodeSigningId": "iPhone Developer",
        "automationName": "XCUITest"
    }
    

    运行py文件。


    补充 :
    运行py文件报错:
    "The file “WebDriverAgentRunner-Runner.app” couldn’t be opened because there is no such file."

    原因是 WebDriverAgentRunner 程序被我终止了,回到WebDriverAgent 项目,重新Cmd+U,在运行py文件就可以了

    相关文章

      网友评论

        本文标题:Appium 自动化测试 <三、iOS 真机自动化测试与环

        本文链接:https://www.haomeiwen.com/subject/doqtwqtx.html