Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click() becomes longClick() #45

Open
GoogleCodeExporter opened this issue May 29, 2015 · 7 comments
Open

Click() becomes longClick() #45

GoogleCodeExporter opened this issue May 29, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 15 Jan 2014 at 8:56

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 7 Mar 2014 at 4:33

@GoogleCodeExporter
Copy link
Author

Please, fix the issue. My tests fail randomly 

Original comment by [email protected] on 23 Jul 2014 at 3:00

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 19 Sep 2014 at 2:22

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 19 Sep 2014 at 2:29

@GoogleCodeExporter
Copy link
Author

We've been using doubleClick instead of click when Espresso decides to 
longPress. It's a good way to get a faster click to avoid triggering a 
longPress. However, if your app is already using double click actions, this may 
not be a good solution.

Original comment by [email protected] on 5 May 2015 at 4:29

@GoogleCodeExporter
Copy link
Author

I think the click action that takes a rollback action is probably the best 
solution most of the time, but it might not be enough for all scenarios.  I 
wrote a custom view action for scenarios where a rollback action didn't resolve 
my problems.  It's definitely not the "Espresso" way, but flaky tests need to 
be resolved and this has worked for me: 
https://gist.github.com/jabKnowsNothing/fe34673419500dcc6fc9.

Original comment by [email protected] on 19 May 2015 at 9:11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant