cancel
Showing results for 
Search instead for 
Did you mean: 

Reading test data from into datasource and to feed that to the test case

Highlighted
Occasional Contributor

Reading test data from into datasource and to feed that to the test case

Hello,

I have testdata.properties in the format for example
name1=data1,data2,data3

I have a properties test step defined reading the data from this properties file for the property name = name1

I also have a data source and data source loop test step to read the data from this properties file and to loop through the data with comma separation between data.

The idea here is to have the datasource read the file and loop through the data from 1 through 3 and feed each one at a time to the properties step.

The request is built to take the data from properties like ${Properties#mesLotName}

I am not sure if this is the right way to set up the steps in this order to achieve data driven testing looping through a set of test data.

But it is not working the way I expect it to. It is reading the datasource but putting the entire line with comma as the property value so the response is NullPointerException where it cannot qualify the data input.

Could someone please let me know what is the best way to fix this scenario or if there an alternative to this?

Any help is much appreciated.

Thanks
- Shashi
9 REPLIES 9
Highlighted
Super Contributor

Hi Shashi,

If I understand this correctly you want to run a request for each of the 3 values in name1. I'm not sure if you really need the Properties step, as far as I can see you will need to do as follows:

1) Change the file to contain one row for each set of data, where columns are separated with ','. In your case there seems to be only one column, so the file should be

data1
data2
data3
etc..


2) Create a DataSource step with the DataSource type set to File and pointed at the above created file

3) Define one property in your DataSource step named mesLotName

4) Add a request after this DataSource step containing

${#mesLotName}

5) And finally a DataSourceLoop that loops back to the request step for each row in the DataSource

When running this, the DataSource will read the comma-separated file one row at a time and assign the only value on each row to its mesLotName. The request will "use" this value and the DataSourceLoop will loop back until there are no more rows..

Ok.. hope I got it right, let me know!

regards,

/Ole
eviware.com
Highlighted
Occasional Contributor

Thanks for the reply with detail instructions.

It was a perfect solution. thanks again.

I do have an extended question as I am new to Soap ui pro.

I have a groovy assertion to save the response file onto my system so I can parse and analyze the result later.

Is there a simple way to say all the three responses into different files so I can parse them and get the test results?

I am doing this save and parse method because I want to be able to validate the data in some particular tags in the Soap response.

Regards
- Shashi
Highlighted
Super Contributor

Hi,

easiest way to save the entire response to files would probably be to create a Groovy Script Step after your request, containing something like the following:

def datasource = testRunner.testCase.testSteps["<Name of DataSource>"]
def outFile = new FileOutputStream('response-' + datasource.currentRow + '.txt')
outFile.write( context.expand( '<Name of Request Step>#Response' ))
outFile.close()


Hope this helps!

regards,

/Ole
eviware.com
Highlighted
Occasional Contributor

Hello,

I am able to save the response into the file. I was able to do this with the assertions as well. I have moved the assertion to a test step now.

But the file comes out empty. Could it be the problem where the file object is still not closed completely and the next request is trying to access the same object?

Thanks
- Shashi
Highlighted
Super Contributor

Hi,

are you maybe not closing the file when you are finished? Or not flushing it between requests?

regards,

/Ole
eviware.com
Highlighted
Occasional Contributor

I have outFile.close() right after I write the response to the file. It is not able to capture the responses.

Instead if I out the same script as a script assertion, it is able to write the response to the file. But the draw back is I get only one file with the last request and response. I need to save all the responses.

I want to try some try catch and finally block to handle to this situation where I can force things a bit. for that, I need some help with Groovy scripting. Can anyone point me to a good source on Groovy where I can see the usage of the scripting language and also some examples?

Thanks
- Shashi
Highlighted
Super Contributor

Hi,

the Groovy UserGuide is what I can recommend; http://groovy.codehaus.org/User+Guide

Can you share your entire script so I can try to see whats going wrong?

regards!

/Ole
eviware.com
Highlighted
Occasional Contributor

I have this resolved now. I had to change the order if the test steps (I was not aware the order matters)

Now I have the responses saved for all the requests. The idea is to write programs to extract information to have test results compared with expected results.

Thanks for all the information Ole and I will use the groovy site as I will be writing more and more of that.
Highlighted
Occasional Contributor

I was reading a tutorial on Soap ui pro where we could create properties on response and create a transfer to transfer the value of the properties from the response to the property. that link also had a data source loop to be created to get the properties for all the requests posted to the service.

I am trying to parse out the response to get some specific values from the response. Initial thought was to save the response a files and to write a java program to parse the response. But for testing maintainability is a bug thing with this approach.

Is this configurable in soap ui pro by using properties and transfers? Is yes, can someone tell me how?
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors