Skip to content

Commit d7b3ce6

Browse files
authored
MQE-766: Drag & Drop support to allow resizing of elements
- added override for dragAndDrop, and x/y offset options.
1 parent 02661c3 commit d7b3ce6

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

dev/tests/verification/Resources/BasicFunctionalTest.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class BasicFunctionalTestCest
9494
$I->dontSeeOptionIsSelected(".functionalTestSelector", "someInput");
9595
$I->doubleClick(".functionalTestSelector");
9696
$I->dragAndDrop(".functionalTestSelector", ".functionalTestSelector2");
97+
$I->dragAndDrop(".functionalTestSelector", ".functionalTestSelector2", 100, 900);
9798
$executeJSKey1 = $I->executeJS("someJSFunction");
9899
$I->fillField(".functionalTestSelector", "someInput");
99100
$I->fillField(".functionalTestSelector", "0");

dev/tests/verification/TestModule/Test/BasicFunctionalTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
<dontSeeOptionIsSelected selector=".functionalTestSelector" userInput="someInput" stepKey="dontSeeOptionIsSelectedKey1" />
5757
<doubleClick selector=".functionalTestSelector" stepKey="doubleClickKey1"/>
5858
<dragAndDrop selector1=".functionalTestSelector" selector2=".functionalTestSelector2" stepKey="dragAndDropKey1" />
59+
<dragAndDrop selector1=".functionalTestSelector" selector2=".functionalTestSelector2" stepKey="dragAndDropKey2" x="100" y="900"/>
5960
<executeJS function="someJSFunction" stepKey="executeJSKey1"/>
6061
<fillField selector=".functionalTestSelector" userInput="someInput" stepKey="fillFieldKey1" />
6162
<fillField selector=".functionalTestSelector" userInput="0" stepKey="fillFieldKey2" />

src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Facebook\WebDriver\WebDriverSelect;
1414
use Facebook\WebDriver\WebDriverBy;
1515
use Facebook\WebDriver\Exception\NoSuchElementException;
16+
use Facebook\WebDriver\Interactions\WebDriverActions;
1617
use Codeception\Exception\ElementNotFound;
1718
use Codeception\Exception\ModuleConfigException;
1819
use Codeception\Exception\ModuleException;
@@ -526,6 +527,36 @@ public function _before(TestInterface $test)
526527
parent::_before($test);
527528
}
528529

530+
/**
531+
* Override for codeception's default dragAndDrop to include offset options.
532+
* @param string $source
533+
* @param string $target
534+
* @param int $xOffset
535+
* @param int $yOffset
536+
* @return void
537+
*/
538+
public function dragAndDrop($source, $target, $xOffset = null, $yOffset = null)
539+
{
540+
if ($xOffset !== null || $yOffset !== null) {
541+
$snodes = $this->matchFirstOrFail($this->baseElement, $source);
542+
$tnodes = $this->matchFirstOrFail($this->baseElement, $target);
543+
544+
$targetX = intval($tnodes->getLocation()->getX() + $xOffset);
545+
$targetY = intval($tnodes->getLocation()->getY() + $yOffset);
546+
547+
$travelX = intval($targetX - $snodes->getLocation()->getX());
548+
$travelY = intval($targetY - $snodes->getLocation()->getY());
549+
550+
$action = new WebDriverActions($this->webDriver);
551+
$action->moveToElement($snodes)->perform();
552+
$action->clickAndHold($snodes)->perform();
553+
$action->moveByOffset($travelX, $travelY)->perform();
554+
$action->release()->perform();
555+
} else {
556+
parent::dragAndDrop($source, $target);
557+
}
558+
}
559+
529560
/**
530561
* Override for _failed method in Codeception method. Adds png and html attachments to allure report
531562
* following parent execution of test failure processing.

src/Magento/FunctionalTestingFramework/Test/etc/actionTypeTags.xsd

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,22 @@
269269
<xs:documentation>
270270
End point selector for drag-and-drop.
271271
</xs:documentation>
272-
</xs:annotation></xs:attribute>
272+
</xs:annotation>
273+
</xs:attribute>
274+
<xs:attribute type="xs:string" name="x">
275+
<xs:annotation>
276+
<xs:documentation>
277+
X offset for drag-and-drop destination.
278+
</xs:documentation>
279+
</xs:annotation>
280+
</xs:attribute>
281+
<xs:attribute type="xs:string" name="y">
282+
<xs:annotation>
283+
<xs:documentation>
284+
Y offset for drag-and-drop destination.
285+
</xs:documentation>
286+
</xs:annotation>
287+
</xs:attribute>
273288
<xs:attributeGroup ref="commonActionAttributes"/>
274289
</xs:extension>
275290
</xs:simpleContent>

src/Magento/FunctionalTestingFramework/Util/TestGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ public function generateStepsPhp($actionObjects, $hookObject = false, $actor = "
980980
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector, $parameterArray, $button);
981981
break;
982982
case "dragAndDrop":
983-
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector1, $selector2);
983+
$testSteps .= $this->wrapFunctionCall($actor, $actionObject, $selector1, $selector2, $x, $y);
984984
break;
985985
case "selectMultipleOptions":
986986
$testSteps .= $this->wrapFunctionCall(

0 commit comments

Comments
 (0)