RobotFramework--搭建和语法

2017-12-19  本文已影响0人  sandy测试路

Robot Framework

Robot Framework 是一种基于 Python可扩展 关键字驱动 开源自动化测试框架,运行在Jython (JVM) and IronPython (.NET)。主要用作验收测试和验收驱动开发。

一步步安装Robot Framework

1. 安装python

If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version.

# 升级 pip , setuptools
python -m pip install -U pip setuptools
2. 安装各种robot软件包
pip install robotframework

# 安装 RF 的集成环境,RIDE,对应 Python27\Scripts\ride.py
pip install robotframework-ride

# 安装 RF 支持的 selenium 库: Selenium2Library
pip install robotframework-selenium2library

# 下载cx_Oracle
# pip install robotframework-databaselibrary     

# 安装 requests
pip install requests              
pip install -U robotframework-requests

# 显示所有安装的软件
pip list                        

Test Cases

*** Test Cases ***
1.1 Workflow tests

工作流测试,即按照工作流程写测试用例。

  • The syntax requires that keywords and arguments. It is generally recommended to use four spaces.
1.2. Higher-level tests

One common style is the given-when-then format popularized by behavior-driven development (BDD)

1.3. Data-driven tests

如果测试场景很相似只是输入或者输出数据不一样。这种通常使用数据驱动方式测试避免重复的工作流。例如表单提交。

  • With Robot Framework the [Template] setting turns a test case into a data-driven test where the template keyword is executed using the data defined in the test case body.

2. Keywords

2.1. Library keywords

主要分为三类: standard libraries, external libraries and custom libraries.

2.2 User keywords

用户定义的关键字(由其他关键字组合而成)

*** Keywords ***
Login arg1 arg2

3. Variables

Variables can also be given from the command line which is useful if the tests need to be executed in different environments. For example this demo can be executed like:

robot --variable USERNAME:johndoe --variable PASSWORD:J0hnD0e QuickStart.rst
*** Variables ***
${username} ma

4. Organizing test cases

4.1 Setup/Teardown

钩子在测试用例集和单个测试用例中均可设置

*** Settings ***
Test Setup        Login
Test Teardown Close Browser
4.2 Tags
robot --include tag1 testsuite1     # 执行测试用例集中标记为tag1的所有用例
robot --exclude tag1 testsuite1     # 不执行测试用例集中标记为tag1的所有其他用例

5. Creating test libraries

自定义第三方测试库: Robot Framework offers a simple API for creating test libraries using either Python or Java, and the remote library interface also allows using other programming languages.

上一篇 下一篇

猜你喜欢

热点阅读