如何为会话创建全局变量并在测试用例中使用它(RobotFramework,REST API)

时间:2017-04-07 09:54:04

标签: rest python-requests robotframework

有人可以告诉我如何创建全局会话变量,并且应该跨关键字/测试用例使用该会话变量。我尝试了以下方法并在找不到$ {itoc_session}时收到错误。

*** Settings ***
Library           RequestsLibrary
Library           Collections


*** Keywords ***

Create session for server
    @{auth}=  Create List  admin  admin123
    Create Session    httpbin    https://host141.swlab.net:71/  auth=@{auth}
    Set Global Variable     ${itoc_session}      httpbin

Get Policy for Server
     ${resp}=  Get Request  ${itoc_session}      uri=/policies/
     Log     ${resp.status_code}
    :FOR   ${item}   in  @{resp.json()}
    \   Log  ${item}
    \   ${get_policy_id}=    Get Variable Value    ${item['id']}
    \   ${get_policy_name}=    Get Variable Value    ${item['name']}
    \   Log     ${get_policy_id},${get_policy_name}       
    Set Global Variable    ${policy_id}      ${get_policy_id}


Get Policy with policyID
    ${res}=   Get Request    ${itoc_session}     uri = /policies/${policy_id}
    Log   ${res}
    Log   ${res.json()['name']} , ${res.json()['extReference']}



*** Test case ***

get_policy_id 
    Get Policy for Server

get_policy_details
     Get Policy with policyID   

1 个答案:

答案 0 :(得分:1)

您永远不会调用Create session for server,因此变量永远不会被设置。