Forum Discussion

connectnishant's avatar
connectnishant
New Contributor
4 years ago
Solved

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.

  • HimanshuTayal's avatar
    HimanshuTayal
    4 years ago

    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.

     

5 Replies

  • richie's avatar
    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
    • connectnishant's avatar
      connectnishant
      New Contributor

      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.

      • HimanshuTayal's avatar
        HimanshuTayal
        Community Hero

        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.