|
Title: executing a step from groovy script Post by: anu on July 10, 2008, 10:44:47 pm 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 Title: Re: executing a step from groovy script Post by: omatzura on July 11, 2008, 01:13:34 pm 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 Title: Re: executing a step from groovy script Post by: anu on July 11, 2008, 09:03:17 pm Thanks a lot.
I am able to get it working with testRunner.gotoStepByName( "Step 1 - open" ); Title: Re: executing a step from groovy script Post by: anu on July 14, 2008, 11:23:27 pm 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 <username xsi:type="xsd:string"> a1 </username> <password xsi:type="xsd:string"> 1 </password> When I try to run this, it does not work. But when I put them in one line as below <username xsi:type="xsd:string">a1</username> <password xsi:type="xsd:string">1</password> 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 Title: Re: executing a step from groovy script Post by: omatzura on July 15, 2008, 08:17:26 am 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/functional/groovystep.html#soapUI_GroovyUtils to get started and just post any follow-up questions you might have here.. regards! /Ole eviware.com Title: Re: executing a step from groovy script Post by: anu on July 15, 2008, 11:35:42 pm Thanks.
|