locked
Automating drag and drop functionality using Coded UI Test RRS feed

  • Question

  • Hi All,

    I have a application in which i need to drag and drop the items from one pane to another. While automating Coded UI test is recording the steps but while replay it starts to drag and doesnt move at all. If i move my mouse a bit the the drop happens properly. Can anyone help me how i can overcome this situation

    Thanks in advance

    Nithya

    Thursday, March 31, 2011 1:52 PM

Answers

  • I had the same issue and could only solve it by changing the Playback settings for the coded UI test.  

    In the example you can see that I set the Playback settings to WaitForReadyLevel.Disabled and Timeout to 0.

    This is the only way I found to make the mouse move during a drag.

    My example:

     

    // Disable the wait for ready of UI thread so we can move the mouse a bit and initiate the drag drop
    			int waitForReadyTimeOut = Playback.PlaybackSettings.WaitForReadyTimeout;
    			Playback.PlaybackSettings.WaitForReadyTimeout = 0;
    			Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
     
     
    			// Do Drag and Drop
    			uIItemPane.EnsureClickable(...);
    			Mouse.StartDragging(dragItem, dragItem.GetClickablePoint());
    			Mouse.Move()...
    			Mouse.StopDragging(uIItemPane, ...);
     
    			// Re-enable the wait for ready playback to UI Thread waiting
    			Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
    			Playback.PlaybackSettings.WaitForReadyTimeout = waitForReadyTimeOut;

     

    Tuesday, July 19, 2011 9:41 PM

All replies

  • Can you please share the generated code for drag and drop action, I'll see if you can put some additional code to move the mouse so that drag and drop can continue further?
    Friday, April 8, 2011 5:40 AM
  • Can you please share the generated code for drag and drop action, I'll see if you can put some additional code to move the mouse so that drag and drop can continue further?


    Hi Deepak,

    There are multiple occurances where the mouse drag drop happens., i have pasted one such drag drop code generated while recording

    Mouse.StartDragging(uIItemClient2, new Point(104, 24));
    Mouse.StopDragging(uICareEnhanceCallCenteClient, new Point(53, 12));

    I tried to add Mouse.Move... but no chance with that

    Thanks in advance

    Nithya

    Friday, April 8, 2011 2:30 PM
  • Can you please share the generated code for drag and drop action, I'll see if you can put some additional code to move the mouse so that drag and drop can continue further?


    Hi Deepak,

    There are multiple occurances where the mouse drag drop happens., i have pasted one such drag drop code generated while recording

    Mouse.StartDragging(uIItemClient2, new Point(104, 24));
    Mouse.StopDragging(uICareEnhanceCallCenteClient, new Point(53, 12));

    I tried to add Mouse.Move... but no chance with that

    Thanks in advance

    Nithya


    Hi Deepak...

    Any update on the above issue

    Thanks,

    Nithya

    Tuesday, April 12, 2011 4:16 AM
  • Hi Nithya, sorry for the delay. Please expect a response by today.
    Tuesday, April 12, 2011 4:56 AM
  • Though I was not able to repro the same issue at my end but can you try putting this code between StartDragging and StopDragging call

    Mouse

     

    .Move(uIItemClient2, new Point(uIItemClient2.BoundingRectangle.Right+5, uIItemClient2.BoundingRectangle.Bottom+5));

    The basic idea here is to move the mouse out of the UI Cotnrol that you are trying to move. You can probably try out different values for co-ordinates and see if this enables your scenario.

     
    • Marked as answer by Nithya'S Thursday, April 21, 2011 6:02 AM
    • Unmarked as answer by Nithya'S Monday, June 27, 2011 5:13 AM
    Tuesday, April 12, 2011 12:44 PM
  • Though I was not able to repro the same issue at my end but can you try putting this code between StartDragging and StopDragging call

    Mouse

     

    .Move(uIItemClient2, new Point(uIItemClient2.BoundingRectangle.Right+5, uIItemClient2.BoundingRectangle.Bottom+5));

    The basic idea here is to move the mouse out of the UI Cotnrol that you are trying to move. You can probably try out different values for co-ordinates and see if this enables your scenario.

     


    Hi Deepak,

    I gave a try with your code but it seems to be working only when i execute the test using F11 (Step Into).. after that if i execute the script completely (using F5) again it requires a manual mouse move action

    If there any other way to we can perform drag and drop operation other than this mouse move action

    Thanks,

    Nithya

    Wednesday, April 13, 2011 9:34 AM
  • Can you try doing like this.

    Mouse.click(UiItemClient2);
    Mouse.StartDragging(uIItemClient2, new Point(104, 24));
    Mouse.StopDragging(uICareEnhanceCallCenteClient, new Point(53, 12));
    Mouse.click(uICareEnhanceCallCenteClient);
    

    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox
    • Marked as answer by Nithya'S Thursday, April 21, 2011 6:02 AM
    • Unmarked as answer by Nithya'S Monday, June 27, 2011 5:13 AM
    Wednesday, April 13, 2011 11:16 AM
  • Can you try doing like this.

    Mouse.click(UiItemClient2);
    
    Mouse.StartDragging(uIItemClient2, new Point(104, 24));
    
    Mouse.StopDragging(uICareEnhanceCallCenteClient, new Point(53, 12));
    
    Mouse.click(uICareEnhanceCallCenteClient);
    
    

    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox


    Hi Venkat,

    The solution provided by you seems to be working but taking a long time to complete the task

    Thanks,

    Nithya

    Thursday, April 21, 2011 6:02 AM
  •  

    Hi Venkat/Deepak,

    Am facing an issue with drag and drop again. I tried the both the ways you people suggested. Now my problem here is the item is dragging and before dropping onto the desired Pane coded Ui test is throwing one of the the following errors:

    1. Failed to perform action on the Blocked control

    2. The control is not available or not valid

    3. Cannot perform 'Drag' on the control. Additional Details:
    TechnologyName:  'MSAA'
    Name:  'XXXXXXXXXXXXXXXXX Version: C00001'
    ControlType:  'Client'

    4. Another control is blocking the control (for this i tried to minimize the parent window then this error didnt came)

    Kindly let me know what could be the reason for this. Am confused so much

    Thanks in Advance,
    Nithya

     


    Friday, June 24, 2011 11:54 AM
  • I had the same issue and could only solve it by changing the Playback settings for the coded UI test.  

    In the example you can see that I set the Playback settings to WaitForReadyLevel.Disabled and Timeout to 0.

    This is the only way I found to make the mouse move during a drag.

    My example:

     

    // Disable the wait for ready of UI thread so we can move the mouse a bit and initiate the drag drop
    			int waitForReadyTimeOut = Playback.PlaybackSettings.WaitForReadyTimeout;
    			Playback.PlaybackSettings.WaitForReadyTimeout = 0;
    			Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled;
     
     
    			// Do Drag and Drop
    			uIItemPane.EnsureClickable(...);
    			Mouse.StartDragging(dragItem, dragItem.GetClickablePoint());
    			Mouse.Move()...
    			Mouse.StopDragging(uIItemPane, ...);
     
    			// Re-enable the wait for ready playback to UI Thread waiting
    			Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.UIThreadOnly;
    			Playback.PlaybackSettings.WaitForReadyTimeout = waitForReadyTimeOut;

     

    Tuesday, July 19, 2011 9:41 PM