天天看点

Groovy in SOAP UI

很高兴又一次post一篇web service的文章在这里,其实这些内容都有详细的解释文档,觉得还不错,就集中在一起了,希望感兴趣的朋友可以有帮助,对每一个title都有相应的链接在后面,可以直接找到这个文章的出处。希望可以有更多的盆友来交流,谢谢大家! 1. Groovy in SOAP UI (http://groovyinsoapui.wordpress.com/)

While testing several conditions or performing the same operations over a range of values, we intend to use loops. We have three ways to accomplish looping in a groovy step.

1) while

2) for

3) closures For developers ‘while’ and ‘for’ are familiar operations.

while – 2. Usage:

while (condition)

{

// useful code here, which keeps executing until the condition is true

}

Example:

def a = 3;

while (a > 0)

{ a- -;

log.info(‘ more ‘ + a + ‘ loop(s) left’);

}

for – 3.

Usage:

for (x in )

{

// useful code here, which executes till the iteration over range of values is complete

}

Example:

for ( ad in 0..9)

{

log.info(ad + ‘ inside’);

}

For more usages of ‘for’ loop click here.

closures – closures are similar to iterators.

We mention an array or map of values, and write a closure to iterate over it.

To access the current value in the loop ‘it’ is to be used (but not ${it}) Usage/Example:

def sampleArray = [“dev”, “integration”, “qa”, “prod”]; def a = 1; sampleArray.each()

{ log.info(a + ‘:’ + it); a++; }

If you have a map to iterate in groovy step like below

def sampleMap = [ "Su" : "Sunday", "Mo" : "Monday", "Tu" : "Tuesday", "We" : "Wednesday", "Th" : "Thursday", "Fr" : "Friday", "Sa" : "Saturday" ];

then use stringMap.each()

{ log.info(it);

log.info( it.key + ‘:’ + it.value );

}

Note: break and continue statements can be used only in for and while loops but not in a closures. So if you wish to conditionally come out of the loop, its better you use for or while.

(break – as and when encountered comes out of the loop completely; continue – as and when encountered, skips all the succeeding steps in the loop and starts with next iteration. ) (Please feel free to get back if u have any trouble…as i’m just a mail away…otherwise leave a comment)

4. Groovy (http://wenku.baidu.com/view/bca803b91a37f111f1855bc1.html) You can refer to this doc to configure your groovy environment, and meanwhile, know about the fundamental grammar and usage. Good luck you guys!!

5. Using Script Assertion in SOAP UI (ttp://groovyinsoapui.wordpress.com/) We can access the request and response xml as below

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) def requsetHolder = groovyUtils.getXmlHolder( messageExchange.requestContent ) def responseHolder = groovyUtils.getXmlHolder( messageExchange.responseContent )

SOAP UI API online doc (http://www.soapui.org/apidocs/overview-summary.html)

PS: you can click on hyperlink behind related title to access the original article or online doc