Forum Discussion

richie's avatar
richie
Community Hero
7 years ago

Loop using DataSource Directory Type Doesn't Seem to Be Working

Hi,

 

i'm sure you're all sick of reading my posts, especially the questions that appear straightforward.  I've been trawling the forum but I can't quite find the answer I need and I'm sure the answer is simple.

 

My Test Case has the following:

 

 

Datasource (Directory) type reading text files from the directory (FileContents property contains the flat files contents)
REST POST step (posts the contents of the FileContents property)
REST GET step (queries the database checking the POST worked ok)
Datasource Loop (Datasource step = Datasource (Directory), TargetStep = REST POST step)

 

 

NOW - I have 3 files in my directory, if I run the Datasource (with ZERO rows) - I can see the contents of the 3 files

 

I was expecting as there are 3 files in my directory, that the loop would execute the test 3 times,  once for each file - HOWEVER - this is NOT happening - the test is executing only once.

 

My reading indicates that what I think I've setup is correct - but I'm failing to see where the problem is - can anyone please advise?

 

I need to setup my testcase so that it executes for each file found via the Directory Datasource.

 

Many thanks to all!

 

richie

 

4 Replies

  • richie's avatar
    richie
    Community Hero

    Hi,

     

    I've finally worked out what I was doing wrong.

     

    The relevant help page is here for anyone else that hits this - but it doesn't mention an important point (that I think it's worth mentioning for anyone else who is SoapUI challenged. 

     

    I've found what I was doing wrong.  My hierarchy is as follows:

     

     

    Datasource (Directory) - fileContents property
    POST Request (publishing fileContents property) to the webservice
    Datasource Loop

     

    NOW - my directory has 3 files in it currently.  When I ran the Datasource, I'd specified '0' as the number of rows to get (where 0=maximum number of rows).  So it returned 3 rows.  When I'd specified '0', the loop didn't appear to work (the testcase only executed once).

     

    When I set the number of rows to be returned in the Datasource as '1' (each file has 1 line) - then the testcase executed 3 times!

     

    Sorry for wasting anyone's time - but hopefully this will help anyone else that is struggling with this.

     

    Thanks,

     

    richie

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      Glad you got it figured out and posted the solution! 

    • IgorG's avatar
      IgorG
      Staff

      richie Can you give a step-by-step explanation of what you were doing wrong? It seems like a simple thing that should be mentioned in the tutorial, but i am not sure where the issue is exactly.

      • richie's avatar
        richie
        Community Hero

        Hi IgorG,

         

        Yep - it's kindof obvious when you think about it, but anyway....

         

        My scenario is that I have three flat files (| delimited testdata files) saved on my local drive. I need to post the contents of each of these 3 test data files to a web service using a REST (POST) request

         

        My TestCase hierarchy was as follows:

         

        Datasource(DirectoryType) with fileContents property 
        REST (POST) request  <---publishing the contents of the fileContents property
        Datasource Loop - Target = REST (POST) request

        When you run the Directory Datasource, it prompts you with a query dialogue entitled 'Test data source' with the prompt text 'Specify the max number of rows to get (0 = all)'.  

         

        When I ran the Directory Datasource, it sources the file contents and passes them into the fileContents property - so the whole file string is on a single file.  Because I had 3 files in the directory, when I ran the Datasource with '0' setting - it returned 3 lines of data.  I then tried executing the test case (with the loop) but it executed only once.

         

        I was specifying '0' originally and this what was causing the problem.  This was what resulted in the testcase executing only once.

         

        Once I changed the 'Specify the max number of rows to get (0 = all)' setting to '1' instead of '0' (so it sources 1 file at a time, rather than all 3 files initially) and executed the testcase, the loop function worked - i.e. - the test case executed 3 times, whereas when the setting was '0' (for all) - it executed only once.

         

        So - as I said initially - it was user error - it's kindof obvious when you think about it - but ONLY after you think about it - so yeah - it might help to add this in the help.

         

        I hope I've been clear in my description!

         

        Thanks,

         

        richie