RobotFramework 关键字变量未设置

RobotFramework Keyword variable not setting

我正在使用 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 重新分配变量,但没有成功。 Keywords里不能这样赋值变量吗?任何见解都会有所帮助。谢谢!!

即使问题中的代码仍然没有给出您所说的错误,因为还有其他错误根本无法 运行,但问题是这一行:

${status} =  ${resp.status_code}

这不是分配变量的正确方法。您必须使用 Set Variable 关键字(或其他一些 "Set" 关键字),例如:

${status}=  Set Variable    ${resp.status_code}

出现错误的原因是每个测试或关键字步骤都必须有一个关键字。你只有变量名而没有关键字,所以你得到错误 Keyword name cannot be empty.