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。python

使用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"] = Trueios

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("請簡要描述一下詐騙來電的內容,好比來電時間,對方特徵,被騙方式等")git

el6.send_keys("騙子,大騙子")
el7 = driver.find_element_by_accessibility_id("詐騙內容")
el7.click()
el8 = driver.find_element_by_accessibility_id("提交舉報")
el8.click()github

相關文章
相關標籤/搜索