RobotFramework-appiumLibrary关键字

对appiumLibrary的关键字进行重命名,翻译工作

*** Keywords ***
###常用appiumLibrary 关键字翻译,及示例

打开app
    Open Application     http://localhost:4723/wd/hub   platformName=Android
    ...                  platformVersion=8.0.0          deviceName=Android Emulator
    ...                  automationName=appium          appPackage=com.example.notes
    ...                  appActivity=.Activity.MainActivity
    wait until page contains element        com.example.notes:id/fab_expand_menu_button

关闭app
    quit application

程序放置后台几秒
     [Arguments]  ${TIME}
     background app     second = ${TIME}        #second = 5

截取当前页面并放置在logzhong
    Capture Page Screenshot

清空文本
    [Arguments]  ${locator}
    clear text          ${locator}            #自动识别为id和xpath,xpath要已//开头,后面包含locator参数的使用方法一致

点击位置
    [Arguments]   ${locator}
    Click Element       ${locator}
点击按钮
    [Arguments]   ${index_or_name}
    Click Button        ${index_or_name}     #按钮有名称才好使用,不建议使用,建议使用上面的

点击     #可以多次点击
    [Arguments]     ${locator}      ${x_offset}=None       ${y_offset}=None
    ...             ${count}=1
    Tap    ${locator}       ${count}

关闭所有程序
    Close All Applications


##验证相关操作
验证 ${locator} 是禁用的
    Element Should Be Disabled      ${locator}

验证 ${locator} 是可用的
    Element Should Be Enabled       ${locator}

验证 ${locator} 的name是 ${string}
    Element Name Should Be      ${locator}      ${srting}
    #举例
    # Element Name Should Be    xpath = //*[contains(@text,'example text')]     txt_field_name

验证 ${locator} 是可见的
    Element Should Be Visible   ${locator}

验证文本 ${text} 应是可见的
    Text Should Be Visible      ${text}


验证         #最通用的
    [arguments]    ${locator}    ${attribute}    ${string}
    Element Attribute Should Match     ${locator}       ${attribute}    ${string}
    #举例
    # Element Attribute Should Match    xpath = //*[contains(@text,'example text')]    name   txt_field_name
    #安卓支持的属性名称:contentDescription,text,className,resourceId,enabled,checkable,checked,clickable,focusable,focused,longClickable,scrollable,selected,displayed

验证 ${locator} 包含text  ${text}
    Element Should Contain Text     ${locator}      ${text}

验证 ${locator} 不包含text ${text}
    Element Should Not Contain Text    ${locator}       ${text}

验证 ${locator} 的text应该是 ${text}
    Element Text Should Be     ${locator}       ${text}

验证 ${locator} 的value应该是 ${value}
    Element Value Should Be     ${locator}      ${text}



####获取相关值或者对象
获取当前的Activity
    Get Activity     #返回当前的activity

获取当前appium的SessionId
    Get Appium SessionId   #当前appium的SessionId作为参考

获取当前上下文
    Get Current Context

获取可用的上下文      #查看源码发现两者返回的是同一个东西
    Get Contexts

获取属性值
    [Arguments]  ${locator}   ${attribute}
    Get Element Attribute  ${locator}   ${attribute}
    #举例:Get Element Attribute   locator    name

####操作
返回   #从历史记录中返回上一步
    Go Back

前往网址${Url}
    Go To Url   ${Url}

隐藏键盘   #只可在ios上使用,安卓上没有可用的参数去操作
    [Arguments]  ${key_name】
    Hide Keyboard   ${key_name}

#输入操作
在 ${locator} 输入文本 ${text}
    input text         ${locator}       ${text}

在 ${locator} 输入密码 ${password}
    #与输入文本的区别是就是输入的密码日志不打印出来。正常没什么用,使用input text就可以
    input password      ${locator}    ${password}

在 ${locator} 输入值 ${value}
    #官方文档说只在ios上使用,但实际操作中android有的输入框上用input text输入不进去,用inputv alue却是成功的
    input value         ${locator}      ${value}

横屏
    Landscape
竖屏
    Portrait

锁屏   #仅限ios
    Lock

安装app
    [Arguments]  ${app_path}     ${app_package}
    install app     ${app_path}     ${app_package}

启动app
    Launch Application     #需要启动appium时选择app='路径地址'#写在用例中

退出程序
    quit application     #与Launch Application相对,用在测试用例中启动程序

Log记录当前页面或者框架的HTML源码
    log source


长按 ${locator}
    Long Press      ${locator}

#判断页面包含,都可以设置日志等级,默认info。暂且不改动
页面应该包含 ${locator}
    Page Should Contain Element     ${locator}

页面不应该包含 ${locator}
    Page Should Not Contain Element  ${locator}

页面应该包含 ${text}
    Page Should Contain Text    ${text}

页面不应该包含文本${text}
    Page Should Not Contain Text        ${text}

缩小      #缩小一定量元素
    [Arguments]  ${locator}       ${percent}=200%   ${steps}=1
    Pinch   ${locator}      ${percent}      ${steps}

放大      #放大一定量元素
    [Arguments]  ${locator}       ${percent}=200%   ${steps}=1
    Zoom   ${locator}      ${percent}      ${steps}

摇晃设备
    Shake

关键字失败时执行
    Register Keyword To Run On Failure


#等待验证
等待活动
    [Arguments]  ${activity}    ${timeout}      ${interval}=1
    wait activity       ${activity}     ${timeout}
    #...                interval-重试之间的休眠间隔,以秒为单位,默认1s
等待直到元件可见
    [Arguments]     ${locator}      ${timeout}=None     ${error}=None
    Wait Until Element Is Visible   ${locator}      ${timeout}      ${error}
    #error 用于覆盖默认的错误消息,自定义错误消息

等待页面包含文本
    [Arguments]     ${text}      ${timeout}=None     ${error}=None
    Wait Until Page Contains      ${text}

等待页面不包含文本      #与上面相对
    [Arguments]     ${text}      ${timeout}=None     ${error}=None
    Wait Until Page Does Not Contain     ${text}

等待页面包含元件
    [Arguments]     ${locator}      ${timeout}=None     ${error}=None
    Wait Until Page Contains Element     ${locator}

等待页面不包含元件
    [Documentation]  与Wait Until Page Contains Element相对
    ...              timeout 表示超时时间
    ...              error表示错误信息用于覆盖默认的,自定义错误信息
    [Arguments]     ${locator}      ${timeout}=None     ${error}=None
    Wait Until Page Does Not Contain Element    ${locator}

Xpath应该匹配几次
    [Documentation]   error表示错误信息用于覆盖默认的,自定义错误信息
    ...               loglevel  用于设置日志等级
    [Arguments]   ${xpath}   ${count}   ${error}=None   ${loglevel}=INFO
    Xpath Should Match X Times   ${xpath}   ${count}



...未完待续...

你可能感兴趣的:(RobotFramework-appiumLibrary关键字)