如何在机器人框架中声明全局变量并在另一个机器人文件中使用它
How to I declare Global Variable in Robot Framework and use it in another 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
不要让令牌的生成成为测试 - 考虑将其设为 运行 在套件设置中的关键字
像这样:
GenerateToken.resource
*** 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
在回复中 我得到一个存储在 ${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
不要让令牌的生成成为测试 - 考虑将其设为 运行 在套件设置中的关键字
像这样:
GenerateToken.resource
*** 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