【发布时间】:2016-08-23 07:32:38
【问题描述】:
试图在机器人框架中创建一个测试用例。
我们有几个 rest api,它们将 Json 作为结果返回给我们。为了调用这种情况,我们在 rest2.py 中使用了以下代码
def restJSON():
r = requests.get("http://httpbin.org/get")
# print "Code" , r.status_code
# print "Text " , r.text
return r.json()
我们将 json 存储在文件输出中。我们编写了机器人测试用例来评估json比较,如下所示
*** Settings ***
Library rest2.py
Library OperatingSystem
*** Test Cases ***
Example that calls a python keyword
${result}= restJSON
${json}= Get file output
Should be equal ${result} ${json}
但是当我们运行 pybot 测试用例时,我们收到错误说两个 json 不一样。
--------------------------------
pybot testSuite.txt
--------------------------------
==============================================================================
testSuite
==============================================================================
Example that calls a python keyword | FAIL |
{u'origin': u'10.252.30.94, 69.241.25.16', u'headers': {u'Via': u'1.1 localhost (squid/3.1.14)', u'Accept-Encoding': u'gzip, deflate, compress', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.2.1 CPython/2.7.6 Linux/3.16.0-30-generic', u'Host': u'httpbin.org', u'Cache-Control': u'max-age=259200'}, u'args': {}, u'url': u'http://httpbin.org/get'} != {u'origin': u'10.252.30.94, 69.241.25.16', u'headers': {u'Via': u'1.1 localhost (squid/3.1.14)', u'Accept-Encoding': u'gzip, deflate, compress', u'Accept': u'*/*', u'User-Agent': u'python-requests/2.2.1 CPython/2.7.6 Linux/3.16.0-30-generic', u'Host': u'httpbin.org', u'Cache-Control': u'max-age=259200'}, u'args': {}, u'url': u'http://httpbin.org/get'}
------------------------------------------------------------------------------
testSuite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
json 文件是一样的。但是它的失败测试用例仍然说两者都不相同。这是比较的正确方法,还是我们在机器人框架中有任何其他方法可以做到这一点。
【问题讨论】:
标签: python robotframework