2013-05-28

How to long press in Robotium?

In this article we are going to see how to click /press long. It is a spatial event like as clicking. Android provide separate event handler for long press. Ex- when we press on screen long time(3s+), the menu comes.

We need to initiate the Solo object. After initiation, we will uses solo to get those.

-To Long click on specific list line of a text view. It returns an ArrayList of the TextView objects (contains the lines). It will get the first ListView that it finds.
solo.clickLongInList(0);

-To Long click on specific list line of a text view and the index. It returns an ArrayList of the TextView objects (contains the lines).
solo.clickLongInList(1,0);

-To Long click on specific list line of a text view , the index and the amount of time (long press time in millisecond integer) . It returns an ArrayList of the TextView objects (contains the lines).
solo.clickLongInList(2, 1,5);

-To Long click on specific coordinate X, Y. This coordinate is the resolution of the screen.Ex-480x800, here X=480(max) and Y=800(max) in portrait mode.
solo.clickLongOnScreen(240, 400);

-To Long click on specific coordinate X, Y and the amount of time (long press time in millisecond integer)
solo.clickLongOnScreen(240,400,5);

-To Long click on a View/Web Element displaying a specific text. It will automatically scroll.
solo.clickLongOnText("TextToClick");

-To Long click on a View/Web Element displaying a specific text and the index for multiple match. It will automatically scroll.
solo.clickLongOnText("Regix", 0);

-To Long click on a View/Web Element displaying a specific text , the index for multiple match and scroll Boolean value . Provide true when if we need to enable scrolling.
solo.clickLongOnText("Regix", 0, true);

-To Long click on a View/Web Element displaying a specific text , the index for multiple match and the amount of time (long press time in millisecond integer)
solo.clickLongOnText("Regix", 0, 5);

-To Long click on specific text and then selects an item(index) from the context menu that appears. It will automatically scroll.
solo.clickLongOnTextAndPress("Regix", 1);

-To Long click on specific view. In here myView is a view object.
solo.clickLongOnView(myView);

-To Long click on specific view and the amount of time (long press time in millisecond integer)
solo.clickLongOnView(myView, 5);

Thanks...:)

2 comments:

  1. Shantonu,

    I would like to know how do I verify all the items present in the list.

    ReplyDelete
    Replies
    1. we need the list items as iteration with assertion(is item present/ search with text).. like, if we have a combo box, first we need to get the items of the combo and iterate inside of the items with assertion for specific items. (we can manually assert without iteration also but it will need more coding)

      Delete