This is how my test looks like:
- Sterp1: Outer loop DataSource( returns customerId and number of accounts for each customer from DB) For the example I shared earlier, this select would return 4 lines:
- Customer1,1 (customer1 has one account)
- customer2, 3 (customer2 has three accounts)
- customer3, 1 (customer3 has one account)
- customer4, 4 (customer4 has four accounts)
- Step2: Call API using customer ID. API returns json with details for all the accounts of the customer.
- Step3: Assert that the API retuned the correct number of accounts
- Step4: Inner Loop Datasource (returns the account details for all the customer's accounts)
- Step5: Assert that the account details of the current row exist in the json response
- Step6: Inner Data Source loop
- Step7: Outer Data Source Loop
So, in the outer loop I check that the API response json has the correct number of accounts for the customer, and in the inner loop I check that each account is correctly represented in the response json.
So for the above example, the outer loop would be executed 4 times and the API would be called 4 times, once per customer. The inner loop would be executed once for Customer1, 3 times for customer2, once for customer3 and 4 times for customer4.
"However, it is possible to do entirely in single groovy script too if one wishes to do so. It will be little lengthy."
I still can't see how to I can do this using just a simple loop!