Forum Discussion

anu's avatar
anu
Occasional Contributor
16 years ago

executing a step from groovy script

I am passing my parameters to the request object in say "Step 1 - open" using groovy script. How do I run the script.
Below is my script


// get request property
def openrequest = testRunner.testCase.getTestStepByName( "Step 1 - open" );
def openrequestproperty = openrequest.getProperty( "request" );

// parse out textnodes to modify
def node = new groovy.util.XmlParser(false,false).parseText(openrequestproperty.value);
def textNodes = node["soapenv:Body"]["x:open"]["abc"][0].children()

// modify
textNodes.clear();
textNodes.add( "test1" + System.currentTimeMillis() );

// write back to string
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( node );

// set property
openrequestproperty.setValue( writer.toString() )

testRunner.gotoStepByName( "Step 1 - open" );

Now how do I execute "Step 1 - open".

Any help will be greatly appreciated.

Anu

5 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    the testRunner.gotoStepByName( .. ) method will transfer execution to the specified step when the current script is finished, so this can be used as you have done. An alternative is to run the desired step "manually" with

    def step = testRunner.testCase.getTestStepByName( "Step 1 - open" )'
    step.run( testRunner, context )

    but this will not generate any entry in the log or fail the testcase if the step fails, you would have to do that by checking the result of the run call..

    regards,

    /Ole
    eviware.com
  • anu's avatar
    anu
    Occasional Contributor
    Thanks a lot.

    I am able to get it working with testRunner.gotoStepByName( "Step 1 - open" );
  • anu's avatar
    anu
    Occasional Contributor
    Hi Ole

    I am using the above script to read and write the properties. After the script is executed, I see the output as thus


            a1
         

         
            1
         


    When I try to run this, it does not work. But when I put them in one line as below
    a1
          1

    and then execute this step, it works. How do I write it in one line? or how do I take care of this problem. Any help will be greatly appreciated.

    Anu
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Anu,

    hmm.. it seems there is some pretty-printing being performed when printing the xml.. maybe you could try using the GroovyUtils/XmlHolder classes instead for modifying the xml? Have a look at the docs and examples at http://www.soapui.org/userguide/functio ... roovyUtils to get started and just post any follow-up questions you might have here..

    regards!

    /Ole
    eviware.com