用robot-framework库实现自动登录

首先安装robot-framework,然后下载安装selenium库,运行测试用例可以实现自动登录diandian网

sudo ./setup.py install

./rundemo.py selenium start

pybot login.tsv

 编写测试用例(自动登录脚本如下)

*** Settings ***

Documentation  A test suite with a single test for valid login. This test has
...            a workflow that is created using keywords from the resource file.
Resource       common_resource.txt


*** Test Cases ***

Valid Login
    Open Browser To Login Page
    Input Username    your_account
    Input Password    your_password
    Submit Credentials
    Welcome Page Should Be Open
#    [Teardown]  Close Browser

 下面文件是用selenium的关键字组成的一组测试用例

html_resource.txt

*** Settings ***

Documentation  A resource file containing the application specific keywords
...            that create our own domain specific language. This resource
...            implements keywords for testing HTML version of the test
...            application. Keywords for Flex version are in flex_resource.txt
...            and common_resource.txt is used to select which one to use.


*** Variables ***

${LOGIN URL}     http://${SERVER}/login
${WELCOME URL}   http://${SERVER}/home


*** Keywords ***

Open Browser To Login Page
    Open Browser  ${LOGIN URL}  ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed  ${DELAY}
#    Title Should Be  diandian

Go To Login Page
    Go To  ${LOGIN URL}
    Title Should Be  Login Page

Input Username  [Arguments]  ${username}
    Input Text  account  ${username}

Input Password  [Arguments]  ${password}
    Input Text  password  ${password}

Submit Credentials
    Click Button  login-submit

 通用的一组变量

common_resource.txt

*** Settings ***

Documentation  A resource file with variables common to both HTML and Flex
...            versions of the application. The correct SUT specific resource
...            is imported based on ${SUT} variable. SeleniumLibrary is also
...            imported here so that no other file needs to import it.
Resource       ${SUT}_resource.txt
Library        SeleniumLibrary


*** Variables ***

${SUT}           html
${SERVER}        www.diandian.com
${BROWSER}       firefox
${DELAY}         0
${VALID USER}    your_account
${VALID PASSWD}  your_passwd

你可能感兴趣的:(framework)