header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
January 09, 2009, 07:01:12 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
executing a step from groovy script
Welcome, Guest. Please login or register.
January 09, 2009, 07:01:12 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  executing a step from groovy script
« previous next »
Pages: [1] Print
Author Topic: executing a step from groovy script  (Read 682 times)
anu
Newbie
*
Posts: 6


« 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
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #1 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
Logged
anu
Newbie
*
Posts: 6


« Reply #2 on: July 11, 2008, 09:03:17 pm »

Thanks a lot.

I am able to get it working with testRunner.gotoStepByName( "Step 1 - open" );

Logged
anu
Newbie
*
Posts: 6


« Reply #3 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
« Last Edit: July 14, 2008, 11:25:56 pm by anu » Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #4 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
Logged
anu
Newbie
*
Posts: 6


« Reply #5 on: July 15, 2008, 11:35:42 pm »

Thanks.
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header