[Support - with Solution] Best place to set BEHAT_PARAMS
subhojit777 opened this issue · comments
Inside before_script
:
before_script:
- drupal-ti before_script
- drupal-ti --include drupal_ti/before/before_script.sh
- drupal-ti --include drupal_ti/before/runners/behat/before_script.sh
And I have a file like this drupal_ti/before/runners/behat/before_script.sh
:
#!/bin/bash
# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/runners/behat/before_script.sh"
set -e $DRUPAL_TI_DEBUG
export BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"DRUPAL_TI_WEBSERVER_URL:DRUPAL_TI_WEBSERVER_PORT/"},"Drupal\\DrupalExtension":{"drush":{"root":"DRUPAL_TI_DRUPAL_DIR"},"drupal":{"drupal_root":"DRUPAL_TI_DRUPAL_DIR"}}}}'
BEHAT_PARAMS=`echo $BEHAT_PARAMS | sed -e "s#DRUPAL_TI_WEBSERVER_URL#$DRUPAL_TI_WEBSERVER_URL#" -e "s#DRUPAL_TI_WEBSERVER_PORT#$DRUPAL_TI_WEBSERVER_PORT#" -e "s#DRUPAL_TI_DRUPAL_DIR#$DRUPAL_TI_DRUPAL_DIR#" -e "s#DRUPAL_TI_DRUPAL_DIR#$DRUPAL_TI_DRUPAL_DIR#"`
export BEHAT_PARAMS
echo $BEHAT_PARAMS
But it seems the BEHAT_PARAMS
is not considered when the tests are run. And it fails with error:
[InvalidArgumentException]
Driver "drupal" is not registered.
Any idea why this is happening?
As a workaround I am setting BEHAT_PARAMS
under before_script
like this:
# Setting Behat environment
- DRUPAL_DIR="$TRAVIS_BUILD_DIR/../$DRUPAL_TI_ENVIRONMENT/drupal"
- BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"DRUPAL_TI_WEBSERVER_URL:DRUPAL_TI_WEBSERVER_PORT/"},"Drupal\\DrupalExtension":{"drush":{"root":"DRUPAL_DIR"},"drupal":{"drupal_root":"DRUPAL_DIR"}}}}'
- BEHAT_PARAMS=`echo $BEHAT_PARAMS | sed -e s#DRUPAL_TI_WEBSERVER_URL#$DRUPAL_TI_WEBSERVER_URL# -e s#DRUPAL_TI_WEBSERVER_PORT#$DRUPAL_TI_WEBSERVER_PORT# -e s#DRUPAL_DIR#$DRUPAL_DIR# -e s#DRUPAL_DIR#$DRUPAL_DIR#`
- export BEHAT_PARAMS
There is several things mixed here:
a) The easiest solution likely is just to source your script with parameters:
- . behat-params.sh
or
- source ./behat-params.sh
That will ensure that environment variables are exported correctly.
b) You can set all those behat parameters already in a custom behat.yml.dist file including placeholders for all environment variables, see the test behat test in the drupal-7 / drupal-8 test directories:
c) When you want to use the before or after functionality you can run in the same environment as the runner you want to extend, there is no need to --include that:
- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
You need to uncomment that in your .travis.yml, then it will automatically find e.g. drupal_ti/before/runners/behat/script.sh and you can set environment variables there.
Hope that helps! :)
Thanks! I missed the behat.yml.dist
in the README. That really helped and it is working.
BTW I have another confusion regarding the "before" script. You have asked to uncomment this:
- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
But it seems like it is not considering the scripts. Where do I have to put this drupal_ti
directory. Currently it is placed just under my module's directory like this:
mymodule
- tests/
- drupal_ti/
- mymodule.info
- mymodule.module
I have also tried placing drupal_ti
under tests
directory, and changed DRUPAL_TI_SCRIPT_DIR_BEFORE
this to:
- DRUPAL_TI_SCRIPT_DIR_BEFORE="./tests/drupal_ti/before"
But it is still not working. Only option to make it work is "including" it under before_script
. Am I doing something wrong?
Inside before_script.sh
:
#!/bin/bash
# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"
set -e $DRUPAL_TI_DEBUG
# Install list.js library.
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_LIBRARIES_DIR"
wget "https://github.com/javve/list.js/archive/v$DRUPAL_TI_LISTJS_VERSION.tar.gz"
tar -xzf "v$DRUPAL_TI_LISTJS_VERSION.tar.gz"
mv "list.js-$DRUPAL_TI_LISTJS_VERSION" "listjs"
# Enable required modules.
drush en -y "features"
drush en -y "views"
drush en -y "views_ui"
Thanks for the awesome project.
I'm struggling with the same issue as @subhojit777. I cannot make the autodiscovery work when using DRUPAL_TI_SCRIPT_DIR_BEFORE.
I defined - DRUPAL_TI_SCRIPT_DIR_BEFORE="./tests/drupal_ti/before"
and have the script placed in tests/drupal_ti/before/runners/behat/before_script.sh
. But it's not taken into account.
Do you have any suggestions?
@szeidler I did like this https://github.com/subhojit777/listjs/blob/7.x-1.x/tests/behat.yml#L39 and asked Travis to run the specific profile like this https://github.com/subhojit777/listjs/blob/7.x-1.x/.travis.yml#L51