When we define our tests in Gherkin language, the idea is that the tests are written in a language that our users and business experts (product team) have mastered.

Gherkin allows us translations in 70 languages.

When we write code, the most common is that everything (functions, variables, unit tests and others) is written in English, but if our users and business experts do not handle English on a day-to-day basis, it’s worth writing our Gherkin tests in Spanish or in the language that users speak.

In a previous post we describe an example of how we go from Gherkin tests to code, and now, we are going to translate those tests to Spanish.

Writing our test cases

Remember that it all starts with our examples of our system’s behavior. When we have our examples (defined in the requirements workshop and we build our example mapping), we design our test scenario as well. Each scenario has steps expressed in Gherkin language: Given, When, Then, And, and But.

Gherkin is a non-technical language which can be read by anyone (as a natural language) and allows us to express behaviors.

The most important steps are:

  • Given: these are the preconditions for a scenario and preparation of the environment to execute our test.
  • When: the action to be performed by the user (the action under test).
  • Then: the expected result. What is the response we expect from the system?

Our example with sample data in Gherkin language is:

When we translate it into Spanish, we get:

We can notice that the reserved words change:

Given → Dado

When → Cuando

Then → Entonces

Then we write the test in a more generic way, separating the data and converting it into variables that will allow us to run the same test with different data sets:

 

From Gherkin to source code (scenarios, steps, step definitions)

We start from our tests written in Gherkin. Then, we can convert them into executable specifications (source code). In this way we can automate our acceptance criteria.

To achieve these executable specifications, we use:

  • Feature file
  • Page Object Model
  • Step definitions

What do we do to change our tests to Spanish?

The first thing to consider is that our Page Object Model doesn’t change; it contains all our javascript code to obtain all our interactive elements, and we write the functions corresponding to that page. Everything can be written in English.

 

What we are going to change are our Feature Files and Step Definitions.

This one was my original feature file:

 

When we translate it into Spanish, we get:

 

We can notice that the reserved words change:

Feature → Característica

Scenario Outline → Esquema del escenario

Given → Dado

When → Cuando

Then → Entonces

Examples → Ejemplos

 

We also add the language at the beginning of our feature file

 

The step definitions also change to Spanish, but only the name of the step. We continue using Given, When and Then.

 

And, easily, we managed to implement our tests written with Gherkin and Cucumber in Spanish.

Here you will find the source code in English, pull it and run the tests.

Here you will find the source code in Spanish, pull it and run the tests.