Contributions
Re: iterate datasource, multiple rows single request
My loop is not going to next row by usingtestRunner.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 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> 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 --01.5KViews0likes0CommentsRe: Looping a Datasource in Groovy script (Always starts at last row)
I am not able to go to next row, methods next( testRunner,context) is not working 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++) { //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 log.info context.testCase.getTestStepByName("PNRDataSource").next(testRunner,context) currentRow = context.testCase.getTestStepByName("PNRDataSource").getCurrentRow() log.info "currentRowThird is --" + currentRow } Fri Jul 28 14:32:49 CDT 2017:INFO:currentRow First is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:rowCount-- 6 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowSecond is --0 Fri Jul 28 14:32:49 CDT 2017:INFO:execute is --N Fri Jul 28 14:32:49 CDT 2017:INFO:false Fri Jul 28 14:32:49 CDT 2017:INFO:currentRowThird is --07 years agoPlace ReadyAPI QuestionsReadyAPI Questions6.5KViews0likes1Comment