Robotframework平台搭建

本文介绍了如何在Robotframework平台上搭建自动化测试环境,重点讲述了安装pyvirtualdisplay库的步骤,该库用于在虚拟显示器上运行Selenium测试。
摘要由CSDN通过智能技术生成
安装RobotFramework工具
1.安装Python2.7
http://python.org/download/
将Python目录添加进环境变量
2.安装setuptool包
https://pypi.python.org/pypi/setuptools/
Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. 
python ez_setup.py
将%PYTHON_HOME%Scripts目录添加进环境变量
3.安装pip包
https://pypi.python.org/packages/source/p/pip/
unzip the file and into pip-1.3 folder.
python setup.py install
4.安装robot
pip install robotframework
5.安装robot-selenium
pip install robotframework-selenium2library
6.安装chromedriver(firefox不需要)
http://code.google.com/p/chromedriver/downloads/list
将下载后的chromedriver.exe设置进幻境变量

7.安装pyvirtualdisplay
pip install pyvirtualdisplay


8.执行测试脚本
参考:https://bitbucket.org/robotframework/webdemo/src/
pybot login_tests

#resource.txt
*** Settings ***
Documentation     A resource file with reusable keywords and variables.
...
...               The system specific keywords created here form our own
...               domain specific language. They utilize keywords provided
...               by the imported Selenium2Library.
Library           Selenium2Library


*** Variables ***
${SERVER}         localhost:7272
${BROWSER}        chrome
${DELAY}          0
${VALID USER}     demo
${VALID PASSWORD}    mode
${LOGIN URL}      http://${SERVER}/
${WELCOME URL}    http://${SERVER}/welcome.html
${ERROR URL}      http://${SERVER}/error.html


*** Keywords ***
Open Browser To Login Page
    Open Browser    ${LOGIN URL}    ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}
    Login Page Should Be Open


Login Page Should Be Open
    Title Should Be    Login Page


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


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


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


Submit Credentials
    Click Button    login_button


Welcome Page Should Be Open
    Location Should Be    ${WELCOME URL}
    Title Should Be    Welcome Page


#valid_login.txt
*** Settings ***
Documentation     A test suite with a single test for valid login.
...
...               This test has a workflow that is created using keywords in
...               the imported resource file.
Resource          resource.txt


*** Test Cases ***
Valid Login
    Open Browser To Login Page
    Input Username    demo
    Input Password    mode
    Submit Credentials
    Welcome Page Should Be Open
    [Teardown]    Close Browser

#invalid_login.txt
*** Settings ***
Documentation     A test suite containing tests related to invalid login.
...
...               These tests are data-driven by they nature. They use a single
...               keyword, specified with Test Template setting, that is called
...               with different arguments to cover different scenarios.
...
...               This suite also demonstrates using setups and teardowns in
...               different levels.
Suite Setup       Open Browser To Login Page
Suite Teardown    Close Browser
Test Setup        Go To Login Page
Test Template     Login With Invalid Credentials Should Fail
Resource          resource.txt


*** Test Cases ***               User Name        Password
Invalid Username                 invalid          ${VALID PASSWORD}
Invalid Password                 ${VALID USER}    invalid
Invalid Username And Password    invalid          whatever
Empty Username                   ${EMPTY}         ${VALID PASSWORD}
Empty Password                   ${VALID USER}    ${EMPTY}
Empty Username And Password      ${EMPTY}         ${EMPTY}


*** Keywords ***
Login With Invalid Credentials Should Fail
    [Arguments]    ${username}    ${password}
    Input Username    ${username}
    Input Password    ${password}
    Submit Credentials
    Login Should Have Failed


Login Should Have Failed
    Location Should Be    ${ERROR URL}
    Title Should Be    Error Page

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值