[英]How to I declare Global Variable in Robot Framework and use it in another robot file
In the response I'm getting one access token which I'm storing in ${Token} variable and want to set it as Global variable and want to use it in SendFax.robot file在响应中,我得到一个访问令牌,我将其存储在 ${Token} 变量中并希望将其设置为全局变量并希望在 SendFax.robot 文件中使用它
**GenerateToken.robot**
*** Variables ***
${base_Url}= https://pssidpdev01.modmedclouddev.com:5001
*** Keywords ***
*** Test Cases ***
Generator Token with valid credentials
${body}= create dictionary grant_type=client_credentials client_id=OrgClient3 client_secret=2M7A$Lbw567#WJdEixE&qFc#k
${headers}= create dictionary Content-Type=application/x-www-form-urlencoded
create session mysession ${base_Url} disable_warnings=1
${response}= POST On Session mysession /connect/token data=${body} headers=${headers}
log to console ${response.json()}
${Token}= Collections.Get From Dictionary ${response.json()} access_token
Set Global Variable ${Token}
**SendFax.robot**
*** Settings ***
Resource GenerateToken.robot
*** Variables ***
*** Test Cases ***
Send Fax Request
log to console ${Token} //Want to print above token here
Instead of having the generation of the token a test - consider making it a keyword which is ran on suite setup不要让令牌的生成成为测试 - 考虑将其作为在套件设置上运行的关键字
Something like this:是这样的:
GenerateToken.resource GenerateToken.资源
*** Variables ***
${base_Url}= https://pssidpdev01.modmedclouddev.com:5001
*** Keywords ***
Generator Token with valid credentials
${is_token} Run Keyword And Return Status Variable Should Exist ${Token}
# Only generate a token if ${TOKEN} var doesn't exist
IF ${is_token}
Return From Keyword
ELSE
${body}= create dictionary grant_type=client_credentials client_id=OrgClient3 client_secret=2M7A$Lbw567#WJdEixE&qFc#k
${headers}= create dictionary Content-Type=application/x-www-form-urlencoded
create session mysession ${base_Url} disable_warnings=1
${response}= POST On Session mysession /connect/token data=${body} headers=${headers}
log to console ${response.json()}
${Token}= Collections.Get From Dictionary ${response.json()} access_token
Set Global Variable ${Token}
END
SendFax.robot发送传真机器人
*** Settings ***
Resource GenerateToken.resource
Suite Setup Generator Token with valid credentials
*** Test Cases ***
Send Fax Request
log to console ${Token} //Want to print above token here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.