Can we pass non English strings as parameters using Cucumber with Java language?

321 Views Asked by At

I have trying to pass non English strings as parameters using Cucumber for automation Testing. The language used is Java. But when these strings are passed from feature files to steps definitions, French characters such as 'é' are printed as '?'. Is there a way by which I can pass Non-English characters as parameters?

I am trying to pass the string 'Décoration murale'. But when this is printed in Step Definitions, 'é' is printed as '?' Please see the screenshot attached.

@tag
Feature: String Verifcations

    @PassNonEnglishCharacters
  Scenario Outline: Verify non English parameters
    Given I have my driver ready
    Then I print collection "<collection>" name on console

    Examples: 
      | collection          |
      | Décoration murale   |

@Then("^I print collection \"([^\"]*)\" name on console$")
    public void i_print_collection_name_on_console(String collection) throws Throwable {
        
        System.out.println("Collection:" +collection);
    }

Outcome on Console:

**Collection:D?coration murale**

Screenshot

2

There are 2 best solutions below

0
MrUwugu On

To my knowledge, Cucumber and Java are using Unicode, which should support the French character you've mentioned. Perhaps there is an issue in the code which this step definition is calling, or with the environment where you are printing out this result? Perhaps a char is being used somewhere instead?

0
M.P. Korstanje On

This depends on the encoding of your file. This should be UTF-8, but if you are using something like Notepad you may end up with a different encoding such as ISO-8859-1.

You can tell Cucumber that your file is not UTF-8 encoded by using the # encoding: comment.

# language: fr
# encoding: ISO-8859-1
Fonctionnalité: Concombres dans ISO-8859-1

  Scénario: dans la ventre
    Étant donné j'ai 5 concombres