1. 程式人生 > >AppiumLibrary用戶關鍵字

AppiumLibrary用戶關鍵字

鍵盤 capture password ide 另一個 系統變量 orm example about

*** Settings ***
Library           AppiumLibrary
Library           AutoItLibrary
Library           os

*** Keywords ***
xpath應該匹配次數
    [Arguments]    ${xpath}    ${count}
    Xpath Should Match X Times    ${xpath}    ${count}

上傳文件
    [Arguments]    ${path}    ${data}    ${encode}=base64
    Push File    ${path}    ${data}    ${encode}

元素不應該包含文本
    [Arguments]    ${locator}    ${expected}    ${msg}
= Element Should not Contain Text ${locator} ${expected} ${msg} 元素值應該是 [Arguments] ${locator} ${expected} Element Value Should Be ${locator} ${expected} 元素名應該是 [Arguments] ${path} ${name} Element Name Should Be ${path} ${name} 元素屬性應該匹配 [Arguments] ${locator} ${attr_name} ${match_pattern} ${regx}
=False Element Attribute Should Match ${locator} ${attr_name} ${match_pattern} ${regx} 元素應該包含文本 [Arguments] ${locator} ${expected} ${msg}=None Element Should Contain Text ${locator} ${expected} ${msg} 元素應該失效 [Arguments] ${locator} ${level}=INFO Element should be disabled ${locator} ${level} 元素應該有效 [Arguments] ${locator} ${level}
=INFO Element should be enabled ${locator} ${level} 元素文本應該是 [Arguments] ${locator} ${expected} ${msg}=None Element Text Should Be ${locator} ${expected} ${msg} 關閉當前應用 Close Application 關閉所有應用 Close All Applications 切換應用 [Arguments] ${index_or_alias} Switch Application ${index_or_alias} 切換頁面內容 [Arguments] ${webview} Switch To Context ${webview} 卸載應用 [Arguments] ${application_id} Remove Application ${application_id} 後臺運行 [Arguments] ${sec} Background App ${sec} 向上滾動 [Arguments] ${locator} Scroll Up ${locator} 向下滾動 [Arguments] ${locator} Scroll Down ${locator} 失敗後運行關鍵字 [Arguments] ${keyword} [Documentation] Example: # Disables run-on-failure functionality and stores the previous kw name in a variable. # Restore to the previous keyword. ... ... Register Keyword To Run On Failure \ \ \ Log Source ... \ \ \ \ \ \ \ # Run `Log Source` on failure. ... ... ${previous kw}= ... Register Keyword To Run On Failure \ \ Nothing ... ... ... Register Keyword To Run On Failure \ \ \ \ ${previous kw} \ \ \ Register Keyword To Run On Failure ${keyword} 打印資源 [Arguments] ${level} Log Source ${level} 打開URL [Arguments] ${url} [Documentation] Example: ... ... 打開應用 ... http://localhost:4755/wd/hub \ platformName=iOS \ platformVersion=7.0 ... deviceName=iPhone Simulator ... browserName=Safari ... ... 打開URL \ http://m.webapp.com Go To URL ${url} 打開應用 [Arguments] ${url} ${platformName} ${version} ${deviceName} ${app} [Documentation] 打開應用 ${url} ${platformName} ${version} \ \ ${devicename} ${app} @{args} ... ... 例如: ... ... 打開應用 http://localhost:4723/wd/hub Android 5.1.1 5e25d20d ${CURDIR}${/}app${/}fft.apk ... ... ${url} 是用於訪問應用的地址,一般是固定的。 url 和 端口可以根據具體地址修改。 ... ${version} \ 是安卓的版本 ... ${devicename} 是手機的UDID, 可以打開cmd 然後用 adb devices -l \ 看到設備列表。 ... UDID 是看到的第一列的內容,真機是一串字符串,模擬器是 \ ip:port \ 的形式 ... ${app} 是apk 存放的路徑 ${CURDIR} 系統變量,取得當前腳本路徑。 ${/} 系統變量 / open application ${url} platformName=${platformName} platformVersion=${version} deviceName=${deviceName} app=${app} 按關鍵字 [Arguments] ${keycode} ${metastate}=None Press Keycode ${keycode} ${metastate} 搖動手機 Shake 放大元素 [Arguments] ${locator} ${percent}=200% ${step}=1 Zoom ${locator} ${percent} ${step} 敲擊元素 [Arguments] ${locator} Tap ${locator} 橫屏 [Documentation] 手機設置橫屏 LANDSCAPE 清除文本 [Arguments] ${locator} Clear Text ${locator} 滑動 [Arguments] ${start_x} ${start_y} ${end_x} ${end_y} swipe ${start_x} ${start_y} ${end_x} ${end_y} 滾動 [Arguments] ${start_locator} ${end_locator} [Documentation] 從一個元素滾動到另一個元素 Scroll ${start_locator} ${end_locator} 點擊元素 [Arguments] ${locator} Click Element ${locator} 點擊元素坐標 [Arguments] ${coordinate_x} ${coordinate_y} Click Element At Coordinates ${coordinate_x} ${coordinate_y} 點擊固定點 [Arguments] ${x} ${y} @{args} Click A Point ${x} ${y} @{args} 點擊按鈕 [Arguments] ${index_or_name} Click Button ${index_or_name} 點擊文本 [Arguments] ${text} ${exact_match}=false [Documentation] 點擊匹配到文本的元素: ... ... 點擊文本 "text" ... 點擊文本 "text" True ... ... 默認模糊匹配所有元素,可以設置成精確匹配。 ... 如果可以匹配到兩個或兩個以上的元素,那麽需要用 click Element 元素,去處理。 Click Text ${text} ${exact_match} 睡眠 [Arguments] ${sec} sleep ${sec} 豎屏 PORTRAIT 等待頁面元素出現 [Arguments] ${locator} ${timeout}=100 ${err}=None Wait Until Page Contains Element ${locator} ${timeout} ${err} 等待元素出現文本 [Arguments] ${text} ${timeout}=10 ${err}=None Wait Until Page Contains ${text} ${timeout} ${err} 等待頁面不包含元素 [Arguments] ${locator} ${timeout}=10 ${err}=None Wait Until Page Does Not Contain Element ${locator} ${timeout} ${err} 等待頁面不包含文本 [Arguments] ${text} ${timeout}=10 ${err}=None Wait Until Page Does Not Contain ${text} ${timeout} ${err} 縮小元素 [Arguments] ${locator} ${percent}=200% ${step}=1 Pinch ${locator} ${percent} ${step} 獲取Appium超時時間 ${timeout} Get Appium Timeout [Return] ${timeout} 獲取Web元素 [Arguments] ${locator} [Documentation] 獲取匹配的定位器的第一個元素: ... ... ${element} 獲取Web元素 id=name ... 點擊元素 ${element} ${element} Get Webelement ${locator} [Return] ${element} 獲取元素坐標 [Arguments] ${locator} ${location} Get Element Location ${locator} [Return] ${location} 獲取元素尺寸 [Arguments] ${locator} ${size} Get Element Size ${locator} [Return] ${size} 獲取元素屬性 [Arguments] ${locator} ${name_or_value} [Documentation] 獲取元素屬性:(name 或者 value) ... ${val} \ 獲取元素屬性 ${locator} ${name_or_value} ... ... 例如: ... ${val} 獲取元素屬性 id=xxxx name ... ${val} 獲取元素屬性 id=xxxx value ${val} Get Element Attribute ${locator} ${name_or_value} [Return] ${val} 獲取匹配xpath數 [Arguments] ${xpath} [Documentation] 例如: ... ... ${count} \ \ \ 獲取匹配xpath數 \ \ //android.view.View[@text=Test] ${count} Get Matching Xpath Count ${xpath} [Return] ${count} 獲取可見文本 ${contents} Get Contexts [Return] ${contents} 獲取當前文本 ${context} Get Current Context [Return] ${context} 獲取所有web元素 [Arguments] ${locator} [Documentation] @{element} 獲取所有web元素 id=my_element ... 點擊元素 @{element}[2] @{element} Get Webelements ${locator} [Return] @{element} 獲取文件 [Arguments] ${file_path} ${decode}=False pull file ${file_path} ${decode} 獲取文件夾 [Arguments] ${folder_path} ${decode}=False Pull Folder ${folder_path} ${decode} 獲取文本 [Arguments] ${locator} [Documentation] 獲取符合元素的文本: ... ${text} \ 獲取文本 \ //*[contains(@text,foo)] ${text} Get Text ${locator} [Return] ${text} 獲取網絡連接情況 ${stat} Get Network Connection Status [Return] ${stat} 獲取資源 ${source} Get Source [Return] ${source} 設置Appium超時 [Arguments] ${sec} Set Appium Timeout ${sec} 設置網絡連接狀態 [Arguments] ${sec} Set Network Connection Status ${sec} 輸入值 [Arguments] ${locator} ${val} Input Value ${locator} ${val} 輸入密碼 [Arguments] ${path} ${passwd} Input Password ${path} ${passwd} 輸入文本 [Arguments] ${path} ${text} Input Text ${path} ${text} 返回 [Documentation] 瀏覽器返回上一個的頁面 Go Back 重置應用 Reset Application 鎖屏 [Arguments] ${sec} [Documentation] 這個方法只使用於IOS Lock ${sec} 長按元素 [Arguments] ${locator} Long Press ${locator} 長按關鍵字 [Arguments] ${keycode} ${metastate}=None [Documentation] keycode 可以在這個網址裏面找到: ... http://developer.android.com/reference/android/view/KeyEvent.html. ... ... Args: ... \ \ \ \ - keycode - the keycode to be sent to the device ... \ \ - metastate - meta information about the keycode being sent Long Press Keycode ${keycode} ${metastate} 隱藏鍵盤 Hide Keyboard 頁面不應該包含元素 [Arguments] ${locator} ${lvl}=INFO Page Should Not Contain Element ${locator} ${lvl} 頁面不應該包含文本 [Arguments] ${locator} ${lvl}=INFO Page Should Not Contain Text ${locator} ${lvl} 頁面應該包含元素 [Arguments] ${locator} ${lvl}=INFO Page Should Contain Element ${locator} ${lvl} 頁面應該包含文本 [Arguments] ${locator} ${lvl}=INFO Page Should Contain Text ${locator} ${lvl} 頁面截圖 [Arguments] ${filename}= Capture Page Screenshot ${filename}

AppiumLibrary用戶關鍵字