Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an export to excel feature in our application. For which I have one scenario:

  1. Perform export to excel
  2. Validate API response status and exported excel content.

With Postman, I am able to save exported excel in .xlsx format with "Send and Download" option on which later I am validating content (Column Headers and row values) manually.

Is there any way to automate this scenario end to end through API automation?

Currently, I am doing get operation (Karate framework) which is responding me these headers in response:

  1. Content-Type →application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

  2. Accept-Ranges →bytes

Body: Stream objects which are not human readable.

Status: 200 ok

If e2e automation not possible/feasible, what should be the acceptance criteria for automation in this case than?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
935 views
Welcome To Ask or Share your Answers For Others

1 Answer

Find out a way to implement the solution with Java and Karate. Below are the steps:

  1. Send your responsebytes to a java class Utility. This is how I did in Karate feature file:

    And def helper = Java.type('com.java.Utility') And def excel = helper.ByteArrayToExcel(responseBytes)

  2. In Utility class, you will have a ByteArrayToExcel method which will contain this code:

    import org.apache.commons.io.FileUtils;

    FileUtils.writeByteArrayToFile(new File("srcestjavaestdataActual_Response.xlsx"), ResponseBytes);

  3. Now, You will have the excel in the specified location.

  4. Write a method to compare two excel file (Actual and your expected one for the particular request). Google it, you will find the code. Specify, its return type to boolean.

  5. In Karate, use the boolean like this:

And match excelCompareResult == true

Hope it will help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...