【发布时间】:2017-04-07 13:19:06
【问题描述】:
我正在使用 RobotFramework 和 RobotRequestsLibrary 为一系列 API 创建冒烟测试套件。这是我第一次使用 RobotFramework。在尝试清理代码并使其更易于维护时,我决定尝试使用关键字来删除所有附带的细节。
例如,这里有两个我要清理的测试:
*** Variables ***
${sint} http://int.somecoolwebsite.com
*** Test Cases ***
Retrieve Store Info By Code Should Return Successful
[Tags] get
Create Session data-int ${sint}
${resp}= Get Request int /store/1234
Should Be Equal As Strings ${resp.status_code} 200
Retrieve All Store Info Should Return Successful
[Tags] get
Create Session data-int ${sint}
${resp}= Get Request int /stores
Should Be Equal As Strings ${resp.status_code} 200
以及我使用关键字的尝试:
*** Variables ***
${sint} http://int.somecoolwebsite.com
*** Keywords ***
Make ${call} Call To ${end_point}
Create Session ${sint} ${sint}
${resp} = Get Request ${sint} ${end_point}
${status} = ${resp.status_code}
Set Test Variable ${status}
Status Should Be ${required_status}
Should Be Equal ${status} ${required_status}
*** Test Cases ***
Retrieve Store Info By Code Should Return Successful
[Tags] get
Make Get Call To /store/1234
Status Should Be 200
Retrieve All Store Info Should Return Successful
[Tags] get
Make Get Call To /stores
Status Should Be 200
当我使用关键字运行测试用例时,出现以下错误:
Keyword name cannot be empty.
我尝试调试问题并在关键字分配中放置一个断点,我注意到${resp} 被分配并且${resp.status_code} 也有效。但是当我尝试分配 {$status}= ${resp.status_code} 时,会抛出错误。
我尝试了各种方法来使用内置的 Set Variable 重新分配变量,但没有任何运气。不能在关键字中以这种方式分配变量吗?任何见解都会有所帮助。谢谢!!
【问题讨论】:
-
抱歉,我没有时间深入研究这一点,但通过简短的阅读,数据驱动的风格可能更适合您正在尝试做的事情 - robotframework.org/robotframework/latest/…
-
您问题中的代码没有给出您所说的错误。该代码对我来说很好。
-
@BryanOakley 你是对的。我在此处编写代码时添加了
Set Variable声明。没有它,它确实会出错。但在测试用例中,我不需要使用该声明。 -
如果您不显示重现问题的代码,我们将无法帮助您。
-
我更新了代码,所以它会产生错误。
标签: python automated-tests robotframework smoke-testing