Forum Discussion

dmltn84's avatar
dmltn84
Occasional Contributor
14 years ago

property is not set by groovy script

Hello,

I have a groovy script that should update property value on each iteration, value is generated correctly and supposedly is expanded correctly in the output, but it never makes it to soap request. Script is as follows:

def myTestCase = context.testCase

File tempFile = new File("c:/my_Input_File.txt")
List lines = tempFile.readLines()

def x = Math.random()*10
i = String.valueOf(x).getAt(0)
i = i.toInteger()

myTestCase.setPropertyValue("inputValue", lines[i])
log.info context.expand( '${#TestCase#inputValue}' )


Script output is as follows:

Thu Mar 01 13:43:02 CET 2012:INFO:strings


Value 'strings' is correctly extracted, but it never appears in the request:

<nx4:operationType></nx4:operationType>
  • balak84's avatar
    balak84
    Occasional Contributor
    Hi,

    Considering that the << inputValue >> variable in the Test Case holds the value/data retrieved from the notepad file, then I would suggest that you try the groovy script given below.

    def var1 = myTestCase.getPropertyValue("inputValue")
    //log.info var1
    def project = testRunner.testCase.testSuite.project ;
    def requestpost = project.testSuites["TestSuiteName"].testCases["TestCaseName"].getTestStepByName("TestStepName");
    requestpost.getProperty("request").setValue(var1)
    //log.info requestpost.getPropertyValue("request")

    Hope this helps!!!

    Regards