Karate DSL : Unable to convert string characters from different languages while reading json file

标签 karate

我试图将整个响应与 json 文件匹配。

    Background:
    * url BaseURL
    * def resp =  read('response_get_discount.json') // Reading json file

   Scenario: Verify Users discount
    Given path '/discount'
    When method get
    Then status 200
    * match response == resp //Trying to match whole response with the output of the above json file

问题:

我的 json 文件在西类牙有以下输出:

    {
    "familyCode": "DH",
    "validityStart": 1575500400000,
    "description": "Aparamenta modular Limitadores sobretensiones + Gestión Energía  (SPD + CCB)"
}

请注意“Gestión Energía”一词,当它从文件读取时,它会被转换为“Gestión Energía”。 因此它无法与响应与响应匹配。

有没有办法忽略或处理此类编码字符?

最佳答案

请阅读文档中的此部分:https://github.com/intuit/karate#fileencoding

The solution is to ensure that when Karate tests run, the JVM file.encoding is set to UTF-8. This can be done via the maven-surefire-plugin configuration. Add the plugin to the <build>/<plugins> section of your pom.xml if not already present:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <argLine>-Dfile.encoding=UTF-8</argLine>
    </configuration>
</plugin>

编辑:这是一个文件编码问题 - 请参阅评论

I have figured out the fix as per your suggestion. Since I was using eclipse , i did below steps to encode json properly. Windwos -- preferences -- General -- Workspace : Under Text encoding , selected Others -- UTF-8. Apply and restart ecplise.

关于 Karate DSL : Unable to convert string characters from different languages while reading json file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59208117/

相关文章:

karate - 我们可以循环功能文件并在 Karate 中使用多个登录用户执行吗

javascript - Karate 模糊匹配 - 构建自定义标记

karate - 如何在另一个特征文件的javascript函数中调用我的特征文件函数?

cucumber - Karate 测试框架: Only one assert using Examples

karate - 如何使用Karate Framework中的功能文件调用Android模拟器

localization - 如何在 Karate 框架中使用小 cucumber 本地化?

automated-tests - Karate - 输入字段/文本区域清除字段无法正常工作

cucumber - 在 cucumber 中使用背景部分时出现 "required (...)+ loop did not match anything at input ' 场景 :'"错误

Karate xpath - 我们可以替换/删除节点吗

testing - 从命令行运行 Karate 测试会返回surefire-plugin 错误