nats
16 years agoNew Contributor
Inserting values or datas into request by using grovvy scripts
HI
I am working on groovy scripting
I written script to access data from external file like xls,or csv successfully.
But I am facing problem to inserting same data or values in request XML in soapui tool to run test.
Can you pls provide me code to pick data from xls and insert it to request dynamically for mor than one iteration for the same request.(Its just like parametrization of data's running script for n number of iterations).
Please provide me ASAP I stuck up in between for this issue.
If this approach works fine its very useful to Soapui tool automation using groovy
Here is the groovy script to get values from xls and need how to pass it to soupui request.
//Fetches excel data if any value is present in Iteration Column.Breaks immediately when finds a null value//
// JAVA CLASSES
import java.io.File;
import com.eviware.soapui.support.*;
import java.util.*;
import jxl.*;
import java.lang.*;
// TO CREATE VARIABLES TO HOLD THE RESQUEST VALUES
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def request = groovyUtils.getXmlHolder("getCustomerDetails#Request");
// DECLARING VARIABLES FOR GLOBAL PROPERTIES
//def projectdir = context.expand('${#Global#PATH}');
Workbook workbook = Workbook.getWorkbook(new File("C:/Documents and Settings/abc/Desktop/Orange/POC/Excel/Input_Data.xls"));
Sheet sheet = workbook.getSheet("Sheet2");
rowcount = sheet.getRows();
log.info("rowcount = $rowcount");
colcount = sheet.getColumns();
log.info("colcount = $colcount");
//Getting rowcount and incrementing it
for(r=1;r {
Cell a1= sheet.getCell(0,r);
String s1 =a1.getContents();
// log.info ("string value in cell s1 : $s1");
if (s1 != "")
{
//Fetch header fields only if Value is present in Increment column
for(c=1;c {
Cell a2= sheet.getCell(c,0);
String s2 =a2.getContents();
// log.info ("string value in cell s2 : $s2");
if (s2 != "")
{
//Fetch the values of the current cell only if header is present
Cell a3= sheet.getCell(c,r);
String s3 =a3.getContents();
log.info ("string value in cell s3 : $s3");
}
else break;
}
}
else break;
}
My request is which i need to pass values
new
?
?
?
?
?
9900118820
?
?
?
I am working on groovy scripting
I written script to access data from external file like xls,or csv successfully.
But I am facing problem to inserting same data or values in request XML in soapui tool to run test.
Can you pls provide me code to pick data from xls and insert it to request dynamically for mor than one iteration for the same request.(Its just like parametrization of data's running script for n number of iterations).
Please provide me ASAP I stuck up in between for this issue.
If this approach works fine its very useful to Soapui tool automation using groovy
Here is the groovy script to get values from xls and need how to pass it to soupui request.
//Fetches excel data if any value is present in Iteration Column.Breaks immediately when finds a null value//
// JAVA CLASSES
import java.io.File;
import com.eviware.soapui.support.*;
import java.util.*;
import jxl.*;
import java.lang.*;
// TO CREATE VARIABLES TO HOLD THE RESQUEST VALUES
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def request = groovyUtils.getXmlHolder("getCustomerDetails#Request");
// DECLARING VARIABLES FOR GLOBAL PROPERTIES
//def projectdir = context.expand('${#Global#PATH}');
Workbook workbook = Workbook.getWorkbook(new File("C:/Documents and Settings/abc/Desktop/Orange/POC/Excel/Input_Data.xls"));
Sheet sheet = workbook.getSheet("Sheet2");
rowcount = sheet.getRows();
log.info("rowcount = $rowcount");
colcount = sheet.getColumns();
log.info("colcount = $colcount");
//Getting rowcount and incrementing it
for(r=1;r
Cell a1= sheet.getCell(0,r);
String s1 =a1.getContents();
// log.info ("string value in cell s1 : $s1");
if (s1 != "")
{
//Fetch header fields only if Value is present in Increment column
for(c=1;c
Cell a2= sheet.getCell(c,0);
String s2 =a2.getContents();
// log.info ("string value in cell s2 : $s2");
if (s2 != "")
{
//Fetch the values of the current cell only if header is present
Cell a3= sheet.getCell(c,r);
String s3 =a3.getContents();
log.info ("string value in cell s3 : $s3");
}
else break;
}
}
else break;
}
My request is which i need to pass values