我正在使用 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 重新分配变量,但没有任何运气。不能在关键字中以这种方式分配变量吗?任何见解都会有所帮助。谢谢!!