Forum Discussion

caz88's avatar
caz88
Occasional Contributor
6 years ago

How to load values from csv PRIOR to setting DataSource

Hey Folks, 

 

Is there a way to access the csv file that is populating the datasouce prior to loading the datasource. I'm attempting to isolate only certain rows in the csv file but in order for this to be dynamic I need to be able to determine which rows the data exists so that I can populate the datasource with only those rows. 

 

Something like: 

 

def objGlobalProperties = com.eviware.soapui.SoapUI.globalProperties;
def regionToRun = objGlobalProperties.getPropertyValue("region");

def locale = context.expand( '${DataSource#locale}' )

if(locale == regionToRun)
{
def dataSourceTestStep = testRunner.getTestCase().getTestStepByName("DataSource")

def endRow = dataSourceTestStep.getCurrentRow()

dataSourceTestStep.setEndRow(endRow)

}

 

I'm not sure if I'm overcomplicating this so I'm open to suggestions. Ideally I would like it to completely ignore the data that isn't in the regions to be run. This is at the testcase level so if there is a way to run this from the project or suite level it would be even better. Each testcase has it's own csv file that it uses to populate the DataSource. 

 

Many thanks! 

 

 

  • Hi caz88,

     

    You can add a Groovy script right after your DataSource Test Step that will check if the region value from your source is equal or is not equal to something and based on this either continue the loop execution or jump to the end of the loop. Example:

     

  • Olga_T's avatar
    Olga_T
    SmartBear Alumni (Retired)

    Thanks for reaching out, caz88!

     

    Community, any ideas or suggestions?

    • NBorovykh's avatar
      NBorovykh
      Moderator

      Hi caz88,

       

      You can add a Groovy script right after your DataSource Test Step that will check if the region value from your source is equal or is not equal to something and based on this either continue the loop execution or jump to the end of the loop. Example:

       

      • Olga_T's avatar
        Olga_T
        SmartBear Alumni (Retired)

        Thank you, NBorovykh!

        caz88, is this what you were looking for? We are looking forward to your results.