天天看點

appium 下 python 腳本自動化測試iOS APP 執行個體

環境:Mac,Xcode, appium python

本文基于appium 環境搭建成功後。如何使用python 編寫腳本測試iOS APP

1.下載下傳python-client https://github.com/appium/python-client

2.在終端 打開到已經下載下傳的檔案目錄下執行 python setup.py install

3. 打開apppium 桌面版。點選 start session (host,port 不變,預設host 0.0.0.0 port: 4723)

4. 建立一個demo.py 檔案

5. 代碼如下:

‘import unittest

from appium import webdriver

from appium.webdriver.common.touch_action import TouchAction

desired_caps = {}

desired_caps[‘platformName’] = ‘iOS’

desired_caps[‘platformVersion’] = ‘10.3’

desired_caps[‘deviceName’] = ‘裝置名’

desired_caps[‘bundleId’] = ‘項目的bundleId’

desired_caps[‘udid’] = ‘測試手機的udid’

desired_caps[‘app’] = ‘/Users/xiaoMing/Desktop/testDemoipa/testDemo.ipa’ // 必須先将項目打包ipa,此處傳入ipa 路徑

driver = webdriver.Remote(‘http://localhost:4723/wd/hub‘, desired_caps)

el = driver.find_element_by_accessibility_id(‘Button’) // Button 是通過appium 采集到的對應按鈕的id

action = TouchAction(driver)

action.tap(el).perform() // 執行點選事件