Forum Discussion

ABCDEFG's avatar
ABCDEFG
Contributor
14 years ago

Groovy: setPropertyValue()

Hi,

Can some one help me to use setPropertyValue() function?

I need to update a value in the property test step. Dynamically I am getting value in 'abc' parameter and 'line1' value need to update in 'abc' parameter in Properties test step.

testRunner.testCase.getTestStepByName("Properties1").setPropertyValue(%s,"abc",line1)

This giving error message. Pls help!

Can you please...

^Thanks
  • 1. What is the error message?
    2. doesn't setPropertyValue(java.lang.String name, java.lang.String value) take two arguments not the 3 you have given "setPropertyValue(%s,"abc",line1)"?
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    First Get rid of %s in your statement.
    Next try using this:

    testRunner.testCase.getTestStepByName("Properties1").setPropertyValue("abc",line1)

    It should work.
  • I agree its 3 Parameters fn(). Could you help me with right values, if this fn() is not working.


    following is the Error msg,


    <org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script99.groovy: 19: expecting EOF, found '(' @ line 19, column 70. Properties1").setPropertyValue(%s,"abc", ^ org.codehaus.groovy.syntax.SyntaxException: expecting EOF, found '(' @ line 19, column 70. at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:139) at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107) at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236) at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:163) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:520) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731) at groovy.lang.GroovyShell.parse(GroovyShell.java:743) at groovy.lang.GroovyShell.parse(GroovyShell.java:770) at groovy.lang.GroovyShell.parse(GroovyShell.java:761) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: Script99.groovy:19:70: expecting EOF, found '(' at groovyjarjarantlr.Parser.match(Parser.java:211) at org.codehaus.groovy.antlr.parser.GroovyRecognizer.compilationUnit(GroovyRecognizer.java:780) at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:130) ... 20 more 1 error >

    ^Thanks
  • Deepesh,

    I will elaborate it more. Pls go thrgh the below content,

    This is my program-

    /*To Access Properties of a Test case and update it from i/o file*/
    def proj = testRunner.testCase.testSuite.project;
    def tsuite = testRunner.testCase.testSuite;
    def tcase = testRunner.testCase;

    //Reading from File
    myFile = new File("C:\\Documents and Settings\\ABCDEFG\\Desktop\\soapUI\\params.txt")
    for (def j=0; j<myFile.readLines().size(); j++)
    {
    line1= myFile.readLines().get(0)
    line2= myFile.readLines().get(1)
    for (def i=0; i<2; i++)
    {
    def Pnme = tcase.getTestStepByName("Properties1").getPropertyAt(i).getName();
    def Pvalue= tcase.getTestStepByName("Properties1").getPropertyAt(i).getValue();
    }
    //Update properties
    tcase.getTestStepByName("Properties1").setPropertyValue("Value1",line1)
    tcase.getTestStepByName("Properties1").setPropertyValue("Value2",line2)
    }

    What i need to do is, Need to Dynamically use Value1/Value2 [in Bold letters] and change it value in Pname field and update the parameter's?

    ^Thanks