RobotFramework常见语法

常用关键字

* Settings *

Library           Selenium2Library

* Keywords *

打开浏览器

    [Arguments]    ${url}    ${browser}
    [Documentation]    打开浏览器
    open browser    ${url}    ${browser}

最大化窗口

    [Documentation]    最大化窗口
    Maximize Browser Window

等待时间

    [Arguments]    ${time} 
    [Documentation]    等待时间
    sleep    ${time}

文本框输入

    [Arguments]    ${location}    ${value}
    [Documentation]    文本框输入
    input text    ${location}    ${value}

点击按钮

    [Arguments]    ${location}
    [Documentation]    点击按钮
    click button    ${location}

点击元素

    [Arguments]    ${location}
    [Documentation]    点击元素
    click element    ${location}

点击链接

    [Arguments]    ${location}
    [Documentation]    点击链接
    click link    ${location}

鼠标滑动

    [Arguments]    ${location}
    [Documentation]    鼠标滑动
    mouse over    ${location}

截图

    [Documentation]    截图
    Capture Page Screenshot

执行js

    [Arguments]    ${JSContent}
    [Documentation]    执行JS
    Execute JavaScript    ${JSContent}

选择Frame

    [Arguments]    ${location}
    [Documentation]    选择Frame
    Select Frame    ${location}

等待元素

    [Arguments]    ${location}    ${time}    ${error}    # 元素|等待时间|输出错误
    [Documentation]    等待元素
    wait until element is visible    ${location}    ${time}    ${error}

勾选框

    [Arguments]    ${location}
    [Documentation]    勾选框
    Select Checkbox    ${location}

单选框

    [Arguments]    ${group}    ${value}
    [Documentation]    单选框
    Select Radio Button    ${group}    ${value}

复选框选择

    [Arguments]    ${type}    ${location}    @{value}    # type:label、value,按照label还是value来定位,默认为label
    [Documentation]    复选框选择
    run keyword if    ${type}=='value'    Select From List By value    ${location}    @{value}
    \    else    Select From List By label    ${location}    @{value}
    [Teardown]

下拉框选择

    [Arguments]    ${type}    ${location}    @{value}    # type:label、value,按照label还是value来定位,默认为label
    [Documentation]    下拉框选择
    run keyword if    ${type}=='value'    Select From List By value    ${location}    @{value}
    \    else    Select From List By label    ${location}    @{value}
    [Teardown]

判断文本正确性

    [Arguments]    ${location}    ${expected}
    [Documentation]    判断文本正确性
    element text should be    ${location}    ${expected}

循环

if循环

Run Keyword If  '${addr.status_code}' == '200' Log     接口返回状态码正常
...             ELSE                            Log     接口返回状态码错误!

这里写图片描述

你可能感兴趣的:(RobotFramework)