How to save information from a looping Scenario into a CSV

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
A helpful tool to store information from a test scenario execution is to use the Write Tool. However, once the test loops, it may be difficult to save that data in an organized way.
Using this set up, you will be able to save all the information in a CSV file, which could then even be used in future tests.

First thing you want to do is create a write tool in the very top test suite. This write tool can be given input, so you can give it a column name of the information you will be gathering, such as
"ISBN Numbers
"
There must be an enter there as well, as it ensures the next piece of information is entered at the right place. The write file options then need to be set with a file name, I will be using "Output.txt" and a file location, I will be using "C:\tmp". Lastly, this write tool needs to have the Append option unchecked.
This first step is clearing out any previous creation of this file, and making a new one ready to be filled with information.

A new test suite can then be made to place the scenario inside of. This will prevent the first write tool from looping, and overwriting the gathered data. In my example, my scenario will consist of just a SOAP client that loops through a data source.

Once you have the SOAP Client looping through all the information properly, you can add an XML Transform. This will allow you to exact the one piece of information you need, which will place it as output.

Then attached to that XML Transform you will need an Extension tool in order to get the information in the form you need. All the code will do is add a new line character after the information given, to make sure all the information is still easy to differentiate between, and is once again placed as the output.
CODE
def formOutput(input,context):
return str(input) + "\r\n"


A write tool can then be attached to the extension tool's output. It will give the same file name, "Output.txt" and file location "C:\tmp", as the original, however it will be placed in Append mode. This will allow it to add information in a clear format without deleting any previous information.

When you are done, your test suite will look like this:
image

And when you run the entire .tst file, it will generate an output like this:
ISBN Numbers
0130341517
0130084662
0764548662

This process can be repeated to generate multiple .csv files for each piece of information you need.

If you have any steps about this process, feel free to respond to this post.
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    For a Web Functional Test, you would follow many of the same steps:

    Start by setting up the Write File Tool

    Create a Test Suite for the Web Functional Test

    The first difference will be to use the Browser Data Bank to save the information you need instead of an XML Transform. Save the variable with any name, in my recreation I used the name "ToWrite".

    Second difference will be that that Extension Tool will be its own tool, sequentially following the step where the variable was created in the Browser Data Bank. The code this time will be
    CODE
    def formOutput(input,context):
    return (context.getValue("Generated Data Source","ToWrite") + "\r\n")


    There will still be a Write File Tool attached the same way, exactly like the post above.

    When completed your Test Suite will look something like this:

    image

    This is the best way to get the information stored right now, but in the future if there is a new feature that helps shorten this process, I will update this post.
Sign In or Register to comment.