2

Suppose I have a generated random alphanumeric character in Test 1(or by using user defined keyword). Now I want to set that random generated value to a variable ${RandomName} (see attached image) and use that variable for other test methods (say Test 2).

How would I go about doing this in Robot Framework?

enter image description here

Community
  • 1
  • 1
Shoaib Akhtar
  • 1,393
  • 5
  • 17
  • 46

1 Answers1

3

You can use the keyword Set Suite Variable to make the variable accessible in every test in the current suite:

Set suite variable    ${RandomName}

There is also a keyword named Set global variable which works in a similar manner but makes the variable available to all tests:

Set global variable    ${RandomName}

If you want to create a new variable that is visible everywhere you can do that with Set Suite Variable as well, passing the value as an additional argument.

Set suite variable    ${new variable}    hello, world

The above will create a varnamed named ${new variable} and set it to the string hello, world.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Though your answer didn't address my question exactly on how I can set random generated value to a variable in robot framework, but it did help me in resolving my scenario exactly what I wanted. Thank you very much. – Shoaib Akhtar Jan 18 '17 at 06:52
  • @ShoaibAkhtar: I added some clarification. You can use the same keyword to make an existing variable available in a suite, but you can use the same keyword to create a new variable. – Bryan Oakley Jan 18 '17 at 12:38
  • @ShoaibAkhtar - Will you please provide exact solution to this and how you resolved it .I struck from 2 days in exactly same scenario .Your help is really appreciated. – Chirag Dhingra Dec 23 '22 at 09:41
  • @ChiragDhingra I moved out from Jmeter project and currently into different roles and feel sorry that I cannot recollect the solution now as it's been long not doing anything related to Jmeter now. I should have posted answer that time itself. – Shoaib Akhtar Dec 29 '22 at 09:11