Forum Discussion

sonya_m's avatar
sonya_m
SmartBear Alumni (Retired)
4 years ago

[TechCornerChallenge #12] A script to get data from Petstore and add it to Excel sheets

Hello ReadyAPI Сommunity!

 

We have another task for you to put your ReadyAPI knowledge to the test. Check out the participation rules and the TechCorner Leaderboard here.

 

In this task, we will be having you use Groovy DataSink to write results from a data source to a file.

 

Task: Write a Groovy script that will take data from Swagger Petstore and add them to different excel sheets 

Difficulty

 

Exporting the results to one file can be done easily, but, sometimes, you need to sort data to different sheets inside it or to separate files.

From the request, put the IDs of cats in one or sheet of an Excel table, the IDs of dogs in another, all the rest should go to the third one ("Others").

 

Bonus: You can gain an additional point if you create two scripts: 1) for putting data into separate Excel sheets within one file and 2) into separate Excel files. 

 

The best of luck to all participants🙂

5 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    I'll admit, I have not used swagger so I am not familiar with this particular method. Is it okay if I download the xml response and use that to fuel an XML datasource and write the script from there? I also do not see anything in the provided response that differentiates between cats and dogs

     

    Digging a little deeper, it looks like there are three distinct ID values. 0, 5, and 55. I missed that at first, because the data I saw is mostly 0's so I lost the 5 and 55.

     

     

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Hi groovyguy , these are great valid questions! 

       

      So, to tell cats from dogs, you can use Tags. Since this is an open database, a lot of pets added there have no Tags. So, you can go ahead and add a couple of pets with Tags to it to be sorted using the POST/ pet method  (https://petstore.swagger.io/#/pet/addPet)

       

      DataSink is supposed to work with DataSource, so the DataSource test step will use Petstore's response as a data source, while the DataSink script will handle each pet.

       

      I hope this clarifies things a bit🙂 Let me know if more clarification is required🙂