Ask a Question

Get a list of all properties

SOLVED
opaciga
New Contributor

Get a list of all properties

I have a scenario where a test case loads a DataSource and uses testRunner.testCase.testSuite.setPropertyValue() in a Groovy script to pass values from the data to another test case. The code to do this is highly repetitive and depends on listing out each properly to be passed from the DataSource.

 

Essentially, I have these lines duplicated almost identically dozens of times:

 

 

def some_input_value = context.expand( '${DataSource#some_input_value}' )
testRunner.testCase.testSuite.setPropertyValue( "some_input_value", some_input_value)

 

 

Is it possible to list all properties available on the DataSource, so that I could replace all these repeated blocks with a for loop? e.g. something like:

 

 

DataSource.getProperties().each {
    testRunner.testCase.testSuite.setPropertyValue( it, context.expand( '${DataSource#'+it+'}' ))
}

 

 

 

5 REPLIES 5
msiadak
Community Hero

@opaciga you are very close with the script that you have. But in this instance "it" is a reference to a hash map of the key (property name) and the value (property value from the datasource.)

If you change "it" to "it.key" the script should work as you expect. I tried it out with one of my projects that has a datasource and it worked for me. Let me know if it doesn't!




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
opaciga
New Contributor

I maybe have accidentally hit on something when what I intended as pseudocode... how do I get the DataSource object in the first place? I only know how to access its properties with `context.expand()`, which only returns a string.

 

Not a problem, let me see what I can do to help! Give this a shot and let me know if it works. Will need to run the Data Source so it has data, of course.
 

// This is highly dependent on where your DataSource lives. Assuming within the same Test Case.

// Assuming Data Source name of DataSource.
def DataSource = context.testCase.testSteps["DataSource"];

DataSource.getProperties().each {
 // testRunner should work, but it might need to be context.testCase.testSuite
 testRunner.testCase.testSuite.setPropertyValue( it.key, context.expand( '${DataSource#'+it.key+'}' ))
}

 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
opaciga
New Contributor

Thanks, that worked like a charm! Exactly what I needed.

Sorry for accidentally accepting your own reply as a solution. My mouse skipped!

You are more than welcome, glad I was able to help!




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
cancel
Showing results for 
Search instead for 
Did you mean: