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+'}' ))
}
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+'}' )) }
Thanks, that worked like a charm! Exactly what I needed.