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

Categories

0 votes
978 views
in Technique[技术] by (71.8m points)

rest assured - API Automation Testing : Is there any way to automate download scenario with content validation?

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...