オープンソースのクロスプラットフォーム自動テストツールとして、Appiumはネイティブまたはハイブリッドモバイルアプリのテストに適しています。WebDriverプロトコルを使用してIOS、Android、およびWindowsアプリケーションを駆動します。この記事では、ios自動テストの実装を紹介します。
01
AppiumはiOS自動テストを実装しています
01
アプリを起動します
機能情報を入力します
アプリを取得
uuid get
[ウィンドウ]---->[デバイス]->[右側に識別子IDが表示されます。これは、入手したiPhoneのUIDです]をクリックします。
02
要素を取得します
pycharmによって書かれたコードで開く
時間からインポートスリープ
appiumインポートWebドライバーから
キャップ={}
#platformバージョン
caps [“ platformName”] =“ iOS”
xcodeを介したAPP情報
caps [“ app”] =“ Users / hanxingyuan / Library / Developer / Xcode / DerivedData / UICatalog- elvxjsgcreylppcxqfmmfzwuujpo / Build / Products / Debug-iphonesimulator / UICatalog.app”
#装置名
caps [“ deviceName”] =“ iPhone X”
#デバイスバージョン
caps [“ platformVersion”] =“ 12.1”
#uuidはxcodeを通過します
caps ['uuid'] = '4A8743D2-501D-42B6-A20D-14901A5BE61B'
#ドライバーオブジェクトを作成する
driver = webdriver.Remote(“ http://127.0.0.1:4723/wd/hub”、caps)
5秒待つ
driver.implicitly_wait(5)
要件:最初のスクリプトで、[アクションシート]をクリックします-[OK]をクリックします
時間からインポートスリープ
appiumインポートWebドライバーから
キャップ={}
プラットフォームバージョン
caps [“ platformName”] =“ iOS”
xcodeを介したAPP情報
caps [“ app”] =“ Users / hanxingyuan / Library / Developer / Xcode / DerivedData / UICatalog- elvxjsgcreylppcxqfmmfzwuujpo / Build / Products / Debug-iphonesimulator / UICatalog.app”
#装置名
caps [“ deviceName”] =“ iPhone X”
#デバイスバージョン
caps [“ platformVersion”] =“ 12.1”
#uuidはxcodeを通過します
caps ['uuid'] = '4A8743D2-501D-42B6-A20D-14901A5BE61B'
#ドライバーオブジェクトを作成する
driver = webdriver.Remote(“ http://127.0.0.1:4723/wd/hub”、caps)
5秒待つ
driver.implicitly_wait(5)
#アクションシートをクリック
driver.find_element_by_xpath('(// XCUIElementTypeButton [@ name =“ More Info”])[1]').click()
#click ok
driver.find_element_by_xpath('// XCUIElementTypeStaticText [@ name =“ OK / Cancel”]').click()
1.iosポジショニングメソッド
ios_predicate
iOSのUIオートメーションでは、要素の単一属性と複数属性の配置をサポートできる、ネイティブにサポートされている述語配置方法を使用するのが最適であり、使用することを強くお勧めします
driver.find_element_by_ios_predicate(“ value =='ClearEmail'”)
driver.find_element_by_ios_predicate(“ type =='' AND value =='')
アクセシビリティ_id
以前の名前の配置方法の代わりに、iOSでは、要素のラベルまたは名前属性(両方の属性の値が同じ)が主に配置に使用されます。属性が空の場合、この属性は使用できません。
driver.find_element_by_accessibility_id('ClearEmail')
xpath
iOS 10で使用されるXCUITestフレームワークはネイティブにサポートされておらず、測位速度が非常に遅いため、現在、公式はすべての人にそれを推奨していません。また、使用できる他の代替測位方法があります。
絶対パスポジショニングを使用する
driver.find_element_by_xpath('/ XCUIElementTypeApplication / XCUIElementTypeButton')
相対パスポジショニングを使用します。
driver.find_element_by_xpath('// XCUIElementTypeButton')
要素のインデックスで検索
driver.find_element_by_xpath('// XCUIElementTypeButton [index]')
要素の属性を介した検索
driver.find_element_by_xpath(” // className [@ value ='ClearEmail'] ")
iOSNsPredicateString
iOS 10以降のみをサポートし、要素の単一属性および複数属性の配置をサポートできます。これをお勧めします。
プロパティ:MobileBy.iOSNsPredicateString( "type =='XCUIElementTypeButton'")
2つのプロパティ:MobileBy.iOSNsPredicateString( "type =='XCUIElementTypeButton' AND label =='詳細'")
上記のポジショニング方法は基本的にAndroidと同じであり、iOSの特別なポジショニング方法PredicateString、要件:検索バーをクリック-[デフォルト]をクリック-入力ボックスをクリック-入力コンテンツをクリック
2.pycharmはデフォルトのエグゼキュータを設定します
コード:
appiumからインポートwebdriver
インポート時間
selenium.webdriver.support.uiからインポートWebDriverWait
セレンインポートWebドライバーから
クラスTestDemo:
def setup(self):
キャップ={}
caps["platformName"] = "iOS"
caps["app"] = "Users/hanxingyuan/Library/Developer/Xcode/DerivedData/UICatalog- elvxjsgcreylppcxqfmmfzwuujpo/Build/Products/Debug-iphonesimulator/UICatalog.app"
#
caps [“ automationName”] =“ xcuitest”
caps["deviceName"] = "iPhone X"
caps["platformVersion"] = "12.1"
caps['uuid'] = '4A8743D2-501D-42B6-A20D-14901A5BE61B'
caps['startIWDP'] = True
self.driver = webdriver.Remote(“ http://127.0.0.1:4723/wd/hub”、caps)
self.driver.implicitly_wait(5)
スライディング方式
def swipe_view(self):
size = self.driver.get_window_size()
self.driver.swipe(size['width'] * 0.5, size['height'] * 0.75,size['width'] * 0.75, size['height'] * 0.25, 3000)
def test_search(self):
self.swipe_view()
点击 search Bars
self.driver.find_element_by_accessibility_id('Search Bars').click()
# 点击Default
self.driver.find_element_by_accessibility_id('Default').click()
iOS10サポートタイプを超えるオペレーティングシステム=="XCUIElementTypeSearchField"
#入力ボックスをクリックします
self.driver.find_element_by_ios_predicate('type ==“ XCUIElementTypeSearchField”')。click()
time.sleep(4)
クリックして入力
self.driver.find_element_by_accessibility_id('L')。click()
time.sleep(4)
self.driver.find_element_by_accessibility_id('g')。click()
time.sleep(4)
print(self.driver.find_element_by_ios_predicate('value ==“ Lg”')。text)