如何比较空手道中下载的文件?

How to compare downloaded file in karate?

我想比较文本文件,但是 API 正在返回 application/octet-stream,我目前无法更改。这就是为什么空手道可能会尝试比较二进制文件并进行测试。这意味着:

    Given path '/download/testing/'+fileId
    When method get
    Then status 200
    And match response == read('../files/test.txt')

导致:

match failed: EQUALS
$ | data types don't match (LIST:STRING)
  [116,101,115,116,105,110,103]
  'testing'

文件 test.txt 仅包含 testing。我找不到如何将字符串转换为字节数组的方法。我可能会使用 java 函数,但首先我想看看是否有一些内置函数。

您可以进行类型转换:https://github.com/karatelabs/karate#type-conversion

所以这会将二进制响应转换为文本:

* string response = response

这应该让你继续。反之亦然。

为了完整起见,请注意 responseBytes 变量将始终包含 response 的副本,但作为字节数组。