2

If I pass the string ${varName} to the built in keyword Log to Console, the console outputs the literal string ${varName}. If there is a variable named varName with a value of test123, how do I get the keyword Log to Console to output the variable value of test123 when I pass in ${varName}?

I'm making a data-driven script from an Excel spreadsheet. In the string values I'm passing in, there are variables names within it that I want replaced with the variable's value.

I've tried to run the string through the Evaluate keyword, but it just changes all of the variable names like ${varName} to RF_VAR_varName, so it's recognizing something here?

Open Excel ${ExcelFile} ${varName} Read Cell Data By Coordinates ${Sheet_Name} 0 ${RowNum} set global variable ${varName} log varName: ${varName} console=yes

Would output to the console: '38773461|${TMS_ConfNo}|substr:RDSJUMHV FIRSTNAME|${globalLastName} FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|${globalLastName1}, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|${globalLastName}, FIRSTNAME|fullline'

I would like this string: '38773461|${TMS_ConfNo}|substr:RDSJUMHV FIRSTNAME|${globalLastName} FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|${globalLastName1}, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|${globalLastName}, FIRSTNAME|fullline'

To evaluate into this: '38773461|12345678|substr:RDSJUMHV FIRSTNAME|LASTNAME FIRSTNAME|fullline:JEYCTINY, FIRSTNAME|LASTNAME1, FIRSTNAME|fullline:RDSJUMHV, FIRSTNAME|LASTNAME, FIRSTNAME|fullline'

I would like all variables in the string to translate to their respective value.

4
  • Using the value of a variable is one of the rudimentary operations in Robotframework. What you describe as not happening is surprising, to put it mildly. In your original version of the question, before the edit, the variable setting lines were with single spaces b/n the keywords and the values; are you sure it's not a case of simple syntax error? Please add a couple lines coffee sample where you are setting a string, and don't see the variables substituted. Are there any exceptions or errors? Commented Jan 31, 2019 at 21:51
  • I was just looking at the python documentation for eval and noticed this. Is this heading in the right direction? link Commented Jan 31, 2019 at 21:53
  • I see what you are saying. I think my explanation wasn't 100% clear then. The string is passed in via an Excel spreadsheet value. Updated the question above. ^ Commented Jan 31, 2019 at 21:55
  • Ok, I stand corrected - now with the updated question plus Bryan's answer I understand - the variables are inside the excel. They come as a plain string, and you wanted RF to substitute them with their defined values. A good one :) Commented Feb 1, 2019 at 5:29

1 Answer 1

4

Robot has a built-in keyword named Replace variables which will replace variables with their values in a string.

Sign up to request clarification or add additional context in comments.

1 Comment

Did not expect such an easy answer! Thanks again @Bryan Oakley (you answered my other question a day or so ago)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.