M H
M H

Reputation: 43

Is it possible to give arguments inside variables in robot framework?

Library  REST  ${base_url} 

*** Keywords ***
Get Requests
  GET  ${rest_of_the_url}
  Output  response body

*** Test Cases ***
Do some searching
  Get Requests

*** Variables ***
${base_url} https://business.com
${rest_of_the_url} /api/${department}/${person_name}

How can I assign values to ${department} and ${person_name}? I don't want to set those inside Variables because then I cannot write multiple scenarios inside one .robot file. Is it possible to do the assignment as arguments?

Upvotes: 1

Views: 3663

Answers (3)

Mz98
Mz98

Reputation: 51

Try to see this using the Set Test / Suite / Global Variable keywords here: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html

Use "Set Suite Variable" keyword then enter the variables $ {person_name} e $ {department} inside * Variables * then you should read the value inside the test.

Upvotes: 0

forkdbloke
forkdbloke

Reputation: 1565

i do not think there is a way to pass arguments within the variables,

The below section is straight from the documentation of Robotframework, where you can create Variables inside variables

Variables inside variables Variables are allowed also inside variables, and when this syntax is used, variables are resolved from the inside out. For example, if you have a variable ${var${x}}, then ${x} is resolved first. If it has the value name, the final value is then the value of the variable ${varname}. There can be several nested variables, but resolving the outermost fails, if any of them does not exist.

In the example below, Do X gets the value ${JOHN HOME} or ${JANE HOME}, depending on if Get Name returns john or jane. If it returns something else, resolving ${${name} HOME} fails.

*** Variables ***
${JOHN HOME}    /home/john
${JANE HOME}    /home/jane

*** Test Cases ***
Example
    ${name} =    Get Name
    Do X    ${${name} HOME}

Upvotes: 1

asprtrmp
asprtrmp

Reputation: 1062

E.g.,

${person_name}=   Set Variable    Matt
${department}=    Set Variable    R&D
# then your code continues
${rest_of_the_url} /api/${department}/${person_name}

Set Variable documentation.

Upvotes: 0

Related Questions