0

Just starting to learn ReadyApi and Groovy, I would like to combine 3 project properties into a single property using a Groovy Script as a step in my SoapUI test:

Prop1 = "\\ap52\x$"
Prop2 = "\folder1\folder2\"
Prop3 = "1234567890123456"

Where:

  • Prop1 is a net resource which could change
  • Prop2 is a Folder location which is unlikely to change
  • Prop3 is actually a random 16 digit number generated and populated into Prop3 from another step

I need PropX to be created so I can transfer the property into a File Wait step.

Desired result of script with static text:

PropX = "\\ap52\x$\folder1\folder2\filename_1234567890123456_??????????.xml"
class stacker
  • 5,357
  • 2
  • 32
  • 65
PapaBear
  • 1
  • 1
  • found it on my own def string1 = testRunner.testCase.testSuite.project.getPropertyValue("Prop1"); def string2 = testRunner.testCase.testSuite.project.getPropertyValue("Prop2"); def string3 = testRunner.testCase.testSuite.project.getPropertyValue("Prop3"); testRunner.testCase.testSuite.project.setPropertyValue("fileWaitLoc", string1 + string2 + "response_" + string3 + "_??????????.xml") – PapaBear Jan 12 '17 at 21:34
  • 1
    Please submit your commentary as an answer. Self-answers are OK. Plus, in answer you can use code formatting. –  Jan 12 '17 at 22:02
  • I am not a Groovy specialist, but `\"` seems suspicious. Are you sure its not `\\"` or `/"`? –  Jan 12 '17 at 22:06

2 Answers2

0

The basic environment for dynamically generating Ready! API test case properties with Groovy are Ready! API Dynamic Properties, Property Expansions and Variable Access in Groovy Script Steps.

Since the script will be executed dynamically, you need not worry about the context in which the underlying property values change. Therefore, string concatenation of property values is a feasible approach.

As demonstrated elsewhere, your best bet for efficient string concatenation in Groovy is to avoid the Java-ish +-based approach and unleash the power of GString interpolation:

def prop1 = testRunner.testCase.testSuite.project.getPropertyValue('Prop‌​1');
def prop2 = testRunner.testCase.testSuite.project.getPropertyValue('Prop‌​2');
def prop3 = testRunner.testCase.testSuite.project.getPropertyValue('Prop‌​3');
testRunner.testCase.testSuite.project.setPropertyValue('file‌​WaitLoc', "${prop1}${prop2}response_${prop3}_??????????.xml")
Community
  • 1
  • 1
class stacker
  • 5,357
  • 2
  • 32
  • 65
  • Why have you add the [tag:coded-ui-tests] tag to the question? There is nothing in the question about Coded UI or about the Visual Studio that is used to create and run such tests. – AdrianHHH Jan 15 '17 at 09:48
  • @AdrianHHH I'm sorry. It was beyond my imagination that a general tag name would be exclusive to a specific tool. I should have read the tag description more carefully. I have exchanged the tag. Thank you for your friendly hint. – class stacker Jan 15 '17 at 18:39
0

found it on my own ...

def string1 = testRunner.testCase.testSuite.project.getPropertyValue("Prop‌​1"); 
def string2 = testRunner.testCase.testSuite.project.getPropertyValue("Prop‌​2"); 
def string3 = testRunner.testCase.testSuite.project.getPropertyValue("Prop‌​3"); 
testRunner.testCase.testSuite.project.setPropertyValue("file‌​WaitLoc", string1 + string2 + "response_" + string3 + "_??????????.xml")

However, this still did not work when sending this propertyvalue to the "Wait File" step in ReadyAPI ... it doesnt like the wildcard usage in the fileName, i.e. "??????????". I had to have development remove the added characters used for the unique naming in the file name in order for the File Wait step to work.

PapaBear
  • 1
  • 1