Skip to content

Commit

Permalink
Add step definition for dragging one element onto another
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisolof committed Mar 6, 2024
1 parent 22d69d8 commit feba355
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Drupal/DrupalExtension/Context/MinkContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit feba355

Please sign in to comment.