We will use demo project as an example, go though QuickStart repo.

Install:

First you should have python & pip installed on your machine, then install robot framework libaraies.

pip install robotframework
pip install robotframework-selenium2library

Clone the repo.

Run:

robot login_tests

login_tests is the folder contains all the test cases. After running the tests, it should all pass.

Keywords:

You are able to define keywords, you can think 'keywords' is something like composeable function. It combines multi functions together as a single function. In Robot framkwork, it combines multi test cases into one single suit.

For example:

*** Keywords ***
User "${username}" logs in with password "${password}"
Input username ${username}
Input password ${password}
Submit credentials

"User "${username}" logs in with password "${password}"" is a new "keyword" which can be use elsewhere:

*** Test Cases ***
Valid Login
Given browser is opened to login page
When user "demo" logs in with password "mode"
Then welcome page should be open

"Given", "When" && "Then" are built in keyword in Robot framework.

And the keyword itself also combines multi keywords:

Input Username
[Arguments] ${username}
Input Text username_field ${username} Input Password
[Arguments] ${password}
Input Text password_field ${password} Submit Credentials
Click Button login_button

"Argumenets" here you can think it is function params, so when user use "Input Username", should also give a param.

"Input Text" is a built in keywords,from seleium libaray,  "username_field" is a id selector:

<td><input id="username_field" size="30" type="text"></td>

Variables:

resource.robot:

*** Variables ***
${SERVER} localhost:
${BROWSER} Firefox
${DELAY}
${VALID USER} demo
${VALID PASSWORD} mode
${INVALID USER} invalid
${INVALID PWD} invalid
${LOGIN URL} http://${SERVER}/
${WELCOME URL} http://${SERVER}/welcome.html
${ERROR URL} http://${SERVER}/error.html

You can define variables, and you can use those inside other files, just need to import the file contains variables:

*** Settings ***
Documentation A test suite with a single Gherkin style test.
...
... This test is functionally identical to the example in
... valid_login.robot file.
Resource resource.robot

Then you can use those like:

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

Different way to write tests:

*** Settings ***
Documentation A test suite containing tests related to invalid login.
...
... These tests are data-driven by their 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.robot *** Test Cases ***
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

or

*** Settings ***
Documentation A test suite containing tests related to invalid login.
...
... These tests are data-driven by their 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.robot *** 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

最新文章

  1. MySQL GROUP BY用法
  2. webservice服务的简单应用
  3. Bash shell的内建命令:type
  4. plink远程连接服务器进行编译
  5. Java.util.ArrayList详解
  6. 软件密码和https协议
  7. php部分---面向对象静态、抽象类、oop接口、加载类、魔术方法、关键字。
  8. (转)Tarjan应用:求割点/桥/缩点/强连通分量/双连通分量/LCA(最近公共祖先)
  9. 十六进制字符串转化为byte数组
  10. HttpServletRequest对象方法的用法(转)
  11. iOS 简易型标签的实现(UICollectionView)
  12. 创建安全客户端Socket
  13. Hook技术--Activity的启动过程的拦截
  14. BZOJ2141排队——树状数组套权值线段树(带修改的主席树)
  15. 猫眼电影爬取(二):requests+beautifulsoup,并将数据存储到mysql数据库
  16. Ubuntu apt-get 彻底卸载软件包
  17. Instagram 在 PyCon 2017 的演讲摘要
  18. 小tip: base64:URL背景图片与web页面性能优化——张鑫旭
  19. Android内核的编译与测试
  20. wget下载jdk 蛋疼问题

热门文章

  1. Day2二分图笔记
  2. Rpm另类用法加固Linux安全
  3. oracle数据库spfile
  4. linux下加入用户并赋予root权限
  5. [Node &amp; Tests] Intergration tests for Authentication
  6. HTML5 API 是什么
  7. 使用node.js+babel,支持import/export语法
  8. Request、Response 之 Http 请求
  9. 【BZOJ 1146】【CTSC 2008】网络管理network
  10. elementUI upload 对图片的宽高做校验