Ask a Question

problem with a drag command

SOLVED
asavoia
Occasional Contributor

problem with a drag command

hi everyone, I have a problem with the drag command.
since I don't want to use coordinates, is it possible to use drag in some alternative method?
I don't want to use the coordinates because I wouldn't want to have problems if I have to change the screen resolution where they run my test.

4 REPLIES 4
BenoitB
Community Hero

Do you drag on same object, on different object ?

You can use coordinates based upon object ScreenLeft and ScreenTop properties.

Un sourire et ça repart

tristaanogre
Esteemed Contributor

The drag command in testcomplete needs co-ordinates.  You need to know the object to be dragged and the destination and that is, for the Drag method, co-ordinate based.

 

but!  Never fear... I've got a code for that.

 

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); 
}

As noted in the comments, this will drag from roughly the center of the starting object to the center of the destination object.


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
AlexKaras
Champion Level 2

Hi,

 

As per the documentation for the .Drag() method, initial coordinates are "relative to the object, it is not a screen coordinate." The distance to execute dragging for is also calculated as a relative distance between two objects.

So, (as it was mentioned by @BenoitB), proper use of relevant .ScreenLeft/.ScreenTop/.Left/.Top properties of the required objects will provide you with resolution-agnostic code for .Drag().

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
sonya_m
SmartBear Alumni (Retired)

Thank you for helping all!

 

Hi @asavoia! Please mark the asnwer that helped you solve the issue as a solutionSmiley Happy


Sonya Mihaljova
Community and Education Specialist

cancel
Showing results for 
Search instead for 
Did you mean: