Using Script Assertion in SOAP UI
Posted by: devakara on: November 27,2008
In: Groovy|SOAP UI 5 CommentsScript assertion in SOAP UI helps the developer to immediately run some primary tests after the current messageExchange.
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 messageExchange.tiMetaken < 1000”). Using this we Could make the Test Suite look more credible and modular.
Script Assertion has access to messageExchange, context and log objects.
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 )
using the above holders we can get hold of the all elements in response and request xml of the latest messageExchange.
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)
Sample Response xml - I
In the Script Assertion step,to access RefNum fIEld (of the above response xml),we write
def refNum =responseHolder.getNodeValue(“//trans:ProcessMessageResponse/content/Response/RefNum”)
And say if the response xml has varIoUs namespaces to refer its elements as below
then to access the same RefNum value,the xpath used should be
def refNum =responseHolder.getNodeValue(“//trans:ProcessMessageResponse/ns1:content/ns2:Response/ns2:RefNum”)
or
def refNum = responseHolder.getNodeValue(“//ns2:Response/ns2:RefNum”)
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.
Tags: Script Assertion, Script assertion in SOAP UI, messageExchange,messageExchange Script Assertion, messageExchange.timeTaken, script assertion for validating response time, context in script assertion, access request xml in script assertion, access response xml in script assertion,request xml script assertion, response xml script assertion, GroovyUtils Script Assertion, namespaces Script Assertion, getXmlHolder script assertion, accessing elements under default namespace, accessing SOAP request in Script Assertion, accessing SOAP response in Script Assertion,accessing request xml in soap ui, accessing response xml in soap ui,accessing request xml with groovy in soap ui, accessiong response xml with groovy in soap ui Operations with sql instancePosted by: devakara on: October 17,2008
In: Groovy|SOAP UI 4 CommentsGroovy 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
import groovy.sql.sql
def sql = sql.newInstance(dbpath,dbusr,dbpwd,dbdriver)
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.
def res = sql.firstRow(“SELECT * FROM TEST_table WHERE USERID=’12345′”)
Result can accessed from res as
println( res[0] ) OR
println( res.ColUMN_name )
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
sql.eachRow( “SELECT * FROM TEST_table WHERE USERID=’12345′”,
{
println( it.ColUMN_1 );
println( it[2] );
} )
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.
sql.execute( “DELETE FROM TEST_table WHERE USERID=’12345′ & USERname=’SOMEname’ ” )
OR
sql.execute( “DELETE FROM TEST_table WHERE USERID = ? & USERname = ? “,
[ "12345","SOMEname" ] )
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_419_285@ Was the post informative? @H_788_301@@H_788_301@ @H_788_301@ View Results@H_788_301@Polldaddy.com
(Please feel free to get back if u have any trouble…as i’m just a mail away…otherwise leave a comment) Tags: DB Operations with Groovy, groovy DB Select, groovy INSERT into DB, groovy SELECT from database, groovy DELETE from database, DB Select in Groovy, DB Insertion in Groovy, sql methods in Groovy, groovy sql.firstRow(), groovy sql.eachRow(), groovy sql.execute(), DB operations SOAP UI, sql connection SOAPUI, sql.eachRow() SOAPUI, sql.firstRow() SOAPUI, sql.execute() SOAPUI, sql firstRow() Groovy SOAPUI, sql eachRow() Groovy SOAPUI, sql execute() Groovy SOAPUI, sql execute groovy, sql firstRow groovy, sql eachRow groovy Property Transfer in SOAP UI
Posted by: devakara on: October 8,2008
In: SOAP UI 17 CommentsProperty 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:
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
SOAP request to catch tranfered Property
then the target block of Property Transfer should contain details like this:
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) Tags: declaring namespaces in Property Transfer, property transfer,property transfer in SOAP UI, Property Transfer Step, property transfer to request xml, property transfer to SOAP request, target xpath, target xpath in Property Transfer, target xpath in SOAP UI, transfer, transfer in SOAP UI, Transfer properties, Transfer Property in SOAPUI 总结
以上是内存溢出为你收集整理的Groovy in SOAP UI全部内容,希望文章能够帮你解决Groovy in SOAP UI所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)