Forum Discussion
If you want this to be more generic, there's various ways to do it. If possible, I would probably build the fragment that contains the data in a Groovy script that iterates the data source
def ds = testRunner.testCase.getTestStepByName('DataSource')
def rowsToRead = 2
def firstName, lastName, clazz = ""
def reqFrag = ""
for (row in 1..rowsToRead) {
if (row > 1) {
testRunner.testCase.getTestStepByName('DataSource').next(testRunner, context)
} else {
clazz = ds.getPropertyValue('class')
}
firstName = ds.getPropertyValue('firstName')
lastName = ds.getPropertyValue('lastName')
reqFrag += """<name><firstname>${firstName}</firstname><lastname>${lastName}</lastname></name>"""
}
reqFrag = """<person>${reqFrag}<level><class>${clazz}</class></level></person>"""
return reqFrag
then reference the script result in the request, eg:
<people>
${Groovy Script#result}
</people>
My loop is not going to next row by using testRunner.testCase.getTestStepByName('PNRDataSource').next(testRunner, context)
Is there somthing wrong with my code?
M_McDonald wrote:
Yes if you used that method you would have to have script and template for each.
If you want this to be more generic, there's various ways to do it. If possible, I would probably build the fragment that contains the data in a Groovy script that iterates the data sourcedef ds = testRunner.testCase.getTestStepByName('DataSource')
def rowsToRead = 2
def firstName, lastName, clazz = ""
def reqFrag = ""
for (row in 1..rowsToRead) {
if (row > 1) {
testRunner.testCase.getTestStepByName('DataSource').next(testRunner, context)
} else {
clazz = ds.getPropertyValue('class')
}
firstName = ds.getPropertyValue('firstName')
lastName = ds.getPropertyValue('lastName')
reqFrag += """<name><firstname>${firstName}</firstname><lastname>${lastName}</lastname></name>"""
}
reqFrag = """<person>${reqFrag}<level><class>${clazz}</class></level></person>"""
return reqFrag
then reference the script result in the request, eg:<people>
${Groovy Script#result}
</people>
context.testCase.getTestStepByName("PNRDataSource").setStartRow("0")
context.testCase.getTestStepByName("PNRDataSource").repositionAtStartRow( testRunner, context)
currentRow = context.testCase.getTestStepByName("PNRDataSource").getCurrentRow()
log.info "currentRow First is --" + currentRow
def rowCount = context.testCase.getTestStepByName("PNRDataSource").rowCount
log.info "rowCount-- " + rowCount
//for (def i = 0; i < rowCount ; i++)
for (row in 1..rowCount)
{
//castToString= Integer.toString(i)
//log.info "castToString---" + castToString
//context.testCase.getTestStepByName("PNRDataSource").setStartRow(castToString)
currentRow = context.testCase.getTestStepByName("PNRDataSource").getCurrentRow()
log.info "currentRowSecond is --" + currentRow
execute = context.testCase.getTestStepByName("PNRDataSource").getPropertyValue("Execute")
log.info "execute is --" + execute
testRunner.testCase.getTestStepByName('PNRDataSource').next(testRunner, context)
//context.testCase.getTestStepByName("PNRDataSource").next(testRunner,context)
currentRow = context.testCase.getTestStepByName("PNRDataSource").getCurrentRow()
log.info "currentRowThird is --" + currentRow
}
Fri Jul 28 14:47:59 CDT 2017:INFO:currentRowThird is --0
Related Content
- 6 years ago
- 4 years ago
- 4 years ago
Recent Discussions
- 13 days ago
- 14 days ago