分类: 项目管理
2009-08-26 20:03:14
磁针石:xurongzhong#gmail.com
这几天开始接触robot,感觉是个很好的命令行测试框架,当然功能肯定不止这些,待以后深入了解。
这里采用最简单的用例,检验ping一个ip是否通,如果接受到“Received =
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 |
|
192.168.1.1 |
|
|
192.168.1.1 |
|
Status Should Be |
Received = 4 |
执行:
D:\soft\develop\python\ping>pybot ping.htm
==============================================================================
==============================================================================
Can Ping Gateway | 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之类要省事很多,接下来几天有空将继续研究。
|