Forum Discussion
For getting data from Excel you will need a library. You can search for that, one I see a lot is Apache POI. But it's not all that easy to use. An easier approach might be to save your Excel to CSV. Then you can do this:
/* example CSV:
*
* Aaronson,Aaron
* Baggins,Bilbo
* Dion,Celine */
new File('senders.csv')
.getText()
.split ('\n')
.collect { it.split(',') }
.each { String[] sender ->
context << [first: sender[1], last: sender[0]]
/* in the test step, use property expansions:
* ${first}, ${last} */
testRunner.runTestStepByName('some request step')
.with { result ->
/* you can add assertions on the test step,
* or you can do some here */
assert result.responseContext.contains(context.first)
assert result.responseContext.contains(context.last)
assert result.responseStatusCode == 201 //created
}
}
- SuperSingh7 years agoContributor
Add a step for Groovy Script & put the following piece . This will pull data from excel & load it to properties in your test case.
import jxl.*
import jxl.write.*
import com.eviware.soapui.support.XmlHolderWorkbook file = Workbook.getWorkbook(new File("C:/Folder1/File1.xls"))
tc = context.testCase//This is to access the sheet
Sheet PersonInfo = file.getSheet(0)//This will fetch data from cells. getCell(row,column) -- The leftmost cell being (0,0)
Cell FirstName = PersonInfo.getCell(1,1)
Cell LastName = PersonInfo.getCell(2,1)
Cell Address = PersonInfo.getCell(3,1)
Cell DOB = PersonInfo.getCell(4,1)
file.close()//The following piece will load the excel values in SoapUI in Test Case properties
tc.setPropertyValue("First_Name",FirstName.getContents())
tc.setPropertyValue("Last_Name",LastName.getContents())
tc.setPropertyValue("AddressLine1",Address.getContents())
tc.setPropertyValue("DOB",DOB.getContents())
Now, In your Request XML, you can fetch that data using the following syntax.
<firstName>${#TestCase#First_Name}</firstName>
<lastName>${#TestCase#Last_Name}</lastName>Thanks,
PredatorSingh
Related Content
- 11 years agoSoapRookie
Recent Discussions
- 6 days agoemoya