用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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值