Drag and Drop Feature In QTP(Mercurry.DeviceReplay) AND CLASS Concept in QTP
In this page i would demonstrate how to use DRAG and DROP feature. Also Explain how to implement Class Concept in QTP
What is the Need for Device.Replay Object?
Device Replay Object Provides Good Support For all Mouse(DRAG AND DROP option) and Keyboard operation .We have faced issues in automating sometimes .Set and .Type Operation some how Doesnt work for you.In this Cases Its good to use for Device.replay
FROM THE BELOW CODE ONE SHOULD UNDERSTAND THE BASIC IDEA OF HOW TO WORK AROUND WITH Device.replay object and how to use CLASS concept in QTP.
' ** This class holds a point coordinate Class Point Private mX, mY Property Let X( ByVal value ) mX = value End Property Property Get X() X = mX End Property Property Let Y( ByVal value ) mY = value End Property Property Get Y() Y = mY End Property End Class ' ** FIRST OBJECTIVE TO GET THE HANDLE of window AND ACTIVATE THE BROWSER IF YOU ARE USING device replay object hwnd = Browser("QTP").GetROProperty( "hwnd" ) Window( "hwnd:=" & hwnd ).Activate ' ** Create a description of the 1st object Set oWebElemDesc1 = Description.Create() oWebElemDesc1( "micclass" ).Value = "WebElement" oWebElemDesc1( "html tag" ).Value = "------------″ oWebElemDesc1( "innertext" ).Value = "--------------" oWebElemDesc1( "class" ).Value = "------------------" ' ** Create a description for 2nd object Set oWebElementDesc2 = Description.Create() oWebElemDesc2( "micclass" ).Value = "WebElement" oWebElemDesc2( "html tag" ).Value = "---------″ oWebElemDesc2( "innertext" ).Value = "--------" oWebElemDesc2( "class" ).Value = "--------------" ' ** Search for the Object using the Description created above With Browser( "BROWSER NAME " ).Page( "PAGE NAME " ) If .ChildObjects( oWebElemDesc1 ).Count = 1 Then Set oWebElem1 = .WebElement( oWebElemDesc1 ) If .ChildObjects( oWebElemDesc2 ).Count = 1 Then Set oWebElem2 = .WebElement( oWebElemDesc2 ) Else Print "Web Element 'Program Professionally’ was not found." ExitTest( micFail ) End If Else Print "Web Element 'Program Professionally’ was not found." ExitTest( micFail ) End If End With ' Once the OBJECT has been detected USING THAT OBJECT FIND THE X,Y & height Coordinates nX1 = oWebElem1.GetROProperty( "abs_x" ) nH1 = oWebElem1.GetROProperty( "height" ) nY1 = oWebElem1.GetROProperty( "abs_y" ) nX2 = oWebElem2.GetROProperty( "abs_x" ) nH2 = oWebElem2.GetROProperty( "height" ) nY2 = oWebElem2.GetROProperty( "abs_y" ) Set point1 = New Point point1.X = nX1 + 10 point1.Y = nY1 + nH1 - 10 Set point2 = New Point ' ** Dragging up If nY1 > nY2 Then point2.X = nX2 + 20 point2.Y = nY2 + nH2 - 20 Else ' ** Dragging down point2.X = nX2 + 20 point2.Y = nY2 + nH2 + 20 End If Set devRep = CreateObject( "Mercury.DeviceReplay" ) devRep.DragAndDrop point1.X, point1.Y,point2.X, point2.Y, 0
leave a comment