Forum Discussion

Janine_Billings's avatar
Janine_Billings
Occasional Contributor
16 years ago

Data Source and Data Source loops executing all web service requests Help!

Hi
What I want to achieve is read data source from csv file
depending upon a field branch to a specific test request and execute
whilst records exist

what I've configured
DataSource
Groovy Script
Request1
DataSourceLoop1
Request2
DataSourceLoop2

The groovy script is a simple switrch statement - got to Request1 or Request2 based on the flag in the dataSource - this works fine when using the log.info to unit test, see code below

def type = context.expand( '${DS_RNU#Type}' )
log.info('type = '+type)

switch (type)
{
case 'RNU1':
log.info( "gotoStepByName( RNU1 )");
testRunner.gotoStepByName( "RNU1");
break;

  case 'RNU2':
log.info( "gotoStepByName( RNU2 )");
testRunner.gotoStepByName( "RNU2");

break;

default: log.info("broken");
}

Expected
-----------
Whilst there are still records in the csv file loop through and branch to the specified request and repeat

Actual
--------
It loops through all records and executes the required branch, however if there is only one record in the csv file and this record is to branch to Request1 it does so correctly and then executes Request2 with the same data. If it n I stop it from doing this, I would like it to end the test case when the correct branch has been executed and no more records exist

This does not occur if it has to go to Request2 1st

Thanks in advance for any assistance

Christopher

8 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    What about a Groovy step after the first datasource loop to branch to (or beyond) the second loop? That step will never be executed until/unless execution falls through the first loop.
  • Janine_Billings's avatar
    Janine_Billings
    Occasional Contributor
    Hi
    Thank you for the reply, I was thinking the same, add in a groovy script to branch beyond the last loop if it's the last record in the data source. I some how need to access the last row property of the data source, which I'm just looking for now. That's assuming I've understood your reply correctly? This is my first attempt using the data source loops in this manner, so apologies for any glaring mistakes

    Christopher
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I assume you have for each datasource loop you have set the target step to the corresponding request. Then if your script directs execution to the first request, the test case will loop until there is no more data, then fall through past the first datasource loop. I think you would put a Groovy script step there with a [tt:18auj795]return[/tt:18auj795] statement.

    [tt:18auj795]DataSource
    Groovy Script (branching logic to Request1 or 2)
    Request1   
    DataSourceLoop1 (loop to Request1)
    Groovy Script (return statement)
    Request2
    DataSourceLoop2 (loop to Request2)[/tt:18auj795]
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Sorry, the return won't work... and gotoStepByName() will result in the execution path returning to the groovy script regardless.. Doh!
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    OK, brain not working today. I think this should work.

    DataSource
    Groovy Script (branching logic to Request1 or 2)
    Request1 
    DataSourceLoop1 (loop to Request1)
    Groovy Script (with [tt:1zubi903]testRunner.gotoStepByName("Groovy Script (dummy last step)")[/tt:1zubi903])
    Request2
    DataSourceLoop2 (loop to Request2)
    Groovy Script (dummy last step)
  • Hi!

    I agree with the last suggestion here, except that the datasourceloop teststeps might both need to loop back to the first groovy script if each row in the datasource can be dispatched differently.

    let us know if this brings your forward!

    /Ole
    eviware.com
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    True. I thought that from the description it was one or the other request for all rows.
  • Janine_Billings's avatar
    Janine_Billings
    Occasional Contributor
    Hi Both
    That worked a dream thank you very much for the assistance.
    I'm still learning the pro features/functionality, and have a few more questions about api's, but I'll raise that in another post

    Thanks again