Skip to content

Instantly share code, notes, and snippets.

@satujamsaja
Last active November 4, 2022 10:05
Show Gist options
  • Select an option

  • Save satujamsaja/8429390335af42019ea653e4efebd76e to your computer and use it in GitHub Desktop.

Select an option

Save satujamsaja/8429390335af42019ea653e4efebd76e to your computer and use it in GitHub Desktop.
Setting up Behat for local testing with Acquia DevDekstop Windows
1. Install Acquia DevDesktop
2. Install, setup and configure new Drupal 8 Site
3. Make sure composer from Acquia DevDesktop working and make use of PHP 5.6
- Modify C:\Program Files (x86)\DevDesktop\tools\composer.bat
- Make modification to @SET PATH=C:\Program Files (x86)\DevDesktop\php5_6;%PATH% php.exe "C:\Program Files (x86)\DevDesktop\tools\composer.phar" %*
- Add C:\Program Files (x86)\DevDesktop\tools to windows Path environtment variable so composer can be executed on command prompt
4. Modify "settings.php" to load database config directly, not from included settings
- Find Acquia DevDesktop settings file on C:\Users\user.name\.acquia\DevDesktop\DrupalSettings
- Find and comment out below line for .inc include. Example below:
// <DDSETTINGS>
// Please don't edit anything between <DDSETTINGS> tags.
// This section is autogenerated by Acquia Dev Desktop.
//if (isset($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR']) && file_exists($_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_d8_dd.inc')) {
// require $_SERVER['DEVDESKTOP_DRUPAL_SETTINGS_DIR'] . '/loc_d8_dd.inc';
//}
- Copy and paste content from .inc file inside <?php ?> file to settings.php
5. On your Drupal installation folder create "tests" folder
6. Create composer.json with following lines inside "tests" folder
{
"require": {
"drupal/drupal-extension": "~3.0",
"guzzlehttp/guzzle" : "^6.0@dev"
},
"config": {
"bin-dir": "bin/"
}
}
7. Run "composer install"
8. After installation finished. Create "behat.yml" inside "tests" file with following lines, and change "base_url" to your drupal site url, and add Drupal API Driver and your drupal install directory
default:
suites:
default:
contexts:
- FeatureContext
- Drupal\DrupalExtension\Context\DrupalContext
- Drupal\DrupalExtension\Context\MinkContext
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\DrupalExtension\Context\DrushContext
extensions:
Behat\MinkExtension:
goutte: ~
selenium2: ~
base_url: http://d8.dd:8083
Drupal\DrupalExtension:
blackbox: ~
api_driver: 'drupal'
drupal:
drupal_root: 'D:\Sites\devdesktop\d8'
9. From the "tests" folder run "bin\behat --init", it will create "features" directory and "features\bootstrap\FeatureContext.php"
10. Run "bin\behat -dl" to make sure all working, and you'll get list of available context we can use, you will get something like
default | Given :arg1 content with paragraph:
default | Given I am an anonymous user
default | Given I am not logged in
11. Create your behat test file *.feature file and put it into "features" directory
12. Run "bin\behat" to run the tests
Readings:
- https://behat-drupal-extension.readthedocs.io/en/3.1/index.html
- http://behat.org/en/latest/quick_start.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment