From 7c7c9a5f5fa1e22a061f2d9c7ed1d3f855af0067 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 5 Feb 2019 15:46:08 +0100 Subject: [PATCH 1/3] Throw a helpful exception if the AJAX timeout is missing due to a common mistake in the configuration. --- src/Drupal/DrupalExtension/Context/MinkContext.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Drupal/DrupalExtension/Context/MinkContext.php b/src/Drupal/DrupalExtension/Context/MinkContext.php index b7bf9e1c..188220c7 100644 --- a/src/Drupal/DrupalExtension/Context/MinkContext.php +++ b/src/Drupal/DrupalExtension/Context/MinkContext.php @@ -152,7 +152,11 @@ function isAjaxing(instance) { ); }()); JS; - $result = $this->getSession()->wait(1000 * $this->getMinkParameter('ajax_timeout'), $condition); + $ajax_timeout = $this->getMinkParameter('ajax_timeout'); + if ($ajax_timeout === null) { + throw new \Exception('No AJAX timeout has been defined. Please verify that "Drupal\MinkExtension" is configured in behat.yml (and not "Behat\MinkExtension").'); + } + $result = $this->getSession()->wait(1000 * $ajax_timeout, $condition); if (!$result) { if ($event) { /** @var \Behat\Behat\Hook\Scope\BeforeStepScope $event */ From 4dcf5037efdf3dcc3587e1583bcd58bba0373fe2 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 6 Feb 2019 09:28:40 +0100 Subject: [PATCH 2/3] Suggest to use our overridden MinkContext throughout our documentation. --- CHANGELOG.md | 3 +++ README.md | 2 +- behat.yml.dist | 8 ++++---- doc/environment.rst | 8 ++++---- features/subcontexts/find.feature | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e433668..ddfc79c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + * [#528](https://github.com/jhedstrom/drupalextension/pull/528) Show a more helpful failure when running `@javascript` + scenarios with incorrect configuration. ## [4.0.0 beta2] 2018-12-19 ### Added * [#514](https://github.com/jhedstrom/drupalextension/pull/514) Add a note about the need to remove the entries in behat.yml to use BEHAT_PARAMS. diff --git a/README.md b/README.md index 6e9c1934..e2084564 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ the [Full documentation](https://behat-drupal-extension.readthedocs.org) contexts: - Drupal\DrupalExtension\Context\DrupalContext extensions: - Behat\MinkExtension: + Drupal\MinkExtension: goutte: ~ base_url: http://example.org/ # Replace with your site's URL Drupal\DrupalExtension: diff --git a/behat.yml.dist b/behat.yml.dist index 000eaeb6..de166ba5 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -44,7 +44,7 @@ drupal6: filters: tags: "@d6" extensions: - Behat\MinkExtension: + Drupal\MinkExtension: base_url: http://127.0.0.1:8888 Drupal\DrupalExtension: api_driver: "drupal" @@ -67,7 +67,7 @@ drupal7: filters: tags: "@d7" extensions: - Behat\MinkExtension: + Drupal\MinkExtension: base_url: http://127.0.0.1:8888 Drupal\DrupalExtension: api_driver: "drupal" @@ -92,7 +92,7 @@ drush: filters: tags: "@drushTest" extensions: - Behat\MinkExtension: + Drupal\MinkExtension: base_url: http://127.0.0.1:8888 Drupal\DrupalExtension: api_driver: "drush" @@ -119,7 +119,7 @@ drupal8: filters: tags: "@d8&&~@d8wip" extensions: - Behat\MinkExtension: + Drupal\MinkExtension: base_url: http://127.0.0.1:8888 Drupal\DrupalExtension: api_driver: "drupal" diff --git a/doc/environment.rst b/doc/environment.rst index 0912cfa3..86ce948d 100644 --- a/doc/environment.rst +++ b/doc/environment.rst @@ -19,7 +19,7 @@ Example JSON object: { "extensions": { - "Behat\\MinkExtension": { + "Drupal\\MinkExtension": { "base_url": "http://myproject.localhost" }, "Drupal\\DrupalExtension": { @@ -36,7 +36,7 @@ object into a single line and surround with single quotes: .. code-block:: bash - $ export BEHAT_PARAMS='{"extensions":{"Behat\\MinkExtension":{"base_url":"http://myproject.localhost"},"Drupal\\DrupalExtension":{"drupal":{"drupal_root":"/var/www/myproject"}}}}' + $ export BEHAT_PARAMS='{"extensions":{"Drupal\\MinkExtension":{"base_url":"http://myproject.localhost"},"Drupal\\DrupalExtension":{"drupal":{"drupal_root":"/var/www/myproject"}}}}' You must also remove (or comment out) the entries that you use in behat.yml for the values in BEHAT_PARAMS to take affect. @@ -52,7 +52,7 @@ You must also remove (or comment out) the entries that you use in behat.yml for - Drupal\DrupalExtension\Context\MessageContext - Drupal\DrupalExtension\Context\DrushContext extensions: - Behat\MinkExtension: + Drupal\MinkExtension: goutte: ~ selenium2: ~ # Must comment out for BEHAT_PARAMS to be effective. @@ -70,7 +70,7 @@ You must also remove (or comment out) the entries that you use in behat.yml for # bin/behat --profile=local local: extensions: - Behat\MinkExtension: + Drupal\MinkExtension: base_url: 'localhost' Drupal\DrupalExtension: drush: diff --git a/features/subcontexts/find.feature b/features/subcontexts/find.feature index 034ae522..3e71042b 100644 --- a/features/subcontexts/find.feature +++ b/features/subcontexts/find.feature @@ -43,7 +43,7 @@ Feature: Ability to find Drupal sub-contexts default: contexts: [Drupal\DrupalExtension\Context\DrupalContext] extensions: - Behat\MinkExtension: + Drupal\MinkExtension: goutte: ~ selenium2: ~ base_url: http://drupal.org From 0f6ed6ae6b905760ec36dfb66a81fb2a3cbae6fb Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 6 Feb 2019 09:29:57 +0100 Subject: [PATCH 3/3] Only throw the helpful exception in the case the unhelpful one was already being thrown. --- src/Drupal/DrupalExtension/Context/MinkContext.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Drupal/DrupalExtension/Context/MinkContext.php b/src/Drupal/DrupalExtension/Context/MinkContext.php index 188220c7..dc7200de 100644 --- a/src/Drupal/DrupalExtension/Context/MinkContext.php +++ b/src/Drupal/DrupalExtension/Context/MinkContext.php @@ -153,11 +153,11 @@ function isAjaxing(instance) { }()); JS; $ajax_timeout = $this->getMinkParameter('ajax_timeout'); - if ($ajax_timeout === null) { - throw new \Exception('No AJAX timeout has been defined. Please verify that "Drupal\MinkExtension" is configured in behat.yml (and not "Behat\MinkExtension").'); - } $result = $this->getSession()->wait(1000 * $ajax_timeout, $condition); if (!$result) { + if ($ajax_timeout === null) { + throw new \Exception('No AJAX timeout has been defined. Please verify that "Drupal\MinkExtension" is configured in behat.yml (and not "Behat\MinkExtension").'); + } if ($event) { /** @var \Behat\Behat\Hook\Scope\BeforeStepScope $event */ $event_data = ' ' . json_encode([