-1

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

**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

1 Answers1

2

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

*** 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
Matthew King
  • 624
  • 4
  • 11