cancel
Showing results for 
Search instead for 
Did you mean: 

[TechCorner Challenge #2] Dragging One Element to Another

SOLVED
Highlighted
Community Manager

[TechCorner Challenge #2] Dragging One Element to Another

Hi Community! Here's one more interesting challenge for you to complete!

 

Drag and drop is quite a simple task that is performed in TestComplete by using the Drag action. However, it might be that the destination changes its position on the screen, so you need to recalculate the destination coordinates every time.

 

Task: Create a function that takes two objects as parameters and drags the first object to the center of the second one.

Difficulty:Star_Gold.pngStar_Gold.pngStar_gray.pngStar_gray.png

 

Have fun!🙂

 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Dragging One Element to Another

Task: Create a function that takes two objects as parameters and drags the first object to the center of the second one.

 

This is a solution created for [TechCorner Challenge #2]

 

In Javascript:

 

 

function dragCalculatedDistance(startObject, destinationObject) {
    var startPoint, targetPoint, dragX, dragY;
    // Drag from the center of object A to the center of object B

    startPoint = startObject.WindowToScreen(startObject.Width/2, startObject.Height/2);
    targetPoint = destinationObject.WindowToScreen(destinationObject.Width/2, destinationObject.Height/2);

    dragX = targetPoint.X - startPoint.X;
    dragY = targetPoint.Y - startPoint.Y;

    startObject.Drag(-1, -1, dragX, dragY); 
}

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Tags (1)
2 REPLIES 2
Highlighted
Community Hero

Dragging One Element to Another

Task: Create a function that takes two objects as parameters and drags the first object to the center of the second one.

 

This is a solution created for [TechCorner Challenge #2]

 

In Javascript:

 

 

function dragCalculatedDistance(startObject, destinationObject) {
    var startPoint, targetPoint, dragX, dragY;
    // Drag from the center of object A to the center of object B

    startPoint = startObject.WindowToScreen(startObject.Width/2, startObject.Height/2);
    targetPoint = destinationObject.WindowToScreen(destinationObject.Width/2, destinationObject.Height/2);

    dragX = targetPoint.X - startPoint.X;
    dragY = targetPoint.Y - startPoint.Y;

    startObject.Drag(-1, -1, dragX, dragY); 
}

 

 


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

Tags (1)
Highlighted
Community Manager

Re: Your Input Needed - Dragging One Element to Another

Yes, this is perfect, thank you @tristaanogre !🙂


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors