Forum Discussion
3 Replies
Sort By
- logeshOccasional ContributorHi Guarav,
This is peice of code I use to write data from Excel into Request.
Step 1 : Download jxl or JExcel API and copy them into C:\Program Files\eviware\soapUI-2.5.1\bin\ext folder.
Step 2 :Re-start the application.
Step 3: Paste the below script into the Groovy Script - test step
Code:
// JAVA CLASSES
import java.io.File;
import com.eviware.soapui.support.*;
import java.util.*;
import jxl.*;
import java.lang.*;
// VARIABLE TO HOLD THE DATA SHEET NAME
sDataSheetName = "SearchCustomer.xls"
// TO CREATE VARIABLES TO HOLD THE RESQUEST VALUES
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def request = groovyUtils.getXmlHolder("SearchCustomer#Request")
// TO GET THE TEST CASE NAME
def testCase = testRunner.getTestCase()
Name= testCase.getName()
// DECLARING VARIABLES FOR GLOBAL PROPERTIES
def projectdir = context.expand('${#Global#PATH}');
Workbook workbook = Workbook.getWorkbook(new File(projectdir + sDataSheetName))
Sheet sheet = workbook.getSheet("Input");
rowcount = sheet.getRows();
colcount = sheet.getColumns();
// CHECK WHETHER THE TESTCASE NAMES MATCH
for (tc_row in 2..rowcount)
{
Cell a1 = sheet.getCell(0,tc_row)
String s1 = a1.getContents()
if ( Name == s1 )
{
current_row = tc_row
break
}
}
// TO CHECK FOR THE HEADER TAGS
for (tc_column in 1..colcount-1)
{
Cell a2= sheet.getCell(tc_column,1)
String s2 = a2.getContents()
if (s2 != "" )
{
Cell a3= sheet.getCell(tc_column,current_row)
String s3 = a3.getContents()
//UISupport.showInfoMessage("${s3}")
tag = s3
//SETS INPUT VALUES IN CORRESPONDING NODE
request.setNodeValue("//" + s2, "${tag}")
request.updateProperty()
}
}
//**************************************** END OF TEST STEP *************************************//
Refer the attached Search.xls sheet I have used. Use similar Excel.
:-)
- guaravOccasional ContributorHI,
Above script is not working from line:
Workbook workbook = Workbook.getWorkbook(new File(projectdir + sDataSheetName))
Thanks & Regards
Gaurav - joelgluthContributorYou can also save your Excel file as CSV and use a DataSource to read it from SoapUI Pro...
Related Content
Recent Discussions
- 17 minutes agoyassir
- 23 hours agodipsthorat
- 2 days agoisbiat