mac下ios自動化測試,可以使用appium,也可以直接用facebook-wda庫。
此篇先介紹appium:
開始之前先要知道測試app的bundleId,這是ios特有的。可以采用如下命令:
ideviceinstaller -l
遇到問題:
Could not connect to lockdownd. Exiting.
解決辦法:
打開命令行一次輸入如下代碼:
brew uninstall ideviceinstaller -g
brew uninstall libimobiledevice -g
brew install --HEAD libimobiledevice -g
brew install ideviceinstaller -g
sudo chmod -R 777 /var/db/lockdown
問題解決。
如果還有問題
brew install --HEAD ios-webkit-debug-proxy -g
brew install ios-webkit-debug-proxy -g
當然如果上述還是沒有解決你的問題那么下面的絕對能解決:
brew uninstall -f libimobiledevice ideviceinstaller usbmuxd
brew install -v --HEAD --fresh --build-from-source usbmuxd libimobiledevice ideviceinstaller
第1步:開啟server端
前一篇有介紹,我是安裝的命令行版,采用命令行啟動:
/usr/local/bin/appium -a 127.0.0.1 -p 4723 -bp 4724
第2步:運行測試腳本
如下實例:
#! /usr/bin/env python #coding=utf-8 import time,os from appium import webdriver from appium.webdriver.common.touch_action import TouchAction driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={ 'bundleId': 'com.lifesense.LSWearable.iusexxx', 'platformName': 'iOS', 'platformVersion': '10.3', 'deviceName': 'sandyiPhone', "automationName": "XCUITest", "noReset": False, "udid": "11c7b654ae4c7b1bb43d456c5e5e7fxxxxxxxx" }) time.sleep(5) driver.find_element_by_name("請輸入手機號碼").send_keys("13148536426") driver.tap([(30,95),[30,98]],500) driver.find_element_by_accessibility_id("賬號密碼登錄").click() #el2.click() el3 = driver.find_element_by_xpath( "//XCUIElementTypeApplication[XCUIElementTypeSecureTextField") el3.send_keys("123456") driver.tap([(30,95),[30,98]],500) el4 = driver.find_element_by_accessibility_id("登錄") el4.click()
元素定位請參考inspector使用篇