如何为会话创建全局变量并在测试用例中使用它(RobotFramework、RESTAPI)
有人能告诉我如何创建一个全局会话变量,并且该会话变量应该跨关键字/测试用例使用吗。我尝试了以下方法,但由于未找到${itoc_session}而导致错误如何为会话创建全局变量并在测试用例中使用它(RobotFramework、RESTAPI),rest,python-requests,robotframework,Rest,Python Requests,Robotframework,有人能告诉我如何创建一个全局会话变量,并且该会话变量应该跨关键字/测试用例使用吗。我尝试了以下方法,但由于未找到${itoc_session}而导致错误 *** Settings *** Library RequestsLibrary Library Collections *** Keywords *** Create session for server @{auth}= Create List admin admin123
*** 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
您从未调用服务器的
Create session
,因此变量从未设置。感谢您识别错误Get Policy with policyID为服务器${res}=Get请求${itoc_session}uri=/policies/${Policy_id}Log${res}Log${res.json()['name']}
。