Steps :
1. Create a Groovy step for read
// Define a List and Retrieve The Values From External NotePad
def list = []
new File( "C://dd.txt" ).eachLine { line -> list.add( line ) }
log.info( "Read " + list.size() + " test values.." )
context.setProperty( "values", list )
context.setProperty( "index", 0 )
log.info("the value of Values is " + list)
2. Create a Properties step (should be empty and this will be automatically filled with the values when you run the soap pac)
3. Create a Grrovy step for initialization
// Set The First Set of Values in to Properties File. Make Sure That the Property Files Name is
// kept as "Properties" Only, Else Code Needs to Be Changed Accordingly.
def values = context.getProperty( "values" )
def index = context.getProperty( "index" )
def groupOfTokens = new String[1000];
def i = 0
def y = 0
def str = values[index]
log.info("the str value is " + str)
def ix = str.indexOf( " " )
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(str.substring(ix+1),",");
while(tokenizer.hasMoreTokens()){
groupOfTokens[i]=tokenizer.nextToken()
i++
}
for(def x=0;x<groupOfTokens.length;x++){
if(groupOfTokens[x] != null){
def props = testRunner.testCase.getTestStepByName( "Properties" )
props.setPropertyValue(groupOfTokens[x]+[y],groupOfTokens[x+1] )
x++
y++
log.info("The tokens are : "+groupOfTokens[x])
}
}
def props = testRunner.testCase.getTestStepByName( "Properties" )
def resultCount = props.getPropertyValue( "" )
log.info("the resultCount is " + resultCount)
def count = str.substring( ix+1 )
log.info("the Count is " + count)
1. Create a Groovy step for read
// Define a List and Retrieve The Values From External NotePad
def list = []
new File( "C://dd.txt" ).eachLine { line -> list.add( line ) }
log.info( "Read " + list.size() + " test values.." )
context.setProperty( "values", list )
context.setProperty( "index", 0 )
log.info("the value of Values is " + list)
2. Create a Properties step (should be empty and this will be automatically filled with the values when you run the soap pac)
3. Create a Grrovy step for initialization
// Set The First Set of Values in to Properties File. Make Sure That the Property Files Name is
// kept as "Properties" Only, Else Code Needs to Be Changed Accordingly.
def values = context.getProperty( "values" )
def index = context.getProperty( "index" )
def groupOfTokens = new String[1000];
def i = 0
def y = 0
def str = values[index]
log.info("the str value is " + str)
def ix = str.indexOf( " " )
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(str.substring(ix+1),",");
while(tokenizer.hasMoreTokens()){
groupOfTokens[i]=tokenizer.nextToken()
i++
}
for(def x=0;x<groupOfTokens.length;x++){
if(groupOfTokens[x] != null){
def props = testRunner.testCase.getTestStepByName( "Properties" )
props.setPropertyValue(groupOfTokens[x]+[y],groupOfTokens[x+1] )
x++
y++
log.info("The tokens are : "+groupOfTokens[x])
}
}
4. Create a property transfer step and map the elements
5. Create the actual request step
6. Create groovy validate step
// If There are Still Values in the Text File Go Back and Execute the Request.
def values = context.getProperty( "values" )
def index = context.getProperty( "index" );
def index = context.getProperty( "index" );
def str = values[index]
def ix = str.indexOf( " " )
def ix = str.indexOf( " " )
def props = testRunner.testCase.getTestStepByName( "Properties" )
def resultCount = props.getPropertyValue( "" )
log.info("the resultCount is " + resultCount)
def count = str.substring( ix+1 )
log.info("the Count is " + count)
if( count < resultCount )
{
throw new Exception( "not enough hits for resultCount [" + resultCount +
"], expected " + count + ", got " + resultCount )
}
else
{
log.info "got " + resultCount + " hits for [" + resultCount + "], required " + count
if( ++index < values.size() )
{
context.setProperty( "index", index )
testRunner.gotoStepByName( "Groovy Script Initialization" )
}
else
{
log.info "Finished TestCase, tested " + values.size() + " values"
}
}
{
throw new Exception( "not enough hits for resultCount [" + resultCount +
"], expected " + count + ", got " + resultCount )
}
else
{
log.info "got " + resultCount + " hits for [" + resultCount + "], required " + count
if( ++index < values.size() )
{
context.setProperty( "index", index )
testRunner.gotoStepByName( "Groovy Script Initialization" )
}
else
{
log.info "Finished TestCase, tested " + values.size() + " values"
}
}
Hi vinay,
ReplyDeleteThanks for the post and i am able to pass only one iteration in to the request and in my text file the 5 values are there and i want to test all 5 values. Could you please bit explain more how can we achieve this