Forum Discussion

shrik18's avatar
shrik18
Occasional Contributor
7 years ago
Solved

Clone Datasource using groovy script

I have a datasource using internal datagen and another datasource using groovy. I want to trasnfer complete datasource 1 to datasource 2. Baiscally make a copy. How can I achieve this using groovy?

  • Hi,

    I found a work around for this. I used groovy script to set data in property step. Added a property "rows" in property step which would determine the number of rows in datasource. Used this propery in number of rows field of datasource. This let me manipulate the datasource upto some extent.

9 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    When you say you want to copy datasource 1 to datasource 2, what do you mean?

     

    Do you want to replace DataSource 2 with data source 1?

    Or do you want to copy the properties from Data Source 1 to Data Source 2? 

    Or do you want to make a brand new copy of Data Source 1?

  • shrik18's avatar
    shrik18
    Occasional Contributor
    Datasource 2 is groovy script. What I am trying to do is create dynamic datasource. Depending on condition Datasource will have all the values from Datasource 1 or Datasource 3.
    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Bear with me, I am still trying to understand what you are trying to do.


      DataSource1 : Internal Datagen.

      DataSource2: Dynamic datasource

      DataSource3: Groovy datasource

       

      Based on a condition, you want to alter DataSource 2 to either be DataSource 1 or DataSource 3? Is that the use case you are trying to figure out?

      • shrik18's avatar
        shrik18
        Occasional Contributor

        groovyguyThanks for your prompt replies.  Let me make it simple, Use case is 

        Datasource1: using datagen multiple properties multiple rows
        Datasource2: using datagen mulitple properties multiple rows
        Datasource3:  using groovy. This one will be dynamic and condition will be inside this datasource

        For example : Datasource 3 with groovy will look like 
        if(x = 1)
        Datasource 3 = Datasource 1 
        else 
        Datasource 3 = Datasource 2

  • shrik18's avatar
    shrik18
    Occasional Contributor

    the properties are same in all three so that is not the problem. The values and number of rows changes.  What you are suggesting is also feasible, just need datasource to reflect src 1 or src 2. 

  • shrik18's avatar
    shrik18
    Occasional Contributor

    groovyguy : please can you assist with the groovy script for your suggestion. I want to copy whole data source and I am not able to iterate through rows. 

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      I'll see if I can work out a groovy script to do this. It may take a bit.

  • shrik18's avatar
    shrik18
    Occasional Contributor

    Hi,

    I found a work around for this. I used groovy script to set data in property step. Added a property "rows" in property step which would determine the number of rows in datasource. Used this propery in number of rows field of datasource. This let me manipulate the datasource upto some extent.