okcjosh
12 years agoOccasional Contributor
Passing Values from Groovy Script into Request
Due to an immediate change in my company we are loosing our SoapUi Pro licenses and I am tasked with taking a rather large testcase and porting it to the community version of SoapUI. Unfortunately, this project uses the 'DataGen' teststep rather heavily. I have successfully re-created what the 'DataGen' test step produced. It is pasted below. Everyone is welcome to use any of this as they see fit. But I need help immediately with the following: How do I use the created values from my GroovyScript in my Request? How do I pass these values directly into the XML call or into a properties transfer test step. For the life of me nothing is working. I pasted the results of the log as well. This proves my script is working as designed and giving me 12 random values that are used to create a customer profile. How do I go about putting these values into the XML request? In the pro version the datagen properties were mapped directly into the request and wallah! Please Help!!
LOG RESULTS
Mon Jun 17 00:04:18 CDT 2013:INFO:EmailAddress DGKOOFL9B795@42.okcjosh.com
Mon Jun 17 00:04:18 CDT 2013:INFO:FirstName JEIRWEWY
Mon Jun 17 00:04:18 CDT 2013:INFO:LastName VVCIWRQQ
Mon Jun 17 00:04:18 CDT 2013:INFO:DateofBirth 03-28-1975
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationNumber 7KM6VD5HLASAPDL
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationState GA
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationIssueDate 00-13-2011
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationExpirationDate 09-27-2015
Mon Jun 17 00:04:18 CDT 2013:INFO:AddressLine1 0WN1U0JSNXASAPADDRESSX
Mon Jun 17 00:04:18 CDT 2013:INFO:City GFAEDPNXASAPCITYX
Mon Jun 17 00:04:18 CDT 2013:INFO:AddressState NM
Mon Jun 17 00:04:18 CDT 2013:INFO:Zip 70200
XML REQUEST
def random = new Random()
def xxx = { String alphabet, int n ->
new Random().with {(1..n).collect
{ alphabet[ nextInt( alphabet.length() ) ] }.join() } }
def idstate =
["AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"]
def xstate = random.nextInt(idstate.size())
def addystate =
["AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"]
def ystate = random.nextInt(addystate.size())
def dobyear = (1960 + random.nextInt(31))
def xmonthx = random.nextInt(13)
def xdayx = random.nextInt(31)
def idissueyear = (2008 + random.nextInt(5))
def ymonthy = random.nextInt(13)
def ydayy = random.nextInt(31)
def idexpireyear = (2013 + random.nextInt(5))
def zmonthz = random.nextInt(13)
def zdayz = random.nextInt(31)
xmonthx = ( xmonthx < 10 ) ? "0" + xmonthx : "" + xmonthx
xdayx = ( xdayx < 10 ) ? "0" + xdayx : "" + xdayx
ymonthy = ( ymonthy < 10 ) ? "0" + ymonthy : "" + ymonthy
ydayy = ( ydayy < 10 ) ? "0" + ydayy : "" + ydayy
zmonthz = ( zmonthz < 10 ) ? "0" + zmonthz : "" + zmonthz
zdayz = ( zdayz < 10 ) ? "0" + zdayz : "" + zdayz
email = xxx ( (('A'..'Z')+('0'..'9')).join(), 12 )+ '@42.okcjosh.com'
firstname = (xxx ( (('A'..'Z')).join(), 8 ))
lastname = (xxx ( (('A'..'Z')).join(), 8 ))
dob = (xmonthx + '-' + xdayx + '-'+ dobyear)
identid = xxx ( (('A'..'Z')+('0'..'9')).join(), 9 )+ 'ASAPDL'
identissue = (ymonthy + '-' + ydayy + '-'+ idissueyear)
identex = (zmonthz + '-' + zdayz + '-'+ idexpireyear)
address = xxx ( (('A'..'Z')+('0'..'9')).join(), 9 )+ 'XASAPADDRESSX'
city = xxx ( (('A'..'Z')).join(), 7 ) + 'XASAPCITYX'
zip = xxx ( (('0'..'9')).join(), 5 )
log.info"EmailAddress $email"
log.info"FirstName $firstname"
log.info"LastName $lastname"
log.info"DateofBirth $dob"
log.info"IdentificationNumber $identid"
log.info"IdentificationState ${idstate [xstate]}"
log.info"IdentificationIssueDate $identissue"
log.info"IdentificationExpirationDate $identex"
log.info"AddressLine1 $address"
log.info"City $city"
log.info"AddressState ${addystate [ystate]}"
log.info"Zip $zip"
LOG RESULTS
Mon Jun 17 00:04:18 CDT 2013:INFO:EmailAddress DGKOOFL9B795@42.okcjosh.com
Mon Jun 17 00:04:18 CDT 2013:INFO:FirstName JEIRWEWY
Mon Jun 17 00:04:18 CDT 2013:INFO:LastName VVCIWRQQ
Mon Jun 17 00:04:18 CDT 2013:INFO:DateofBirth 03-28-1975
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationNumber 7KM6VD5HLASAPDL
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationState GA
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationIssueDate 00-13-2011
Mon Jun 17 00:04:18 CDT 2013:INFO:IdentificationExpirationDate 09-27-2015
Mon Jun 17 00:04:18 CDT 2013:INFO:AddressLine1 0WN1U0JSNXASAPADDRESSX
Mon Jun 17 00:04:18 CDT 2013:INFO:City GFAEDPNXASAPCITYX
Mon Jun 17 00:04:18 CDT 2013:INFO:AddressState NM
Mon Jun 17 00:04:18 CDT 2013:INFO:Zip 70200
XML REQUEST
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<AddCustomerRequest ReasonCd="M62" UserId="XXXASAPTESTINGXXX" Version="13.1.2" xmlns="urn:hertz.com:crm:v1">
<Source Channel="COUNTER" SystemId="USOKDCR1501298" SystemType="ASAP"/>
<Customer ChangeAction="ADD" CustomerType="IND" LastModifiedBy="">
<Profile OrgCd="HRAC" ChangeAction="ADD" StatusCd="A">
<Person BirthDate="${HELP!}" FirstName="{HELP!}" LastName="${HELP!}" ChangeAction="ADD"/>
<Identification CountryCd="US" ExpirationDate="${HELP!}" IdentId="${HELP!}" IdentType="DL" StateProvCd="${HELP!}"IssueDate="${HELP!}"ChangeAction="ADD"/>
<Addresses>
<StreetAddress PrimaryInd="true" UsageType="HOME" ChangeAction="ADD"/>
<AddressLine1>"${HELP!}"</AddressLine1>
<City>"${HELP!}"</City>
<PostalCode>"${HELP!}"</PostalCode>
<StateProvCd>"${HELP!}"</StateProvCd>
<CountryCd>US</CountryCd>
</StreetAddress>
<Email Address="" PrimaryInd="true" UsageType="HOME" ChangeAction="ADD"/>
</Addresses><LoyaltyMembership MemberNum="" ProgramCd="N1" ServiceStatusCd="p" MemberStatusCd="A"><Tier TierCd="RG"/></LoyaltyMembership>
</Profile>
</Customer>
</AddCustomerRequest>
</S:Body>
</S:Envelope>