通過上一章節,open application關鍵字的使用,相信大家對手機自動化充滿了興趣,那么今天這一章節,主要介紹AppiumLibrary中常用關鍵字的使用。
一、實用函數
關鍵字 |
含義 |
實例 |
備注 |
Click Button |
點擊按鈕 |
Click Button 注銷 |
這里“注銷”的class屬性,必須是Button |
Click Element |
點擊元素 |
Click Element [locator] |
Locator可以是resource-id,也可以是xpath;但必須是當前頁面唯一存在的;一般用該關鍵字可以完成所有元素點擊 |
Click Text |
點擊文字 |
Click Text 我的 |
“我的”需要是當前頁面唯一存在的 |
Input Text |
在指定元素中輸入文本 |
InputText [locator] 111111 |
Locator可以是resource-id,也可以是xpath |
Swipe |
滑動屏幕 |
Swipe 1000 1800 100 1800
|
|
Get Text |
獲取某標簽內容 |
${account} Get Text [locator] |
獲取內容后存儲到指定變量中,從而在后續腳本中調用該內容 |
二、校驗函數
關鍵字 |
含義 |
實例 |
備注 |
Element Name Should Be |
檢查元素的name屬性
|
Element Name Should Be [locator] 登錄 |
locator可以是resource-id,也可以是xpath |
Element Should Be Enabled |
檢查元素是否可用/可見 |
Element Should Be Enabled [locator] |
|
Page Should Contain Element |
檢查界面包含某些元素 |
Page Should Contain Element [locator] |
|
Page Should Contain Text |
檢查界面包含某些文字信息 |
Page Should Contain Text 預約掛號 |
|
Page Should Not Contain Element |
檢查界面不包含某些元素 |
Page Should Not Contain Element [locator] |
|
Page Should Not Contain Text |
檢查界面不包含某些文字信息 |
Page Should Not Contain Text 預約掛號 |
|
三、等待函數
關鍵字 |
含義 |
實例 |
備注 |
Wait Until Page Contains |
等待直到界面中包含某些文字,才進行下一步 |
Wait Until Page Contains 預約掛號 |
默認等待時間為5s |
Wait Until Page Contains Element |
等待直到界面中包含某些元素,才進行下一步 |
Wait Until Page Contains Element [locator] |
locator可以是resource-id,也可以是xpath |
Wait Until Page Does Not Contain |
等待直到界面中不包含某些文字,才進行下一步 |
Wait Until Page Does Not Contain 預約掛號 |
|
Wait Until Page Does Not Contain Element
|
等待直到界面中不包含某些元素,才進行下一步 |
Wait Until Page Does Not Contain Element [locator]
|
|
四、其他函數
1.條件判斷函數
關鍵字:Run Keyword If
用法:
Run Keyword If
…ELSE IF
…ELSE
實例:
1)用Run Keyword If執行單條語句時
2)用Run Keyword If執行多條語句時,在需要執行多條語句的if或else if或else后,增加關鍵字:Run Keywords
2.檢查某關鍵字的返回狀態
關鍵字:Run Keyword And Return Status
返回值:布爾值,True False
實例 :通常和Run Keyword If關鍵字搭配使用
${isMessage} | Run Keyword And Return Status | Wait Until Page Contains Element | [locator] |
Run Keyword If | ${isMessage} | do something |
含義 :判斷當前界面中是否存在取消按鈕;如果存在,則do something
3.For循環
關鍵字:For
實例:
1)For循環單獨使用時
2)For循環嵌套Run Keyword If語句,退出循環
4.自定義關鍵字
創建方法:測試項目-New Resource-New User Keyword
實例:
在需要使用自定義關鍵字的測試套件Edit標簽頁,Resource導入關鍵字,導入結果為藍色,則導入正確
用法:導入resource后,在測試用例中,直接調用
常用關鍵字就介紹到這里。
文章列表