Forum Discussion

cstott1's avatar
cstott1
Occasional Contributor
9 years ago

Generate Test Data Using Groovy

 

 

 

 

Hi,

 

I am looking to generate test data (amended postcodes) from a datasource using a Groovy Script however currently I am only able to pick up one row.

 

Currently my test case is setup as per below:

 

1) Datasource - Contains a list of postcodes in a grid:

 

H4O 0SD
Y68 5LI
C1K 6ZI
G84 4PJ
LI1B 0FC
Y08 0TB
A1 7ZM
OQ5 2SV
O1X 6CK
P4Z 6PJ
CG7O 4HV
G8L 6RG
J5 1FE

DO7 7EV

 

2) I then have a DataGen setup where I run the below Groovy step in order to amend the postcode


def postCode = context.expand( '${DataSource#PostCode

return [
postCode.toLowerCase (),
postCode.toUpperCase (),
postCode.stripIndent (1),
postCode.stripIndent (2),
postCode.stripIndent (3),
postCode.stripIndent (4),
postCode.stripIndent (5),
postCode.stripIndent (6),
postCode.stripIndent (7),
postCode.stripIndent (8)

]

 

However this script only picks up the postcode DO7 7EV and runs the above returns on this postcode which results in the below:

 

[do7 7ev, DO7 7EV, O7 7EV, 7 7EV, 7EV, 7EV, EV, V, , ]

 

However i'm looking for the script to run through one Postcode at a time and amend it once with a return. for example if I had this list

 

H4O 0SD
y68 5li
C1K 6ZI
G84 4PJ

 

and these returns

 

return [
postCode.toLowerCase (),
postCode.toUpperCase (),
postCode.stripIndent (1),
postCode.stripIndent (2),

 

I would be looking for the below as an output to use as test data:

 

h40 0sd
Y68 5LI
1K 6ZI
4 4PJ

 

Any ideas how I can amend the script or whether this is the correct way of generating test data by amending a list of values?

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    looks something missing from your post. Please check and edit to make it complete.
    • cstott1's avatar
      cstott1
      Occasional Contributor

      apologies I've updated it Rao :-)