Forum Discussion

krogold's avatar
krogold
Regular Contributor
5 years ago

cannot obtain data source from a specific row

Hello, I'm currently trying to use a feature of data source loops from the example

Obtain property values of the specific row 

but it does not work.

I have a loop with several elements that can be related. ie. in row 1 I have a device, in row 2 and 3 I have related devices.

I use the loop to create the devices, if the main device is not eligible I don't create it, but I also don't want to create the related devices. A device is eligible depending on the data in column deviceType

The related devices' deviceType does not matter.

 

So I use an additional data in my source : the offset between the current row and the main device's row

If I detect that my device is not a main device but a related device (an offset exists) I want to be able to get the main device's deviceType, ie. get the column from the source at row = (current_row - offset)

 

In my script I do the follwing :

 

def row = testRunner.testCase.testSteps["DataSource"].currentRow
def relatedtooffset = context.expand( '${DataSource#related to offset}' )

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

if ((relatedtooffset != "n/a") && ((deviceType == "LIGHT")||(deviceType == "GENERIC_DEVICE")))
{
	relatedtooffset = relatedtooffset.toInteger()
	log.info relatedtooffset
	device_row = row - relatedtooffset
	log.info "test info = " + context.expand( '${DataSouceTestStep#deviceType::0} ') // here I set 0 just to check that something can be displayed

}

 

 

but this does not display anything. Moreover, I don't know how to set the value in the expression, shall I set $device_row instead of 0 ?

I tried statically (just playing the script) and dynamically for the context but it does not change anything

  • krogold :

     

    Why don't you use groovy script logic instead of DataSource Loop, as i am not sure that you can change the iteration number at runtime. DataSource will run sequentially. 

    Or if you want to use DataSource then you load all the properties at starting and then use the properties later on as described in this link.

     

2 Replies

  • krogold :

     

    Why don't you use groovy script logic instead of DataSource Loop, as i am not sure that you can change the iteration number at runtime. DataSource will run sequentially. 

    Or if you want to use DataSource then you load all the properties at starting and then use the properties later on as described in this link.

     

    • krogold's avatar
      krogold
      Regular Contributor

      Well, in fact I use an excel sheet as the input, I'll try to load it all and use properties afterwards

       

      thank you

       

      Alex