diff --git a/src/Drupal/DrupalExtension/Context/MinkContext.php b/src/Drupal/DrupalExtension/Context/MinkContext.php index 52e255e7..5195e223 100644 --- a/src/Drupal/DrupalExtension/Context/MinkContext.php +++ b/src/Drupal/DrupalExtension/Context/MinkContext.php @@ -3,6 +3,7 @@ namespace Drupal\DrupalExtension\Context; use Behat\Behat\Context\TranslatableContext; +use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Exception\UnsupportedDriverActionException; use Behat\MinkExtension\Context\MinkContext as MinkExtension; use Drupal\DrupalExtension\TagTrait; @@ -251,6 +252,31 @@ public function pressKey($char, $field) $driver->keyUp($element->getXpath(), $char); } + /** + * Drag and drop one element onto another. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * + * @Given I drag element :dragged onto element :target + */ + public function dragElementOntoAnother($dragged, $target) + { + $session = $this->getSession(); + $driver = $session->getDriver(); + + $draggedElement = $session->getPage()->find('css', $dragged); + if (empty($draggedElement)) { + throw new ElementNotFoundException($driver, 'dragged element', 'css selector', $dragged); + } + + $targetElement = $session->getPage()->find('css', $target); + if (empty($targetElement)) { + throw new ElementNotFoundException($driver, 'target element', 'css selector', $target); + } + + $draggedElement->dragTo($targetElement); + } + /** * @Then I should see the link :link */