空手道 - 如何处理 unicode 字符?

Karate - How to deal with unicode characters?

我想像这样发送一个 Unicode 字符串作为请求参数:

{"mobile": "۹۸.۹۱۲۳۴۳۰۴۱۲"}

但是空手道是这样发送的: {"mobile":“??。????????”} 我尝试从包含我的文本的文件中读取 Unicode 文本:

۹۸.۹۱۲۳۴۳۰۴۱۲

然后这样阅读并发送:

* def persianMobile1 = read('classpath:account/unicode/persian.mobile.txt')

        Given url karate.get('urlBase') +  "account/activateMobileByVerificationCode"
        And request
      """
      {
       "mobile":#(persianMobile1),
       "code":#(defaultVerificationCode)
      }
      """

出现同样的问题。我该怎么办?

pom.xml 中设置 maven-surefire-plugin 以使用 UTF-8 文件编码。添加此 <plugin>(如果尚不存在)。

        <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>

编辑:看起来 OP 正在使用 Gradle。您需要获得空手道(我假设是通过 JUnit 运行)将 JVM file.encoding 设置为 UTF-8 - 以解决此问题。

这里有一个 link 可以帮助您在 Gradle 中做到这一点:https://discuss.gradle.org/t/no-possibility-to-set-file-encoding-for-junit-tests-in-gradle-2-13-and-odler/17223

如果需要,我建议您与 Java 开发人员合作。