Forum Discussion

DaveD's avatar
DaveD
Occasional Contributor
16 years ago

Need help getting started with Groovy scripts

I'm working with SoapUI Pro 3.0.1, and am quite a newbie with it. I have constructed a previous test that used a file datasource. But it was a CSV file, so it was pretty easy to read the values into properties, then add a Property Transfer step to transfer them to the request, submit the request, and loop back.

But now I have a situation where I will have a fixed-format file to read, and need to do similar processing. It doesn't appear that the datasource step handles fixed-format files, so I thought I could use a Groovy script for this. But I really have no idea how to go about doing this. I've read over everything I can find in the docs but I'm still at a loss how to proceed.

Any tips, pointers, or suggestions would be greatly appreciated.

Oh, I also need to extract the results that I get back and write those out to a flat file.

Thanks,
Dave D

9 Replies

  • DaveD's avatar
    DaveD
    Occasional Contributor
    Hi Robert,

    Thanks for the links. I'd seen most of that, but was still confused. After playing around with it today, I have a much better feel. But I'm still having a problem.

    Where is the pro forum? When I go to the 'Forums' link it take me to http://www.eviware.com/forums/ which only shows this forum, and an 'eviware general' forum.

    My test flow is:
    1. Properties step - initializes a few static properties
    2. Groovy script - creates a BufferedReader and a PrintWriter that are stored in the context
    3. Groovy Datasource - retrieves the BufferedReader, reads and parses a line, stores values in the result map
    4. Property Transfer - copies properties from the static properties step and the Groovy Datasource into the Request
    5. SOAP Test Request
    6. Groovy Datasink - extracts values from the Response, retrieves the PrintWriter, and writes values from the response out to the file
    7. Datasource loop - Datasource Step is Groovy Datasource, and Target Step is Property Transfer
    8. Groovy script - closes the BufferedReader and PrintWriter

    When I run the test it works great for the first record in the file, but the datasource loop step fails with  "-> Missing dataSource step [] in DataSourceLoop". What could be causing this? I don't understand the message, since the datasource step does exist.

    Thanks,
    Dave
  • To correct my earlier statement... What you have described is correct, although you might want to consider looking into using a normal DataSource, it might do what you need it to.

    Sorry about the confusion.

    /Nenad
    http://eviware.com
  • DaveD's avatar
    DaveD
    Occasional Contributor
    The File Datasource appears to require a CSV file. I suppose that I could use the file datasource if I preprocessed the input file. The file that I'm getting is a fixed-format file with a large number of fields that I don't need.

    Are you saying that the Datasource Loop won't work with a Groovy Datasource? Would it be possible to script the entire process then?


    Dave
  • Hi Dave,

    this setup should work just fine.. are you saying that the DataSource Loop step isn't saving its configuration correctly (ie the configured DataSource step)? If so, could you attach (or mail to support@eviware.com) the project so we can have a look?

    (Please also make sure you are using the latest build)

    regards!

    /Ole
    eviware.com
  • DaveD's avatar
    DaveD
    Occasional Contributor
    Geez I *hate* when this happens. Yesterday I spend a fair amount of time trying to get this to work. This morning, after Ole's response I went in to run the test one more time so I could include the console output with the project, AND IT WORKED! I did first check each step and found that the Loop did not have the correct target step, but I know that it did yesterday.

    There is just one minor issue remaining. My understanding is that the Datasource Loop will continue to loop back to the Datasource step until there is no more data. This is working, but at that point, when there is no more data to be read, an error is generated, which causes the test to fail, skipping the final 'Close Files' step.

    When I read data in the Datasource step I then populate the result Map. I assume that I should be doing something when there is no data to read to signal that fact, rather than letting an exception be thrown. What should I be doing do handle this more gracefully?

    Thanks again,
    Dave
  • Hi Dave,

    just leave the result map empty, that will indicate that there is no more data to be read and the DataSource Loop should not loop back again..

    hope this helps!

    /Ole
    eviware.com
  • DaveD's avatar
    DaveD
    Occasional Contributor
    Hey Ole,

    Man you are really on top of it today! I've *never* had such quick response from *any* forum; or even close!

    Actually I suspected that it would be something like that, but you responded before I could even give it a test! Anyway, I modified the script to test the Reader and set result to null if there is no data. That worked like a champ.

    Thanks a lot for everything,
    Dave