Drag and Drop with Telerik Testing Framework



Posting a blog after a long time, so I'm not gonna add a huge description here.

Most of the user friendly web applications support drag and drop commands/actions and even though lot of test automation IDEs support drag and drop its dosent work most of the time, Trust me I have tired. So on today's post we will discuss how to perform this simple task using Telerik Test studio

Step 1

First you have to identify which are the two elements you're going to use for this operation

Eg: I'm using 2 HTML div Elements

ids: dragitem, droptiem

Since you're using a code first method first you have to identify the 2 elements in the web browser



 HtmlDiv Dragitemspan = ActiveBrowser.Find.ById("dragitem").As<HtmlDiv>();  
 HtmlDiv dropitemspan= myManager.ActiveBrowser.Find.ById("dropitem").As<HtmlDiv>();  

This is the vary basic method of identifying an element in Telerik test studio, you could use page object class or a page factory class to  make the code more maintainable, this is just an example

Step 2

Basic drag and drop method

use the following code

 dragitemspan.DragTo(dropitemspan)  

This works some times but sometimes this doesn't work because the automation code doesnt work exactly the same as  how a user performs the drag and drop

eg: mouse hover tasks doesn't trigger in automation codes, you have specifically trigger them

The complex drag and drop method

So if this doesn't work what are the other options we have?

Method DragTo() has 9 overloading methods 


so you can use them here, but what is the most meaningful and useful method of these? 




 DragTo(Point absolutePoint);  
 DragTo(int offsetX, int offsetY);  
 DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, HtmlControl destination);  
 DragTo(HtmlControl control, OffsetReference destinationOffsetReference, Point destinationOffset);  
 DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, int destinationOffsetX, int destinationOffsetY);  
 DragTo(OffsetReference sourceOffsetReference, Point sourceOffset, HtmlControl destination, OffsetReference destinationOffsetReference, Point destinationOffset);  
 DragTo(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, Rectangle destinationRectangle, OffsetReference destinationOffsetReference, int destinationOffsetX, int destinationOffsetY);  
 DragTo(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, bool sourcePixelDrag, HtmlControl destination, OffsetReference destinationOffsetReference, int destinationOffsetX, int destinationOffsetY, bool pixelDrop);  
 DragToWindowLocation(OffsetReference sourceOffsetReference, int sourceOffsetX, int sourceOffsetY, bool sourcePixelDrag, OffsetReference windowOffset, int windowOffsetX, int windowOffsetY, bool pixelDrop);  

How do we define the most useful overload method from here?

1.. Can we rely on x,y locations on a browser?
2. how many offsets we have?
3. how to define points?

Cant rely on xy locations, this is my argument, so what I'm proposing to use is the 5th overload method


 DragTo(HtmlControl control, OffsetReference destinationOffsetReference, Point destinationOffset);  


Because this is using the HTML control so offsets doesn't apply to the whole screen its only inside the control

So what is an offset referance?

Offset reference is which part of the droptiem  element you are going to drop the dragitem 

its really easy to use offset use the below code

 ArtOfTest.Common.OffsetReference.BottomLeftCorner  

You could use: 
BottomLeftCorner 
TopLeftCorner 
BottomrightCorner 


so how do i set the point?

Point should be created from System.Drawing class

 var des = new System.Drawing.Point();  
 des.X = topcontentarea.ScrollTop;  
 des.Y = topcontentarea.ScrollLeft;  


now we need all the valibales you need to pass for the DragTo() Method


 dragitem.DragTo(dropitem, ArtOfTest.Common.OffsetReference.BottomLeftCorner, des);  


There you go!!! :)  Happy testing

Comments

Popular posts from this blog

Sheduling tests - Running Tests From the Command line | Telerik Testing Framework

Using page object model with Telerik Framework