3

I was trying to match whole response with a json file.

    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

Problem:

My json file has below output in Spain:

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

Please note the words "Gestión Energía", when it is reading from file it is being converted to "Gesti�n Energ�a". Hence it is failing to match with response vs resp.

Is there a way to ignore or handle such encoding characters?

1 Answers1

1

Please read this section in the docs: 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>

EDIT: this was a file-encoding issue - see comments

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.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thank you for your fast response. I added the above plugin to POM, but still no luck. I still see the UNICODE characters in my eclipse console. Not sure what am I doing wrong. – Avishek Behera Dec 06 '19 at 08:57
  • @WilD_Ping time for me to point you to this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Dec 06 '19 at 08:59
  • Thank you for your time ! I really appreciate your dedication towards helping people in solving issues. I have submitted an issue https://github.com/intuit/karate/issues/987 – Avishek Behera Dec 06 '19 at 10:31
  • @WilD_Ping I'm sorry - that project is un-usable. please provide steps on how to run and replicate – Peter Thomas Dec 06 '19 at 13:28
  • 1
    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. – Avishek Behera Dec 11 '19 at 04:07