API 自动化测试:有没有办法通过内容验证来自动化下载场景? [英] API Automation Testing : Is there any way to automate download scenario with content validation?

查看:21
本文介绍了API 自动化测试:有没有办法通过内容验证来自动化下载场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我们的应用程序中有一个导出到 excel 的功能.我有一个场景:

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

  1. 执行导出到 Excel
  2. 验证 API 响应状态和导出的 excel 内容.

使用 Postman,我可以使用发送和下载"选项将导出的 excel 保存为 .xlsx 格式,稍后我将手动验证内容(列标题和行值).

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.

有什么办法可以通过 API 自动化端到端地自动化这个场景吗?

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

目前,我正在执行 get 操作(空手道框架),它正在响应这些标头:

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

  1. 内容类型→application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

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

接受范围→字节

Body:非人类可读的流对象.

Body: Stream objects which are not human readable.

状态:200 正常

如果 e2e 自动化不可能/不可行,那么在这种情况下自动化的验收标准应该是什么?

推荐答案

2 个选项.

  1. 如果你确定文件的二进制内容永远不会改变,做一个二进制比较,看这个例子:upload-image.feature:并匹配响应==阅读('空手道标志.jpg')

您必须编写一些自定义代码.有 Java 库可以读取 Excel.使用其中之一,读取数据,然后与预期结果进行比较.请参阅有关 Java 互操作的文档并编写一个辅助函数来执行此操作.

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.

编辑 - 另请参阅此答案:https://stackoverflow.com/a/53050249/143475

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

这篇关于API 自动化测试:有没有办法通过内容验证来自动化下载场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆