Ask a Question

Dynamic Rest request creation for an update payload

SOLVED
connectnishant
New Contributor

Dynamic Rest request creation for an update payload

I have a requirement to test an update request which can update more than 1 phone number. 

I am using a data driven framework, and was passing the values from excel with 1 to 1 request element mapping.

however in this case, I have to test cases where there can be one number/2 numbers to update/ so and so forth.

This is not possible with my current framework, hence i need some help in a way to create this request dynamically. 

I am thinking of a way in which if the data excel data sheet has a column with number of phones to update as 3, my request should be created with 3 phonenumbers. The phone number array has multiple elements: 

{

phoneNumber1

PhoneType1

extension1

contactPreference1

etc

}

{

phoneNumber2

PhoneType2

extension2

contactPreference2

etc

}

{

phoneNumber3

PhoneType3

extension3

contactPreference3

etc

}

I am very new to Groovy and any help would be greatly appreciated. Using Groovy, if we can create a requst, I would also need help in passing that to my actual request step in the framework.

 

Please help.

5 REPLIES 5
richie
Community Hero

Hey @connectnishant,

You could cheat and rather than try it with groovy, you could just add the request's whole payload into each field in the spreadsheet and then it wouldnt matter how any repeating phone number records you had in your payload (so youd just have a '${Datasource #property}' value in your REST test steps payload field).
The added advantage of using this approach would be it wouldnt take much to change your existing setup in ReadyAPI!/SoapUI....the changes would be minimal.

Just a suggestion,

If you want to use groovy id suggest using a csv as the datasource file instead...i always find it easier with a .csv than .xls format.

If you respond back saying whether you want do 'cheat' (which i completely advocate) or use groovy.
if you want groovy it'll take me a couple or hours to put it together.... the other forum members are a lot better coders than me, but if they dont respond in time i'll put the groovy together.

Nice one

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

Hello @richie 

Thank you so much for taking time out of your busy schedule and looking in to the problem i am facing. Really appreciate it.

The solution you provided seems viable for a short term, however i believe it will have lot of maintenance involved in long term and if we will have to run this regularly.

I request you to please help me with the groovy scripts as well, where we can dynamically create the Json request. 

Thank you so much for all your help.

@connectnishant :

 

What you can do is pass phone number with "," separated like 1111111,2222222,333333,444444

 

and then split your number with comma in groovy and create dynamic request with number size.

 

//Get phone Number with , seperated from Excel sheet
def phoneNumber = excelsheet(phone__number);

//Split phone number with ,
int phoneNumberSplit = phoneNumber.split(",")
//loop the number of phone number
for(int i = 0 ; i < phoneNumberSplit.size() ; i++){
//generate dynamic request
// Create your dynamic request with phoneNumberSplit[i]
}

 

Let me know if you need more help on this.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

Hey @connectnishant,

See? Wouldve taken me 2 or 3 hours and @HimanshuTayal knocks it out in 5 mins!🤷‍♂️

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
sonya_m
SmartBear Alumni (Retired)

Thank you Himanshu and Richie! You are just using different approaches to things and this is awesome I think 😊

 

@connectnishant could you let us know what helped and mark the appropriate message as a solution?


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: