Ask a Question

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

sonya_m
SmartBear Alumni (Retired)

[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 

DifficultyStar_Gold.pngStar_gray.pngStar_gray.png

 

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🙂


Sonya Mihaljova
Community and Education Specialist

5 REPLIES 5
groovyguy
Champion Level 0

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.

 

 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
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🙂


Sonya Mihaljova
Community and Education Specialist

@sonya_m :

 

I was trying to access the above link posted in original question but it is showing me some error could you please check.

 

https://petstore.swagger.io/v2/pet/findByStatus?status=available


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



Thanks and Regards,
Himanshu Tayal
sonya_m
SmartBear Alumni (Retired)

Hi @HimanshuTayal ! I just checked this link: https://petstore.swagger.io/v2/pet/findByStatus?status=available

It is working for me in Chrome and Edge. Could it be a temporary issue? 


Sonya Mihaljova
Community and Education Specialist

sonya_m
SmartBear Alumni (Retired)

@nmrao @avidCoder @richie Would you like to participate?🙂


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: