Search code examples
behatmink

Using translations of Behat predefined steps (Phar install)


I've run some tests with the predefined step definitions of Mink Extension. They work as long as they're in english language.

Now I've tried the following scenario with german steps:

# language: de
Funktionalität: Demo

  @javascript
  Szenario: Test 1
    Angenommen I am on "/"
    Angenommen ich bin auf "/"
    ...

Behat now tells me that the german step definition is undefined, while the english version works.

According to the CLI help, behat --lang de -dl should display the translated definitions, but it only shows me the english ones ...

What am I doing wrong here?

Edit: Here's a script to rebuild the scenario. It follows the install steps from the docs (http://extensions.behat.org/mink/#through-phar) in a temporary directory and runs the test feature file.

#!/bin/bash

set -e

TEMPDIR=/tmp/behat-$$
mkdir $TEMPDIR
cd $TEMPDIR

curl http://behat.org/downloads/behat.phar >behat.phar
curl http://behat.org/downloads/mink.phar >mink.phar
curl http://behat.org/downloads/mink_extension.phar >mink_extension.phar

cat >behat.yml <<EOF
default:
  extensions:
    mink_extension.phar:
      mink_loader: 'mink.phar'
      base_url:    'http://behat.org'
      goutte:      ~
EOF

mkdir features
cat >features/test.feature <<EOF
# language: de
Funktionalität: Demo

  Szenario: Öffne Startseite DE + EN
    Angenommen I am on "/"
    Angenommen ich bin auf "/"
EOF

php behat.phar

Solution

  • Basically you didn't do anything wrong.

    Although the translation of Behat/Gherkin itself is included in the behat.phar file, the translations of the step definitions from MinkExtension are missing in the mink_extension.phar archive.

    This seems to be the case because the build script only includes the files in MinkExtension/src/ without MinkExtension/i18n/. You could open an issue for MinkExtension at to get this fixed.

    As a workaround I suggest to install Behat/Mink using composer instead of working with phar archives.

    Create the following composer.json file:

    {
        "require": {
            "behat/behat": "2.4.*@stable",
            "behat/mink": "1.4.*@stable",
            "behat/mink-extension": "*",
            "behat/mink-goutte-driver": "*",
            "behat/mink-selenium2-driver": "*"
        },
        "minimum-stability": "dev",
        "config": {
            "bin-dir": "bin/"
        }
    }
    

    and then install it with:

    curl http://getcomposer.org/installer | php
    php composer.phar install