Groovy   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Groovy in SOAP UI大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

Using Script Assertion in SOAP UI

Posted by: devakara on: November 27,2008

Script assertion in SOAP UI Helps the developer to immediately run some priMary tests after the current @R_262_8798@geExchange.

It feels/sounds SIMILAR TO Groovy Script test step but,in a lot ways it’s more hAndy. If say we want to validate on the response time and proceed further for succeeding test steps,it feels heavy to have a Groovy step to do that; instead,the Script Assertion implicitly does that job (can be done using “assert @R_262_8798@geExchange.tiMetaken < 1000”). Using this we Could make the Test Suite look more credible and modular.

Script Assertion has access to messageExchangecontext and log objects.

We can access the request and response xml as below -

using the above holders we can get hold of the all elements in response and request xml of the latest @R_262_8798@geExchange.

While accessing the elements of request/response xml,using the corresponding namespace(s) for every element is very important. If the response xml is simple (that is,mostly all the elements are referenced by one namespacE),then xpath would be simple to trace. But if varIoUs elements are referenced by varIoUs namespaces,then we should be cautIoUs while framing the xpath.

Here are my observations regarding this:

Lets say following is the response xml obtained after running the Test request step(which has the script assertion)

Groovy in SOAP UI

Sample Response xml - I

In the Script Assertion step,to access RefNum field (of the above response xml),we write

And say if the response xml has varIoUs namespaces to refer its elements as below

Groovy in SOAP UI

then to access the same RefNum value,the xpath used should be

This might raise some ambiguity regarding ‘ns2‘ namespace ref. which I have used to access the RefNum value,though it is Nowhere present in the response xml.

what I figured out is default namespaces are named as ns1,ns2 and so on (as applicablE) in the order of their occurrences. In the above xml,‘content‘ element is referred with ‘ns1’; and ‘Response‘ element is referred with ‘ns2’. and thus the xpath is so.

We can verify which namespace is given which name,by clicking the ‘Declare’ button in XPath Assertion window (though this can be done to kNow the names of different namespaces present in response xml only). But to kNow,the names of different namespaces present in request xml, ordering logic (what i have mentioned abovE) should be employed.

Not only while applying Script Assertion,the above explanation (that is,building precise xpath with appropriate namespace references) applies to all the situations where developer needs to access any element of request/response xmls.

Operations with sql instance

Posted by: devakara on: October 17,2008

Groovy provides very robust methods with sql instance to retrieve and manipulate the ResultSet. 

There are methods for retrieving the first row, the ResultSet of some sql query,directly execuTing insert/update/delete queries.

Prerequisite: Obtain sql instance using

 

Below are some comprehensive examples which use the above sql instance.

firstRow( sqlQuery ) : This method returns the first row entity out of the ResultSet that is obtained by execuTing the query passed to it as argument.

Result can accessed from res as

 

eachRow( sqlQuery,{ClosurE} ) : This method is generally used to retain/modify the whole ResultSet based on some condition.  The second argument of this method i.e., clousure actually consists as set of statements to be executed for each of the result set’s entity. For example

The println statements (present as a clousurE) above are executed for each entity while iterating over the ResultSet,and it refers to the entity of ResultSet that is currently being iterated over. Clousure can have any number of statements.

 

execute( sqlQuery ) : Generally this method is used to INSERT/updatE/deletE records,as it doesn’t return any ResultSet as such. 

Second type of usage is to some extent SIMILAR TO PreparedStatement right? and the query Could also be a INSERT/updatE statement,if Developer wants to log some value(s) to database during execution of the TestStep.

 

@H_258_197@
Was the post informative?
@H_413_301@@H_413_301@ @H_413_301@

 

(Please feel free to get BACk if u have any trouble…as i’m just a mail away…otherwise leave a comment)

Property Transfer in SOAP UI

Posted by: devakara on: October 8,2008

Property transfers become crucial steps in scenarios where validations are done mostly using derived data.

Lets say after some Groovy script execution we end up setTing a property value in Properties step while tesTing an application’s functionality. And most of the times we would be in need of the obtained result out of that groovy step. As we have it in Properties Step we can access it using Property Expansion technique and also using Property Transfer Step.

Property Transfer Step shall be in between the Properties Step and SOAP request Step,but before placing the Transfer Step have Properties and SOAP request Steps in place. Property Transfer window would something like this:

Groovy in SOAP UI

Property Transfer Step

After creaTing a new Property Transfer in the above window say ‘RefNumTransfer‘,SELEct source,in this case it would be the ‘Properties’ Step,this inturn provides the list of all properties defined under that Step,SELEct the property you wish to transfer.

Now come to Target block,where we would have our SOAP request to catch the property transfer. Initially declare all the namespaces that your request would use,separating each of them with ‘;’ and then provide the XPath of the target node which should capture the transfered value. 

For example if the SOAP request as is below

Groovy in SOAP UI

SOAP request to catch tranfered Property

then the target block of Property Transfer should contain details like this:

Groovy in SOAP UI

Declaring namespaces and adding target XPath

Try running the Property Transfer step,you see the ‘Transfer Name’ and ‘Transfered Value’ in the Transfer Log,and also correspondingly that value is reflected in the SOAP request at the target XPath.

 

(Please feel free to get BACk if u have any trouble…as I am just a mail away…leave otherwise a comment)

大佬总结

以上是大佬教程为你收集整理的Groovy in SOAP UI全部内容,希望文章能够帮你解决Groovy in SOAP UI所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:groovysoapui