安装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设置进幻境变量
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
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