Chinaunix首页 | 论坛 | 博客
  • 博客访问: 19738259
  • 博文数量: 679
  • 博客积分: 10495
  • 博客等级: 上将
  • 技术积分: 9308
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-18 10:51
文章分类

全部博文(679)

文章存档

2012年(5)

2011年(38)

2010年(86)

2009年(145)

2008年(170)

2007年(165)

2006年(89)

分类: 项目管理

2009-08-26 20:03:14

自动化测试平台:Robot Framework 初探

File information

2009-8-26

磁针石:xurongzhong#gmail.com

博客:oychw.cublog.cn

 

 

§0 简介

       这几天开始接触robot,感觉是个很好的命令行测试框架,当然功能肯定不止这些,待以后深入了解。

       这里采用最简单的用例,检验ping一个ip是否通,如果接受到“Received = 4,就认为是通的。

 

 

ping 192.168.1.1

 

Pinging 192.168.1.1 with 32 bytes of data:

 

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

Reply from 192.168.1.1: bytes=32 time<1ms TTL=64

 

Ping statistics for 192.168.1.1:

    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

    Minimum = 0ms, Maximum = 0ms, Average = 0ms

 

D:\soft\develop\python\ping>

 

       Python的文件:

import os

import sys

 

 

class PingLibrary:

 

    def __init__(self):

 

        self._status = ''

 

    def ping_gateway(self,ip):

        self._run_command(ip)

 

 

    def status_should_be(self, expected_status):

        if  expected_status not in self._status :

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

                                  % (expected_status, self._status))

 

    def _run_command(self,  *args):

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

        process = os.popen(command)

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

        process.close()

 

 

HTML文件:

Setting

Value

Library

OperatingSystem

Library

testlibs/PingLibrary.py

 

 

Test Case

Action

Argument

Can ping gateway

Ping gateway

192.168.1.1

 

Ping gateway

192.168.1.1

 

Status Should Be

Received = 4

 

 

执行:

D:\soft\develop\python\ping>pybot ping.htm

==============================================================================

Ping

==============================================================================

Can Ping Gateway                                                      | PASS |

------------------------------------------------------------------------------

Ping                                                                  | PASS |

1 critical test, 1 passed, 0 failed

1 test total, 1 passed, 0 failed

==============================================================================

Output:  d:\soft\develop\python\ping\output.xml

Report:  d:\soft\develop\python\ping\report.html

Log:     d:\soft\develop\python\ping\log.html

 

注:官方的实例中还有test_login.py文件,感觉这个文件好像没有什么用,去掉照样可以运行。

 

       目前看来,这个平台比之前使用expect之类要省事很多,接下来几天有空将继续研究。


文件:ping.rar
大小:11KB
下载:下载
阅读(3363) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~