Forum Discussion

FSommer's avatar
FSommer
Regular Visitor
3 years ago

Ready API: test Data source properties in groovy script

Hi,

I have a datasource (Excel) and one TestStep which I'd like to run only if some properties in the data source have a certain content, otherweise I'd like to skip the test step.

I added a groovyScript Step where I'm trying to check the property values from the data source, but whatever I do, it is always null.

 

Latest I tried the following:

def coInsured = context.expand( '${DataSource#propertyExample}' )
log.info("propertyExample: ",propertyExample); /*--> null*/

def row = testRunner.testCase.testSteps["DataSource"].currentRow
log.info("row: ",row); /* --> null */

 

So my question: how can I have access to the value of a dataSource property within a Data Source Loop using a groovy script.

Or is there another possibility to run a TestStep depending on the value of one or more data source propertiies?

 

Thanks in advance

Friederike

4 Replies

    • ChrisAdams's avatar
      ChrisAdams
      Champion Level 3
      Hi, this is definitely possible.

      In a Groovy step, you can access all data source props in the current row. Look up ‘get data’ from the left-click mouse menu in the groovy step. You should be able to use the UI to navigate to the data source step and then the props within.

      As for a conditional to run the test for a given row, yes, this can be done. I do this for all of my data-driven tests.

      In my Excel sheet, the first col is always a Boolean headed ‘run test’.

      The first step within my loop is a short groovy step to check the value of run test. If true, do nothing and let it run steps within loop. If false, jump to last step in loop.

      Look up the groovy syntax for ‘go to test step’

      I can’t provide specifics as I am away at the mo, but the others included will definitely be able to help further.
    • ChrisAdams's avatar
      ChrisAdams
      Champion Level 3
      Hi, this is definitely possible.

      In a Groovy step, you can access all data source props in the current row. Look up ‘get data’ from the left-click mouse menu in the groovy step. You should be able to use the UI to navigate to the data source step and then the props within.

      As for a conditional to run the test for a given row, yes, this can be done. I do this for all of my data-driven tests.

      In my Excel sheet, the first col is always a Boolean headed ‘run test’.

      The first step within my loop is a short groovy step to check the value of run test. If true, do nothing and let it run steps within loop. If false, jump to last step in loop.

      I can’t provide specifics as I am away at the mo, but the others included will definitely be able to help further.