Forum Discussion
testerA
13 years agoOccasional Contributor
I was able to read one value, namely AreaCode, from the DataSource. How do I read and input multiple values from a txt file? I need to read and input Prefix and Line Number too.
#1 Read the DataSource - GroovyScript-SaveDataSource
#2 Properties-Looper
#3 a groovy script looper - GroovyScript-DataLoop
#1 GroovyScript-SaveDataSource
/*
@Description : Data Source to read .txt file and pass the value to corresponding property.
@GroovyTestStepName : "GroovyScript-SaveDataSource"
*/
import com.eviware.soapui.support.XmlHolder
def myTestCase = context.testCase
def counter,next,previous,size
File tickerEnumFile = new File("C:/CTS/TestFiles/Save_AreaCode.txt")
List lines = tickerEnumFile.readLines()
size = lines.size.toInteger()
propTestStep = myTestCase.getTestStepByName("Properties-Looper") // get the Property TestStep
propTestStep.setPropertyValue("Total", size.toString())
counter = propTestStep.getPropertyValue("Count").toString()
counter= counter.toInteger()
next = (counter > size-2? 0: counter+1)
tempValue = lines[counter]
propTestStep.setPropertyValue("Value", tempValue)
propTestStep.setPropertyValue("Count", next.toString())
next++
log.info "Reading line : ${(counter+1)} / $lines.size"
propTestStep.setPropertyValue("Next", next.toString())
log.info "Value '$tempValue' -- updated in $propTestStep.name"
if (counter == size-1)
{
propTestStep.setPropertyValue("StopLoop", "T")
log.info "Setting the stoploop property now..."
}
else if (counter==0)
{
def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
propTestStep.setPropertyValue("StopLoop", "F")
}
else
{
propTestStep.setPropertyValue("StopLoop", "F")
}
#2 Properties-Looper
Total 9
Value 304
Count 0
Next 1
StopLoop T
#3 GroovyScript-DataLoop
def myTestCase = context.testCase
def runner
propTestStep = myTestCase.getTestStepByName("Properties-Looper") // get the Property TestStep
endLoop = propTestStep.getPropertyValue("StopLoop").toString()
if (endLoop.toString() == "T" || endLoop.toString()=="True" || endLoop.toString()=="true")
{
log.info ("Exit Groovy Data Source Looper")
assert true
}
else
{
testRunner.gotoStepByName("GroovyScript-SaveDataSource") //setStartStep
}
Step that needs to be parameterize
<cus:CallerID AreaCode='${Properties-Looper#Value}' LineNumber="2013" Prefix="208"/>
Please provide me a way to read and input values for LineNumber and Prefix
#1 Read the DataSource - GroovyScript-SaveDataSource
#2 Properties-Looper
#3 a groovy script looper - GroovyScript-DataLoop
#1 GroovyScript-SaveDataSource
/*
@Description : Data Source to read .txt file and pass the value to corresponding property.
@GroovyTestStepName : "GroovyScript-SaveDataSource"
*/
import com.eviware.soapui.support.XmlHolder
def myTestCase = context.testCase
def counter,next,previous,size
File tickerEnumFile = new File("C:/CTS/TestFiles/Save_AreaCode.txt")
List lines = tickerEnumFile.readLines()
size = lines.size.toInteger()
propTestStep = myTestCase.getTestStepByName("Properties-Looper") // get the Property TestStep
propTestStep.setPropertyValue("Total", size.toString())
counter = propTestStep.getPropertyValue("Count").toString()
counter= counter.toInteger()
next = (counter > size-2? 0: counter+1)
tempValue = lines[counter]
propTestStep.setPropertyValue("Value", tempValue)
propTestStep.setPropertyValue("Count", next.toString())
next++
log.info "Reading line : ${(counter+1)} / $lines.size"
propTestStep.setPropertyValue("Next", next.toString())
log.info "Value '$tempValue' -- updated in $propTestStep.name"
if (counter == size-1)
{
propTestStep.setPropertyValue("StopLoop", "T")
log.info "Setting the stoploop property now..."
}
else if (counter==0)
{
def runner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testRunner.testCase, null)
propTestStep.setPropertyValue("StopLoop", "F")
}
else
{
propTestStep.setPropertyValue("StopLoop", "F")
}
#2 Properties-Looper
Total 9
Value 304
Count 0
Next 1
StopLoop T
#3 GroovyScript-DataLoop
def myTestCase = context.testCase
def runner
propTestStep = myTestCase.getTestStepByName("Properties-Looper") // get the Property TestStep
endLoop = propTestStep.getPropertyValue("StopLoop").toString()
if (endLoop.toString() == "T" || endLoop.toString()=="True" || endLoop.toString()=="true")
{
log.info ("Exit Groovy Data Source Looper")
assert true
}
else
{
testRunner.gotoStepByName("GroovyScript-SaveDataSource") //setStartStep
}
Step that needs to be parameterize
<cus:CallerID AreaCode='${Properties-Looper#Value}' LineNumber="2013" Prefix="208"/>
Please provide me a way to read and input values for LineNumber and Prefix