In this post I will show you how to execute SoapUI test for a set of values. For this I have put all data in csv file. I write groovy scripts for reading data from csv and executing the test steps.
Below is the groovy script for reading data from “URL.csv” file where I put all user credentials.
In above code I read data from “URL.csv” file and pass user name and password into “UserName “ and “Pass” of Login steps parameters.
Below is the groovy script for reading data from “URL.csv” file where I put all user credentials.
def groovyUtils = new
com.eviware.soapui.support.GroovyUtils(context)
def csvFilePath = "D:\\URL.csv"
context.fileReader = new BufferedReader(new
FileReader(csvFilePath))
rowsData = context.fileReader.readLines()
int rowsize = rowsData.size()
for(int i =0; I < rowsize; i++)
{
rowdata
= rowsData[i]
String[]
data = rowdata.split(",")
log.info
data[1]
groovyUtils.setPropertyValue("Login",
"UserName", data[0])
groovyUtils.setPropertyValue("Login",
"Pass", data[1])
testRunner.runTestStepByName(
"Login")
}
In above code I read data from “URL.csv” file and pass user name and password into “UserName “ and “Pass” of Login steps parameters.
“Login” test step executed by using test runner for every data.
Good work! I read lot many blogs gone through many tutorials and finally your script helped me!!! Great work!!!
ReplyDeleteCould you also post the script for reading values from excel and database? If the REST request is of type POST and you are sending a XML body in which the child elements are dynamic and I wanted to make these values dynamically read from an .csv, excel and databases.
ReplyDeletee.g. If I want to read values for the sku1,sku2 and add from SINGLE .csv file or excel and database(sqlserver). Could you please provide scripts for this scenario
Rest Request:
http://www.url.com/resource1/resource2/{locale}/{query2}
Body:
-
--
1234567
3541278
2145HYD
--
-
Sure Sarat....
DeleteBelow post's link is reading data from xls file in SoaupUI using groovy script: http://roadtoautomation.blogspot.in/2013/12/road-to-reading-data-from-excel-file-in.html
Deletecan we parameterize values from script written in mock response dispatch method using above script to configure diffrent mock responses for those values.pls provide solution..
DeleteGreat post, helped me a great deal!
ReplyDeleteThe last line in my csv file is read twice and two requests are posted for the same data
ReplyDeleteCan u please share the groovy script to dynamically add element or complex elements to soap request. This is to manage a collection of elements within a wrapper element
ReplyDeleteYour blog seems simple to understand therefore i have faith that you will be able to help me out with my problem. can you please help me with ,
ReplyDeleteI have a url to where i need to login
then need to provide product id which will be fetched from .csv file
click on a link so it produce 100 lines of json code for product information copy it and
use it inside SoapUI request as it is and get response from which i need to store 5 values in external data source(.xlsx) so i can use that data to produce customized report.
I am new to rest web service(json request) automation can you guide me in right direction?
This comment has been removed by the author.
ReplyDeleteUsing this code i am able to fetch the data from .csv file and see it in log output of groovy script, but how should i call this data in the Login Teststep(Rest service) I used ${#TestCase#UserName} but this didn't work.
ReplyDeleteHi I want to read a .csv file say Test.csv which have names . I want to read and pass the values to the request one by one to the request , so that for each name it generates a new instance.
ReplyDeleteUsing the above code only one value passes to the request.
Can i get a little help how to pass those values in a loop
iam getting this exception, can u pls provide some inputs
ReplyDeletegroovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.support.GroovyUtils.setPropertyValue() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String, java.lang.String) values: [clientId, subjectId, testCfg, 07687] Possible solutions: setPropertyValue(java.lang.String, java.lang.String, java.lang.String) error at line: 16
Thanks a lot...
ReplyDeleteHi ,
ReplyDeleteI Executed ur script it is working fine in the groovy script level,however while the running at the test case after passing the setting properties to testcase, it is failing to read lines between first and last lines.Can you please help me in fixing this issue