Karate - How to deal with unicode characters?

孤街醉人 提交于 2020-01-24 20:01:05

问题


I want to send a Unicode string as a request parameter like this:

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

but Karate send it like this instead: {"mobile": "??.??????????"} I've tried to read Unicode text from a file contains my text:

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

then read and send it this way:

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

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

Same problem occurred. What should I do?


回答1:


Set the maven-surefire-plugin in your pom.xml to use the UTF-8 file encoding. Add this <plugin> if it is not there already.

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

EDIT: looks like OP is using Gradle. You need to get Karate (which I assume is run via JUnit) to have the JVM file.encoding set to UTF-8 - to fix this.

Here is a link that should help you do this in Gradle: https://discuss.gradle.org/t/no-possibility-to-set-file-encoding-for-junit-tests-in-gradle-2-13-and-odler/17223

I suggest you work with a Java dev if you need to.



来源:https://stackoverflow.com/questions/46986687/karate-how-to-deal-with-unicode-characters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!