@@ -596,23 +596,29 @@ public function _before(TestInterface $test)
596596 */
597597 public function dragAndDrop ($ source , $ target , $ xOffset = null , $ yOffset = null )
598598 {
599- if ($ xOffset !== null || $ yOffset !== null ) {
600- $ snodes = $ this ->matchFirstOrFail ($ this ->baseElement , $ source );
601- $ tnodes = $ this ->matchFirstOrFail ($ this ->baseElement , $ target );
599+ if ($ xOffset === null && $ yOffset === null ) {
600+ parent ::dragAndDrop ($ source , $ target );
601+ } else {
602+ $ sNode = $ this ->matchFirstOrFail ($ this ->baseElement , $ source );
603+ $ tNode = $ this ->matchFirstOrFail ($ this ->baseElement , $ target );
602604
603- $ targetX = intval ( $ tnodes -> getLocation ()->getX () + $ xOffset );
604- $ targetY = intval ( $ tnodes -> getLocation ()->getY () + $ yOffset );
605+ $ sHeight = $ sNode -> getSize ()->getHeight ( );
606+ $ sWidth = $ sNode -> getSize ()->getWidth ( );
605607
606- $ travelX = intval ($ targetX - $ snodes ->getLocation ()->getX ());
607- $ travelY = intval ($ targetY - $ snodes ->getLocation ()->getY ());
608+ $ travelX = intval ($ tNode -> getLocation ()-> getX () - $ sNode ->getLocation ()->getX () + $ xOffset );
609+ $ travelY = intval ($ tNode -> getLocation ()-> getY () - $ sNode ->getLocation ()->getY () + $ yOffset );
608610
609611 $ action = new WebDriverActions ($ this ->webDriver );
610- $ action ->moveToElement ($ snodes )->perform ();
611- $ action ->clickAndHold ($ snodes )->perform ();
612- $ action ->moveByOffset ($ travelX , $ travelY )->perform ();
613- $ action ->release ()->perform ();
614- } else {
615- parent ::dragAndDrop ($ source , $ target );
612+ if ($ travelX >0 && $ travelY >0 && $ travelX < $ sWidth && $ travelY < $ sHeight ) {
613+ // Perform separate action steps when dragging and dropping inside the source element boundary
614+ $ action ->moveToElement ($ sNode )->perform ();
615+ $ action ->clickAndHold ($ sNode )->perform ();
616+ $ action ->moveByOffset ($ travelX , $ travelY )->perform ();
617+ $ action ->release ()->perform ();
618+ } else {
619+ // Call dragAndDropBy otherwise
620+ $ action ->dragAndDropBy ($ sNode , $ travelX , $ travelY )->perform ();
621+ }
616622 }
617623 }
618624
0 commit comments