RF的一个demo 续 创建测试库

上一篇 / 下一篇  2012-08-02 22:54:28 / 个人分类:Robot framework

使用标签

Robot Framework 允许为测试用例设置标签以便给他们自由的元数据。allows setting tags for test cases to give them free metadata. 标签可以使用如下表中Default Tags 和 Force Tags  settings为一个文件中的所有测试用例设置。也可以像前面User status is stored in database 测试中那样为单独的测试用例设置标签。

Setting

Value

Value

Force Tags

quickstart

 

Default Tags

example

smoke

当你在一个测试执行后查看报告时,可以发现测试与标签相关联并且按照标签同级生成。标签还可用于很多其他目的,其中一个很重要的就是用于选择想要执行什么测试。你可以尝试下面的命令:

pybot --include smoke quickstart.html

pybot --exclude database quickstart.html

创建测试库

Robot Framework 为创建测试库提供了一个简单的API,包括Python 和 Java。 user guide包括有具有例子的详细说明。

下面是本文中LoginLibrary 的源码。可以看到关键词Create User 是如何映射到方法create_user 的实际实现。

import os

import sys

 

 

class LoginLibrary:

 

    def __init__(self):

        self._sut_path = os.path.join(os.path.dirname(__file__),

                                      '..', 'sut', 'login.py')

        self._status = ''

 

    def create_user(self, username, password):

        self._run_command('create', username, password)

 

    def change_password(self, username, old_pwd, new_pwd):

        self._run_command('change-password', username, old_pwd, new_pwd)

 

    def attempt_to_login_with_credentials(self, username, password):

        self._run_command('login', username, password)

 

    def status_should_be(self, expected_status):

        if expected_status != self._status:

            raise AssertionError("Expected status to be '%s' but was '%s'"

                                  % (expected_status, self._status))

 

    def _run_command(self, command, *args):

        command = '"%s%s %s' % (self._sut_path, command, ' '.join(args))

        process = os.popen(command)

        self._status = process.read().strip()

        process.close()

 


TAG:

 

评分:0

我来说两句

日历

« 2024-05-07  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 19142
  • 日志数: 32
  • 建立时间: 2012-03-07
  • 更新时间: 2013-11-03

RSS订阅

Open Toolbar