6

I'm setting up a test environment with Cucumber, Sikuli and Eclipse in my company. I've managed to get everything working just fine, but now I need to make the .feature files work in portuguese.

As far as I know, all I had to do was put the comment #language: pt at the beginning of the .feature file, but it's not working.

I also ran the commands cucumber --i18n help and cucumber --i18n pt to check if the language is really there, and it is.

Is there another configuration I'm not aware of?

I'm using these jars:

  • cucumber-core-3.0.2.jar
  • cucumber-java-3.0.2.jar
  • cucumber-junit-3.0.2.jar
  • cucumber-jvm-deps-1.0.6.jar
  • gherkin-5.1.0.jar
  • junit-4.12.jar
  • mockito-all-1.10.19.jar
  • I added some code snippets to my answer. Maybe you could start based on them. – SubOptimal Aug 21 '18 at 13:28
  • Are you on Windows? Check that the feature file is not saved by your editor as UTF-8 with the BOM characters (EF BB BF) at the beginning (best is to use a hex viewer or similar). – SubOptimal Aug 22 '18 at 13:53

3 Answers3

5

You can control the language of the Gherkin keyword by adding # language: xx as first line.

For Portuguese it would be

# language: pt
Funcionalidade: um exemplo

A list of all supported spoken languages can be found at https://docs.cucumber.io/gherkin/reference/#spoken-languages. The localized keywords you might lookup for example in gherkin-languages.json

A simple Maven project.

structure

pom.xml
src/test/java/features/example.feature
src/test/java/runner/TestRunner.java

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.suboptimal</groupId>
    <artifactId>cuke-test-13.so</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.cucumber>3.0.2</version.cucumber>
    </properties>
    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${version.cucumber}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

src/test/java/features/example.feature

# language: pt
Funcionalidade: um exemplo

  Cenario: foo
  Dado something given

src/test/java/runner/TestRunner.java

package runner;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features/example.feature"
        )
public class TestRunner {
}

running the test with mvn compile test will produce the following error.

Undefined scenarios:
src/test/java/features/example.feature:4 # foo

1 Scenarios (1 undefined)
1 Steps (1 undefined)
0m0.036s


You can implement missing steps with the snippets below:

@Dado("something given")
public void something_given() {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

edit When the feature file is saved on Windows with Notepad as UTF-8 the BOM characters (EF BB BD) are inserted at the beginning.

$ hexdump -C example.feature
00000000 ef bb bf 23 20 6c 61 6e 67 75 61 67 65 3a 20 70 |...# >language: p|

If running mvn test the execution fails with exception.

cucumber.runtime.CucumberException: gherkin.ParserException$CompositeParserException: Parser errors:
(1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got '# language: pt'
(2:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Funcionalidade: um exemplo'
(4:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Cenario: foo'
(5:3): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'Dado something given'
SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • So essentially, he just missed out the space? – KyleFairns Aug 21 '18 at 12:22
  • @KyleFairns I missed this part in the question. But the blank is not important. I will add an example. – SubOptimal Aug 21 '18 at 12:38
  • I'm not using maven, but I did create another one with maven following those instructions, adapting what needed to be adapted, but the result was the same. When I use `Funcionalidade: abrindo a lista de pedidos` it still throws this error `Missing 'Feature' at: 'Funcionalidade'` – Bruno Pinheiro Aug 21 '18 at 17:36
  • @BrunoPinheiro I added the full `pom.xml`. Which Maven/Java version are you using? What is your locale (`java -XshowSettings:properties 2>&1 | egrep "user.(language|country)"`)? – SubOptimal Aug 22 '18 at 05:31
  • Now I'm using Java 1.8.0.171, Maven Compiler 3.3, Cucumber, 1.2.5, Gherkin 2.12.2, but I also tried with the newest versions available on maven repository, country is BR and language is pt. – Bruno Pinheiro Aug 22 '18 at 13:14
  • @BrunoPinheiro The above is a complete Maven project (consisting of the three files). Have you tried it? Even I amend it to use the old Cucumber version `info.cukes:cucumber-java:jar:1.2.5` it works. Could you please post a [MCVE](https://stackoverflow.com/help/mcve) so someone would be able to reproduce your issue. The locale has no impact. It works with `pt_BR` the same as with `en_US`. – SubOptimal Aug 22 '18 at 13:39
1

First of all, thanks to everyone who helped me.

After quite some time I finally found out the problem.

Sébastien Le Callonnec's answer on this thread made it clear to me. The problem was with the Natural plugin.

Everything was working correctly from the start but it turns out that Natural only supports english. Thats why it was throwing errors but the test was executing. After uninstalling the plugin the errors disappeared.

0

I opened the .feature file with a different hex viewer, this seems more correct: enter image description here

The weird part is, I tried to execute the code despite the errors and it worked. I really don't know why. I only changed the keywords to portuguese for testing purposes. The code is showing the errors but executed all the steps as if everything was alright.

enter image description here

The only thing eclipse says about the error is missing 'Feature:' at 'Funcionalidade:'

  • Your hexdump seems to be shifted or something like that. As the bytes in the image represent ` am in the main menu\n Quando i click the orders button\n Então the orders list should be opened`. Does Eclipse tell a bit about the type of the error? – SubOptimal Aug 23 '18 at 05:51
  • The new hexdump looks better. Maybe it's a problem of the Cucumber plugin for Eclipse with localized key words. – SubOptimal Aug 23 '18 at 13:20