From feba355859fdce5fb781a854a8c03a93560331c9 Mon Sep 17 00:00:00 2001 From: "Christopher O. Caldwell" Date: Wed, 6 Mar 2024 16:33:53 -0700 Subject: [PATCH] Add step definition for dragging one element onto another gh-662 --- .../DrupalExtension/Context/MinkContext.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 */