Professional Documents
Culture Documents
http://webservices-testing.blogspot.de/2012/04/how-to-access-project-test-suitetest.html #Project# #"est#uite# #"est$ase# #%oc&#ervice# #'lobal# ##!stem# #*nv# +"est#tep name,# - re erences a Project propert! - re erences a "est#uite propert! in the containing "est#uite - re erences a "est$ase propert! in the containing "est$ase - re erences a %oc&#ervice propert! in the containing %oc&#ervice - re erences a global propert! (optional) - re erences a s!stem propert! - re erences a environment variable - re erences a "est#tep propert! within the current "est$ase
Reading the properties from the Same level !! "et propert#es from test Case$ test %&#te and pro'ect
de test$asePropert! - test.unner.test$ase.getPropert!/alue (0$ountr!0 ) log.in o test$asePropert! de test#uitePropert! - test.unner.test$ase.test#uite.getPropert!/alue( 0$ountr!0) log.in o test#uitePropert! de projectPropert! test.unner.test$ase.test#uite.project.getPropert!/alue( 0$ountr!0 ) log.in o projectPropert! de globalPropert! com.eviware.soapui.#oap12.globalProperties.getPropert!/alue( 03PPass0 ) log.in o globalPropert!
import com.eviware.soapui.support.4 re5uest - conte6t.e6pand(789all'oal3eeper#re5uest:7) de holder-new ;ml<older(re5uest) holder.set=ode/alue(0// oot:s$ountr!=ame0>7?ra@il7) //setting node value o re5uest holder.updatePropert!() test.unner.test$ase.get"est#tep?!=ame(0all'oal3eeper0).setPropert!/alue(0re5uest 0>holder.get;ml()) de runner-test.unner.run"est#tep?!=ame(0all'oal3eeper0) de status-runner.get#tatus() log.in o status
import com.eviware.soapui.support.4 import com.eviware.soapui.support.components.4 $on igurationAialog Aialog-12#upport.create$on igurationAialog(0"est0) %ap values - new <ash%ap() values.put(0*nter =ame0>00)B Aialog.add"e6tGield(0*nter =ame0> 0"ool"ip0) Aialog.show(values) var-values.get(0*nter =ame0) log.in o var
To +apture a pass(ord
import com.eviware.soapui.support.4 import com.eviware.soapui.support.components.4 char+, Password - 12#upport.promptPassword(0*nter Password0> 0Password #creen0) #tring var-new #tring(Password) log.in o var
//get re5uest de re5uest - test.unner.test$ase.get"est#tep?!=ame( 0.e5uest 10 ).test.e5uest // clear e6isting attachments or( a in re5uest.attachments ) 9 re5uest.removeQttachment( a ) : // get ile to attach //de ile=ame - conte6t.e6pand( 789#ource o data#Path"o;.$ Gile data name :7 ) de ile=ame - conte6t.e6pand( 789#"est$ase#;.$H ileHname:7 ) de ilePath - conte6t.e6pand( 789#"est$ase#;.$H ilesHpath:7 ) log.in o 0 ile: 0 R ilePath R ile=ame de ile - new Gile( ilePath R ile=ame ) i ( ile -- null) 9 log.error 0bad ilename0 : else 9 // attach and set properties de attachment - re5uest.attachGile( ile> true ) attachment.content"!pe - 0application/octet-stream0 de list - ile=ame.to&eni@e(0SS0)B attachment.setPart(list.last()) //de holder2 - groov!1tils.get;ml<older( 0.e5uest 1#.e5uest0 ) // 'et .e5uest bod! //de startAate2 holder2.set=ode/alue( 0//blac:Gile?!te#tream0>0cid:0Rlist.last())B //#et 0lin&0 to attachment in re5uest bod! //holder2.updatePropert!() //and update // attachment.setPart(list.last())B //set attachment :
The top area is a standard soap() script editor, with corresponding popup menu and actions. The *un button e%ecutes the assertion script against the last received response and displays the result in a popup window. The bottom shows the output of the log variable available in the script.
The message+%change ob ect available in the script e%poses a bunch of properties related to the last re,uest-response messages !chec. out the Javadoc$, lets loo. at some simple e%amples/ 0. Validate the content of an HTTP Header in the response
// check that response time is less than 400 ms assert messageExchange.timeTaken !""
Validate the e%istence of an attachment in the response
// check for RequestId element in response de% holder = ne& 'mlHolder( messageExchange.response)ontent#s'ml * assert holder["//ns1 RequestId"! "# null
This last e%ample is greatly simplified in soap() Pro which adds a corresponding wi4ard to the 5utline +ditor'
Method Summary
.peration $et'peration(* +tringTo+tring,ap $et(roperties(* +tring /0te[] /0te[] #ttachment[] #ttachment[] +tring $et(ropert)(+tring name* $etRawRequest*ata(* $etRawResponse*ata(* $etRequest+ttachments(* $etRequest+ttachments,or(art(+tring part1ame* $etRequest-ontent(*
+tring $etRequest-ontent+s.ml(* +tringTo+trings,ap $etRequest/eaders(* 2esponse #ttachment[] #ttachment[] +tring $etResponse(* $etResponse+ttachments(* $etResponse+ttachments,or(art(+tring part1ame* $etResponse-ontent(*
+tring $etResponse-ontent+s.ml(* +tringTo+trings,ap $etResponse/eaders(* long long /oolean /oolean /oolean /oolean $et0imestamp(* $et0ime0aken(* hasRaw*ata(* hasRequest(/oolean ignoreEmpt0* hasResponse(* is*iscarded(*
1erif) %lements of %ach 0)pe are *escendin$ 2) 3core import com.e3i&are.soapui.support.'mlHolder import 4a3a.util.5 de% groo306tils = ne& com.e3i&are.soapui.support.7roo306tils( context *8 de% holder = groo306tils.get'mlHolder( messageExchange.response)ontent#s'ml * de% node)ount = holder["count(99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns1:e*"] de% currentT0pe; current+core = "" de% t0pe<ist = [] de% %ound = %alse de% index = " currentT0pe = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[1]9ns1:result[1]9ns1:t0pe[1]" * current+core = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[1]9ns1:result[1]9ns1:score[1]" * t0pe<ist.add( [ currentT0pe; current+core ] * node)ount = node)ount.to-nteger(* %or ( i = $8 i currentT0pe = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[" > i > "]9ns1:result[1]9ns1:t0pe[1]" * current+core = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[" > i > "]9ns1:result[1]9ns1:score[1]" * t0pe+ize = t0pe<ist.size(* %or ( 0 = "8 0 index = 0 %ound = true /reak @ @ i% ( %ound *? pre3ious = t0pe<ist[ index ] t0pe+ize8 0>> *? i% ( t0pe<ist[ 0 ].contains( currentT0pe * *? node)ount8 i>> *?
0he 4niversal 35+ +ssertion 6makes mana$in$ sla assertion values a one7 stop7shop8 de% slaBtimeBtaken = messageExchange.getTimeTaken(*8 de% slaBtime = context.expand( CD?EFro4ectEslaBtime@C *.to-nteger(*8 assert slaBtimeBtaken slaBtime8
/eader Information +ssertion de% headers = messageExchange.get2esponseHeaders(*8 de% mapBke0 = context.expand( CD?EFro4ectEmapBke0@C *8 de% mapB3al = context.expand( CD?EFro4ectEmapB3al@C *8 assert headers.get(mapBke0*.to+tring(* == mapB3al8
1erif)in$ 'rder of Response %lements 2) %lement 1alue +ssertion import com.e3i&are.soapui.support.'mlHolder8 de% /oBhost = context.expand( CD?EFro4ectEpro4ectBhost@C *8 de% groo306tils = ne& com.e3i&are.soapui.support.7roo306tils( context *8 de% holder = groo306tils.get'mlHolder( messageExchange.response)ontent#s'ml *8 de% node)ount = holder["count(99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns1:e*"]8 de% expected)ount = context.expand( CD?EFro4ectEexpectedBreturnBcount@C *8 node)ount = node)ount.to-nteger(*8
assert node)ount == expected)ount8 pre3iousFla0)ount=alue = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[1]9ns1:result[1]9ns1:track[1]9ns1:pla0counts[1]" *.to-nteger(*8 %or( int i = $8 i = node)ount8 >>i *?
currentFla0)ount=alue = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:search[1]9ns1:results[1]9ns 1:e[Di]9ns1:result[1]9ns1:track[1]9ns1:pla0counts[1]" *.to-nteger(*8 assert pre3iousFla0)ount=alue A= currentFla0)ount=alue8 pre3iousFla0)ount=alue = currentFla0)ount=alue8 @
9re$orian *ate 3trin$ :uilder de% g)alendar = ne& 7regorian)alendar(*8 de% return+tring = null8 g)alendar.time-n,illis = +0stem.currentTime,illis(*8 return g)alendar.get()alendar.GE#2* > "-" >H g)alendar.get()alendar.,.1TH* > "-" > ( g)alendar.get()alendar.I#TE* - 1 * >H " " > g)alendar.get()alendar.H.62B.JBI#G* > ":" > g)alendar.get()alendar.,-16TE* >H ":" > g)alendar.get()alendar.+E).1I*8
Random ;on7Repeatin$ I*s 3trin$ :uilder de% standardBcount = context.expand( CD ?FropertiesEstandardBcount@C *.to-nteger(*8 de% trackBrange = context.expand( CD ?FropertiesEtrackBrange@C *.to-nteger(*8 de% generator = ne& 2andom(*8 de% randomBint = generator.next-nt( trackBrange *8 de% randomBintBstring; returnBstring = randomBint.to+tring(*8 de% 4umpBstring = ""8 %or ( i = 18 i standardBcount8 i>> * ?
trackBrange * ?
Reversin$ I*s 3trin$ :uilder de% original = context.expand( CD?FropertiesEtracks@C *8 de% tokens = original.tokenize("; "*8 de% size = tokens.size(*8 de% ne&=alue = ""8 ne&=alue = tokens[ " ]8 tokens.remo3e( " *8 %or ( current in tokens * ? i% ( current != null KK current != "" * ? ne&=alue = ne&=alue > "; " > current8 @ @ return ne&=alue8
3huffle I*s 3trin$ :uilder de% original = context.expand( CD?FropertiesEtracks@C *8 de% tokens = original.tokenize("; "*8 de% size = tokens.size(* - 18 de% ne&=alue = ""8 de% generator = ne& 2andom(*8 i% ( size A " * ? int r = generator.next-nt(size* > 18
ne&=alue = tokens[r]8 %or ( i in 1..size * ? r = generator.next-nt(size > 1*8 ne&=alue = ne&=alue > "; " > tokens[r]8 tokens.remo3e(r*8 size = tokens.size(* - 18 @ @ else ? ne&=alue = original8 @ return ne&=alue8
Response %lements 1alues 3trin$ :uilder de% groo306tils = ne& com.e3i&are.soapui.support.7roo306tils( context *8 de% holder = groo306tils.get'mlHolder( context.expand( CD?Fu/lish Fla0listE2esponse#s'ml@C **8 de% node=alue = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:&arning[1]9ns1:%ailBtoBadd[ 1]9ns1:e[1]9text(*" *8 de% i = 18 returnBstring = context.expand( CD?FropertiesE/lacklistedBtrackBids@C *8 &hile ( node=alue != null * ? i% ( ! returnBstring.contains( node=alue * * ? returnBstring = returnBstring > "; " > node=alue8 @ i>>8 node=alue = holder.get1ode=alue( "99ns1:2esponse[1]9ns1:&arning[1]9ns1:%ailBtoBadd[ 1]9ns1:e[" > i.to+tring(* > "]9text(*" *8 @ return returnBstring8
Random -haracters 3trin$ :uilder de% generator = ne& 2andom(*8 de% count = ( context.expand( CD?+earch FropertiesEsearchBstringBlength@C *.to-nteger(* *8 de% r = generator.next-nt( count >1 * >18 de% tokenBstring = <ong.to+tring( ,ath.a/s(generator.next<ong(* *; ML*8 return tokenBstring.get#t( 1..count *8
import 4xl.5 import 4xl.&rite.5 Nrita/leNork/ook &ork/ook = Nork/ook.createNork/ook(ne& Jile(C):99Test9output.xlsC** Nrita/le+heet sheet = &ork/ook.create+heet("Norksheet 1"; "* 99log.in%o(sheet1.isHidden(** <a/el la/el = ne& <a/el("; $; "Test data in )olumn #; 2o& M"*8 99column="=#;ro&="=1 sheet.add)ell(la/el*8 <a/el la/el1 = ne& <a/el($; $; ")olumn ); 2o& M"*8 sheet.add)ell(la/el1*8 &ork/ook.&rite(* &ork/ook.close(*
import 4xl.58 context.setFropert0("countr01ames"; ne& readExcel(**8 pu/lic class readExcel? Nork/ook &=Nork/ook.getNork/ook(ne& Jile(C):99Iocuments and +ettings9amunaga9Iesktop9Fro4ect9Fro4ect9IataOase.xlsC**8 99return allElements o% )olumn 99<ist get=alues(int sheet-ndex;int col-ndex* <ist get=alues(int sheet-ndex;int col-ndex*? de% m0+heet=&.get+heet(sheet-ndex*8 <ist name=[]8 de% count2o&s=m0+heet.get2o&s(*8 %or (de% i=18i count2o&s8i>>*? name[i-1]=m0+heet.get)ell(col-ndex;i*.get)ontents(* log.in%o name[i-1] @ return name @ @