在robot框架中检查状态代码为200或202

2024-05-16 01:30:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有机器人框架代码,如果方法是post,应该检查状态代码是200或202,所以我正在尝试这段代码

  Run keyword if  '${Method}'== 'POST'    RequestsChecker.Check Response Status   
  ${response}  202 || 200
  or
  Run keyword if  '${Method}'== 'POST'    RequestsChecker.Check Response Status   
  ${response}  202 or 200

错误: ValueError:基数为10的int()的文本无效:“202 | | 200” 和 ValueError:基数为10的int()的文本无效:“202或200”

有谁能指导我如何使用robot或在robot中执行此状态代码检查


Tags: orrun代码ifresponse状态checkstatus
1条回答
网友
1楼 · 发布于 2024-05-16 01:30:17

该关键字接受单个RC(可以是int或字符串),但它所做的第一件事是将其转换为int。因此,它不能与“202 | | 200”、“202或200”或任何类似的组合一起使用——它从未被设计为

但是你可以通过两次调用来完成,期望其中一次成功

${status 200}=    Run keyword if  '${Method}' == 'POST'    Run Keyword And Return Status    RequestsChecker.Check Response Status   ${response}  200
${status 202}=    Run keyword if  '${Method}' == 'POST'    Run Keyword And Return Status    RequestsChecker.Check Response Status   ${response}  202

# now fail if the method is the one, and the RC was not in the expected
Run keyword if  '${Method}' == 'POST' and not (${status 200} or ${status 202})    Fail   The status code is not 200 or 202

相关问题 更多 >