Ramble01 / android-test-kit

Automatically exported from code.google.com/p/android-test-kit
0 stars 0 forks source link

Click() becomes longClick() #45

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
onView(withId(R.id.abc)).perform(click()) sometimes does long click instead

What is the expected output? What do you see instead?
It should always do click. Doing long click sometimes makes the test flaky.

What version of the product are you using? On what operating system?
All versions of Android OS. Espresso 1.1 test kit

Please provide any additional information below.
I understand that you put a comment there saying that there's no perfect way to 
do this, but I remember that I didn't see this problem when I was using 
Robotium. Here is what Robotium does:

long downTime = SystemClock.uptimeMillis();
                        long eventTime = SystemClock.uptimeMillis();
                        MotionEvent event = MotionEvent.obtain(downTime, eventTime,
                                        MotionEvent.ACTION_DOWN, x, y, 0);
                        MotionEvent event2 = MotionEvent.obtain(downTime, eventTime,
                                        MotionEvent.ACTION_UP, x, y, 0);
                        try{
                                inst.sendPointerSync(event);
                                inst.sendPointerSync(event2);
                                successfull = true;
                        }

Espresso is using the UiController, so it may not be able to send motion event 
like Robotium does. But, the downtime and event time is also different between 
Espresso and Robotium. Maybe it can improve this problem by making this part of 
code as close as Robotium.

Original issue reported on code.google.com by K76...@gmail.com on 15 Jan 2014 at 8:56

GoogleCodeExporter commented 9 years ago
I see this intermittently as well. It takes away some of the reliability of the 
tests, unfortunately. The best I've come up with was to create a custom 
ViewAction as the rollback that what does is basically wait for 
android.R.integer.config_longAnimTime. Although this makes the problem go away 
I don't really want to do this kind of hacking.

Original comment by GoncaloS...@gmail.com on 7 Mar 2014 at 4:33

GoogleCodeExporter commented 9 years ago
Please, fix the issue. My tests fail randomly 

Original comment by Ryabov.G...@gmail.com on 23 Jul 2014 at 3:00

GoogleCodeExporter commented 9 years ago
Yup I am experiencing this problem as well. I have a case that I can reproduce 
100% of the time using the Nexus 4 or Samsung Nexus

Create a share intent and then try and perform a click on the dialog that is 
shown. The long click is performed and so this opens up the settings page for 
that particular app. This line has the problem

        onView(withText("Gmail")).perform(click());

Original comment by s...@waymate.de on 19 Sep 2014 at 2:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Can you try using the click method which accepts a RollBack action incase it 
turns into a longClick? 

onView(withText("Gmail")).perform(click(Espresso.pressBack())); 

-----From ViewActions.java -----
 /**
   * Returns an action that performs a single click on the view.
   *
   * If the click takes longer than the 'long press' duration (which is possible) the provided
   * rollback action is invoked on the view and a click is attempted again.
   *
   * This is only necessary if the view being clicked on has some different behaviour for long press
   * versus a normal tap.
   *
   * For example - if a long press on a particular view element opens a popup menu -
   * ViewActions.pressBack() may be an acceptable rollback action.
   *
   * <br>
   * View constraints:
   * <ul>
   * <li>must be displayed on screen</li>
   * <li>any constraints of the rollbackAction</li>
   * <ul>
   */
  public static ViewAction click(ViewAction rollbackAction) {
    checkNotNull(rollbackAction);
    return new GeneralClickAction(Tap.SINGLE, GeneralLocation.CENTER, Press.FINGER,
        rollbackAction);
  }

Original comment by yashodha...@gmail.com on 19 Sep 2014 at 2:29