Forum Discussion

scottkib's avatar
scottkib
Occasional Contributor
10 years ago

Groovy scripting help

Hi all,

 

I'm new to groovy, and looking for a way to set property values within a loop in my tear down script.  If I run the set and get outside of the loop, I have no problems.  If I move the code within the loop my script log stops on the first iteration at 

 

log.info step.getName() + " : " + res.getStatus()

 

My code is below, and 

 

stepResults = testRunner.getResults()

testStepCount = testRunner.testCase.getTestStepCount()
status = new Object[testStepCount]

count = 0
for(res in stepResults)
{
step = res.getTestStep()
log.info step.getName() + " : " + res.getStatus()
status[count] = res.getStatus()
testRunner.testCase.setPropertyValue("StepStatus"+count, status[count])
log.info testRunner.testCase.getPropertyValue("StepStatus"+count)
count++
}

2 Replies

  • scottkib's avatar
    scottkib
    Occasional Contributor

    I figured it out.  It won't let me setProperty with an string array value within the loop, although it allows it outside of the loop.

     

    I needed to cast to a String within the for loop.  Final code taking out all the steps no longer needed.

     

    stepResults = testRunner.getResults()

    count = 0
    for(res in stepResults)
    {
    testRunner.testCase.setPropertyValue("StepName"+count, res.getTestStep().getName())
    testRunner.testCase.setPropertyValue("StepStatus"+count, res.getStatus().toString())
    log.info testRunner.testCase.getPropertyValue("StepName"+count) + " : " + testRunner.testCase.getPropertyValue("StepStatus"+count)
    count++
    }

    • nmrao's avatar
      nmrao
      Champion Level 3
      Understand from your send post that you could proceed. So, you are good.