Search code examples
automationrest-assuredkarateweb-api-testing

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?


Solution

  • 2 options.

    1. If you are sure the binary contents of the file will never change, do a binary comparison, see this example: upload-image.feature: And match response == read('karate-logo.jpg')

    2. You have to write some custom code. There are Java libraries to read Excel. Use one of those, read the data, and then compare with expected results. Refer the docs on Java interop and write a helper function to do this.

    EDIT - also see this answer: https://stackoverflow.com/a/53050249/143475