Eclipse RobotFramework:当我获得web服务的内容时,结果是文本

Eclipse RobotFramework:当我获得web服务的内容时,结果是文本,eclipse,automation,request,robotframework,Eclipse,Automation,Request,Robotframework,我需要检查webservices的结果是否包含一些数据 例如:我需要获取此web服务的结果,并检查结果是否包含“id”:13985,以及“name”:“Bulkan Evcimen”,以及“node_id”:“MDQ6VXNlcjEzOTg1”, 当我运行此脚本时,测试失败 Create Session github https://api.github.com ${resp}= Get Request github /users/bulkan Should Be Equal As S

我需要检查webservices的结果是否包含一些数据

例如:我需要获取此web服务的结果,并检查结果是否包含
“id”:13985
,以及
“name”:“Bulkan Evcimen”
,以及
“node_id”:“MDQ6VXNlcjEzOTg1”,

当我运行此脚本时,测试失败

Create Session  github  https://api.github.com
${resp}=  Get Request  github  /users/bulkan
Should Be Equal As Strings  ${resp.status_code}  200
Log    ${resp.content}
${az}=    Get Binary File    ${CURDIR}${/}az.txt
log  ${az}
should contain    ${resp.content}    ${az}

因此,我需要将
${resp.content}
转换为json

以字典格式获取响应-例如,解析的json很容易-使用以下调用:

${resp dict}=    Set Variable     ${resp.json()}
发生的情况是,您正在响应对象中调用
json()
方法,如果来自服务器的负载是json,它将被转换为字典(该方法调用技术称为“扩展变量语法”,在RF文档中有详细描述)。
正如您所看到的,对象的
content
属性返回响应的文本表示形式,没有传递和转换(不完全正确,它会根据“content Encoding”标题进行一些转换,但这对于这个问题并不重要)

现在,将有效负载作为字典,您可以使用它执行所有“dict操作”:(使用它-检查是否存在键,获取键的值,等等):

Dictionary Should Contain Key    ${resp dict}    a_key    # this is a synonymous to the "Should Contain" keyword, by the way
${value}=    Get From Dictionary    ${resp dict}    another_key

尽管如此,我认为您的检查不会通过-您正在读取一个文件的内容,并且在响应中检查它(完整内容)。如果文件内容不仅仅是服务器响应中的一个键,而是其他键,那么检查将失败。

您应该附加您的erorr日志