简体   繁体   English

如何在机器人框架中声明全局变量并在另一个机器人文件中使用它

[英]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.

相关问题 如何根据机器人框架中的命令行 arguments 在机器人脚本中声明可选全局变量 - How to declare optional global variable in robot script depending upon command line arguments in robot framework 如何使用随变量文件传递的额外参数 - 机器人框架 - How to use extra arguments passed with Variable file - Robot framework 如何在机器人框架中将变量用作url的一部分 - How to use a variable as part of url in robot framework 如何在机器人框架中动态导入变量文件 - How to import variable file dynamically in robot framework 如何在 Robot Framework 中使用 AND 运算符 - How do I use AND operator in Robot Framework 如何在机器人框架中为我的测试套件设置纪元时间和毫秒的全局变量? - How do I setup a global variable of epoch time and milliseconds to my test suite in robot framework? 使用变量从另一个文件调用关键字的关键字 - Robot Framework - Keyword calling a keyword from another file with variable - Robot Framework 如何在 Robot Framework 中使用 IF 和 ELSE - How to Use IF and ELSE in Robot Framework Robot Framework:如何在Robot Framework中使用用户创建的浏览器实例 - Robot Framework: How to use User created browser instance in Robot framework 如何将动态值设置为变量并将其用于机器人框架中的其他测试? - How to set dynamic value to a variable and use it for other test in robot framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM