Skip to content

Commit

Permalink
Merge pull request #255 from magento/MQE-1185
Browse files Browse the repository at this point in the history
MQE-1185: MFTF DragAndDrop Action Is Not Using X, Y Offsets Correctly
  • Loading branch information
jilu1 authored Nov 14, 2018
2 parents c53b77a + 8600e8b commit 7136da4
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,23 +596,29 @@ public function _before(TestInterface $test)
*/
public function dragAndDrop($source, $target, $xOffset = null, $yOffset = null)
{
if ($xOffset !== null || $yOffset !== null) {
$snodes = $this->matchFirstOrFail($this->baseElement, $source);
$tnodes = $this->matchFirstOrFail($this->baseElement, $target);
if ($xOffset === null && $yOffset === null) {
parent::dragAndDrop($source, $target);
} else {
$sNode = $this->matchFirstOrFail($this->baseElement, $source);
$tNode = $this->matchFirstOrFail($this->baseElement, $target);

$targetX = intval($tnodes->getLocation()->getX() + $xOffset);
$targetY = intval($tnodes->getLocation()->getY() + $yOffset);
$sHeight = $sNode->getSize()->getHeight();
$sWidth = $sNode->getSize()->getWidth();

$travelX = intval($targetX - $snodes->getLocation()->getX());
$travelY = intval($targetY - $snodes->getLocation()->getY());
$travelX = intval($tNode->getLocation()->getX() - $sNode->getLocation()->getX() + $xOffset);
$travelY = intval($tNode->getLocation()->getY() - $sNode->getLocation()->getY() + $yOffset);

$action = new WebDriverActions($this->webDriver);
$action->moveToElement($snodes)->perform();
$action->clickAndHold($snodes)->perform();
$action->moveByOffset($travelX, $travelY)->perform();
$action->release()->perform();
} else {
parent::dragAndDrop($source, $target);
if ($travelX >0 && $travelY >0 && $travelX < $sWidth && $travelY < $sHeight) {
// Perform separate action steps when dragging and dropping inside the source element boundary
$action->moveToElement($sNode)->perform();
$action->clickAndHold($sNode)->perform();
$action->moveByOffset($travelX, $travelY)->perform();
$action->release()->perform();
} else {
// Call dragAndDropBy otherwise
$action->dragAndDropBy($sNode, $travelX, $travelY)->perform();
}
}
}

Expand Down

0 comments on commit 7136da4

Please sign in to comment.