Search Unity

How to press the mouse and drag during the test?

Discussion in 'Testing & Automation' started by dougfy, Nov 29, 2021.

  1. dougfy

    dougfy

    Joined:
    Nov 9, 2015
    Posts:
    3
    In a play mode test I am able to effectively click on items. In some cases I need to drag an item. My first test is actually a scrollview panel that the mouse can move with the left button press and drag. I would have thought you just do the following (assumes the scroll surface is visible at 10,10):

    Code (CSharp):
    1. Set(mouse.position, new Vector2(10,10));
    2. Press(mouse.leftButton);
    3. yield return new WaitForSeconds(0.1f);
    4. InputSystem.Update();
    5. Set(mouse.position, new Vector2(1000,10));
    6. Release(mouse.leftButton);
    7. yield return new WaitForSeconds(0.1f);
    I can debug and see the mouse down/up occurs, and there was a value for delta. Yet the scroll panel does not move. I was able to make the panel move with:

    Code (CSharp):
    1. Set(mouse.scroll, new Vector2(7000,100));
    2. yield return new WaitForSeconds(0.1f);
    So it's functional. Unfortunately I have items that are actual drag and drop. I have yet to find any example how this is properly done as a test. Anyone have a working sample?