zoukankan      html  css  js  c++  java
  • 6-3-1appium iOS

    环境准备

    • brew install carthage
    • npm i -g ios-deploy
    • brew install libimobiledevice --HEAD
    • brew install ideviceinstaller
    • 使用brew安装时,如果出现update home brew 直接control C退出更新

    iOS平台的特殊性:

    • 封闭
      • 系统封闭
      • 应用分发渠道封闭,仅限app store;
      • 软件和硬件绑定,例如iOS测试只能使用mac
    • 文档稀少 封闭导致的
    • 行业交流少,网上关于自动化测试的

    主流移动测试框架

    • Calabash-iOS 需要被测应用的源码才能测试
    • XCTest 苹果主推的,用的人少,但基于XCTest的框架却很多
    • Earl Grey && KIF 谷歌开发的单元测试框架,需要程序源码,基于XCTest
    • WebDriverAgent Facebook推出的,基于XCtest,不需要源码。WDA是一个http服务器。
    • Appium 是一个代理
    • Ui automation(在Xcode8后废弃)

    测试环境准备

    • 启动WDA
      • 切换到WebDriverAgent目录下,先执行bootstrap.sh脚本 ./Scripts/bootstrap.sh
      • Xcode打开WDA,product -test
    • iproxy 8100 8100
    • 启动Appium服务,使用放大镜Start Inspector Session
      • 在capability中输入以下配置,启动session
        {
          "platformName": "iOS",
          "automationName": "XCUITest",
          "usePrebuiltWDA": true,
          "deviceName": "iPhone",
          "udid": "",
          "bundleId": "",
          "newCommandTimeout":600
        }
    

    注意:
    1.查看应用的报名: ideviceinstaller -l
    2.查看本机IP: iconfig en0
    3.安装应用: ideviceinstall -i *.ipa
    4.查看手机udid: idevice_id -l
    5.启动时,要选择Automatic Server,不要选择Custom Server
    6.newCommandTimeout类型选择number,不要选择text。

    使用appium提供的工程测试

    appium提供的example:https://github.com/appium/ios-uicatalog
    打开终端,将代码克隆下来 git clone https://github.com/appium/ios-uicatalog
    xcode打开,product-run,将应用安装到手机
    也可以使用build将工程打成app,如果打成app,要查找app导出目录
    
    #python
    #coding:utf-8
    # This sample code uses the Appium python client
    # pip install Appium-Python-Client
    # Then you can paste this into a file and simply run with Python
    
    from appium import webdriver
    import time
    
    caps = {}
    caps["platformName"] = "iOS"
    caps["automationName"] = "XCUITest"
    caps["deviceName"] = "iPhone"
    caps["udid"] = "527a084d6010b8179658ddeb5295428d1973cfa6"
    caps["bundleId"] = "com.example.apple-samplecode.UICatalogcsj815379479"
    caps["newCommandTimeout"] = 600
    
    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    
    el1 = driver.find_element_by_xpath("(//XCUIElementTypeButton[@name="More Info"])[1]")
    el1.click()
    el2 = driver.find_element_by_accessibility_id("Okay / Cancel")
    time.sleep(2)
    el2.click()
    el3 = driver.find_element_by_accessibility_id("OK")
    try:
      assert el3.text=='OK','button not OK'
    except AssertionError as e:
      print(e)
    driver.quit()
    

    2. 使用Appium录制生成脚本

    recorder里为记录的脚本 ``` #python # This sample code uses the Appium python client # pip install Appium-Python-Client # Then you can paste this into a file and simply run with Python

    from appium import webdriver
    from time import sleep
    caps = {}
    caps["platformName"] = "iOS"
    caps["deviceName"] = "iphone"
    caps["bundleId"] = "com.taobaobj.moneyshield"
    caps["automationName"] = "XCUITest"
    caps["udid"] = "527a084d6010b8179658ddeb5295428d1973cfa6"
    caps["newCommandTimeout"] = "600"
    caps["usePrebuiltWDA"] = True

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    sleep(3)
    el1 = driver.find_element_by_accessibility_id("工具箱")
    el1.click()
    el2 = driver.find_element_by_accessibility_id("诈骗举报")
    el2.click()
    el3 = driver.find_element_by_xpath("//XCUIElementTypeStaticText[@name="电话诈骗举报"]")
    el3.click()
    el4 = driver.find_element_by_xpath("//XCUIElementTypeApplication[@name="钱盾"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeScrollView/XCUIElementTypeOther/XCUIElementTypeOther[1]")
    el4.send_keys("13693347586")
    el5 = driver.find_element_by_xpath("(//XCUIElementTypeImage[@name="radiobox_normal"])[3]")
    el5.click()
    el6 = driver.find_element_by_accessibility_id("请简要描述一下诈骗来电的内容,比如来电时间,对方特征,被骗方式等")

    el6.send_keys("骗子,大骗子")
    el7 = driver.find_element_by_accessibility_id("诈骗内容")
    el7.click()
    el8 = driver.find_element_by_accessibility_id("提交举报")
    el8.click()

  • 相关阅读:
    模块
    匿名函数
    推导式
    函数 重点
    新的
    知识点补充
    unity学习规划与进度
    暂停·笔记
    解决问题__max 模型白色 材质球换没用
    Max__cs骨骼
  • 原文地址:https://www.cnblogs.com/csj2018/p/9645903.html
Copyright © 2011-2022 走看看