Forum Discussion

avidCoder's avatar
avidCoder
Super Contributor
7 years ago
Solved

How to create dynamic DataSink "Name" and "Value" using groovy and store the data dynamically

I am getting dynamic data from output file. I want to crate dynamic name and value inside DataSink. So that, the values are stored into it accordingly. Lets say. I am getting book names as AJANTA, DIKSON, PIRATE, SONIC. And sometimes I will get 6-7 values also based on output. I want to store this dynamic book names to DataSink with the "Name" as Book1, Book2 ... So.. On and Similarly "Value" as AJANTA, DIKSONm PIRATE, SONIC stored into the correspoding Name.

 

I have tried this code:-

 

String storeToDataSink contains all the book names.

 

testRunner.testCase.testSteps["DataSink"].setPropertyValue("Book1", storeToDataSink.toString())

 

But this works, when I knew that I have particular number of books. What if it is dynamic?

 

Any suggestion or code snippet will be appreciated.

  • Here is the solution to create dynamic property value inside DataSink or Properties testSteps.:-

     

    for(int i=0; i<countOfBooks; i++)
    String b = "Book"
    String temp = b.concat(i)
    testRunner.testCase.testSteps["DataSink"].setPropertyValue(temp,
    storeToDataSink.toString())
    }


    where storeToExcel is the value of the books such as AJANTA, DIKSONm PIRATE, SONIC

1 Reply

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Here is the solution to create dynamic property value inside DataSink or Properties testSteps.:-

     

    for(int i=0; i<countOfBooks; i++)
    String b = "Book"
    String temp = b.concat(i)
    testRunner.testCase.testSteps["DataSink"].setPropertyValue(temp,
    storeToDataSink.toString())
    }


    where storeToExcel is the value of the books such as AJANTA, DIKSONm PIRATE, SONIC