Cypress-cucumber-preprocessor: Support for French Definitions

Created on 28 Dec 2018  ·  12Comments  ·  Source: TheBrainFamily/cypress-cucumber-preprocessor

Hi,

My manager wants me to describe the tests in French. We have some tests in French that we've done with cucumber and selenium js

#language: fr

Fonctionnalité: Filtrer la liste de contenus par type de contenu

  Scénario: L'option du filtre Type de contenu est présent
    Etant donné qu'on est dans la liste de contenus
    Alors le filtre Type de contenu est visible
    Et les valeurs disponibles du filtres Type de contenu sont sélectionnable

It works fine in seleniumjs. This is a step_definition that we have

this.Given(/^le service de contenus est disponible$/, function () {
        return driver.get(shared.env.baseUrl);
    });

However, when I use this .feature file and create the definition steps, cypress does not recognize the tests. I get Error: Step implementation missing for: on est dans la liste de contenus

If I change the French keywords to English it works fine. Is there something I can do to have the step definitions in French?

Thanks

Most helpful comment

Sure.
I don't know an example of what, but here is a part of a feature, with the corresponding simplified selectors :

#language: fr
Fonctionnalité: Appel téléphonique

  Lorsqu'un client appel à l'agence, le téléphone ouvre automatiquement une page dans le navigateur avec le numéro de la
  personne qui appelle. Ce numéro doit ensuite servir à identifier si le client existe déjà et afficher le contact.

  Scénario: Client connu

    Lorsque je visite la page "/contacts?telephone=0123456789"
    Alors je dois lire "01 23 45 67 89" dans le "téléphone du contact"
    Et je dois lire "M. Doe John" dans le "nom complet du contact"
    Et je dois lire "[email protected]" dans l'"email du contact"

When(/^je visite la page "(.*)"$/, pageUrl => {
  cy.visit(pageUrl);
});

Then(/^je dois lire "(.*)" dans (?:le |la |l'|les )"(.*)"$/, (text, name) => {
  cy.get(getSelector(name)).should('contain', text)
});

All 12 comments

Can you try with French language but without any special characters?

If I try with this:

#language: fr

Fonctionnalite: Filtrer la liste de contenus par type de contenu

  Scenario: L'option du filtre Type de contenu est présent
    Etant donne qu'on est dans la liste de contenus
    Alors le filtre Type de contenu est visible
    Et les valeurs disponibles du filtres Type de contenu sont sélectionnable

Then I get this error:

Uncaught CompositeParserException: Parser errors:
(3:1): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Fonctionnalite: Filtrer la liste de contenus par type de contenu'
(5:3): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Scenario: L'option du filtre Type de contenu est présent'
(6:5): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Etant donne qu'on est dans la liste de contenus'
(7:5): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Alors le filtre Type de contenu est visible'
(8:5): expected: #TagLine, #FeatureLine, #Comment, #Empty, got 'Et les valeurs disponibles du filtres Type de contenu sont sélectionnable'
(133:0): unexpected end of file, expected: #TagLine, #FeatureLine, #Comment, #Empty

This error originated from your test code, not from Cypress.

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

Check your console for the stack trace or click this message to see where it originated from.

And this is what I have in the console:

at Function.Errors.CompositeParserException.create (http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:12464:13)
    at Parser.parse (http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:15976:45)
    at Object.1./Users/heliosalves/Development/Projects/QMI/pfu-content-ui/test/cypress/e2e/homepage/pfu-1951-filtre-type-contenu/pfu-1951-filtre-type-contenu.js (http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:144:35)
    at o (http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:1:265)
    at r (http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:1:431)
    at http://localhost:3000/__cypress/tests?p=cypress/e2e/homepage/pfu-1951-filtre-type-contenu.feature-578:1:460
logError @ cypress_runner.js:161351

Hi @lgandecki,

First of all, I want to wish you a happy New Year :)

I'd like to know if there's anything here that we'd need to do? Would we need to translate the keywords in French? If so, I could help with that.

Thank you

Hello

Thanks, you too.

I won't be able to look at this till the next week.
Maybe @sawasawasawa or @lucetius will be able to help you, or at least diagnoze the problem.

What would help to start with would be a simple reproduction (yes, it's easy for us to make it, but if you can just push something that you have it will save us some time)

@alveshelio
My suggestion is creating a step_definition file for each step you are making in your feature file, so for the one you have the issue with I'd do something like:

given(/^on est dans la liste de contenus$/, () => {
  console.log("test");
});

(let's call it on_est_dans_la_liste_de_contenus.js and place it in your step_definitions directory)

After I did it, I stopped getting the error you are getting and started seeing error about le filtre Type de contenu est visible step missing (hence we need to have a separate step definition for each of our steps).

That's not a viable solution, we need to simply use this language without cutting our files like this... :disappointed:

I guess I missed what the problem is, @yeppao could you please create a reproduction and push it to github?

Actually, our tests are in French too, and everything is working like a charm.
Do you want me to test some syntax from yours on my codebase?

@mathieutu can you share an example ?

Sure.
I don't know an example of what, but here is a part of a feature, with the corresponding simplified selectors :

#language: fr
Fonctionnalité: Appel téléphonique

  Lorsqu'un client appel à l'agence, le téléphone ouvre automatiquement une page dans le navigateur avec le numéro de la
  personne qui appelle. Ce numéro doit ensuite servir à identifier si le client existe déjà et afficher le contact.

  Scénario: Client connu

    Lorsque je visite la page "/contacts?telephone=0123456789"
    Alors je dois lire "01 23 45 67 89" dans le "téléphone du contact"
    Et je dois lire "M. Doe John" dans le "nom complet du contact"
    Et je dois lire "[email protected]" dans l'"email du contact"

When(/^je visite la page "(.*)"$/, pageUrl => {
  cy.visit(pageUrl);
});

Then(/^je dois lire "(.*)" dans (?:le |la |l'|les )"(.*)"$/, (text, name) => {
  cy.get(getSelector(name)).should('contain', text)
});

Great, thanks a lot Mathieu, I'm gonna use this in our vue/cypress/cucumber stack at work.

I'm wondering, do you use other testing tool beside these E2E tests ? like unit tests (Jest, Ava, ...), component catalogue (StoryBook for example) or someting else ?

the #language: in a feature file will break the test when in a cypress/webpack project. Have no clue on how to fix it a.t.m. hoped to find a config file to set the language.

Was this page helpful?
0 / 5 - 0 ratings