Rotated button Espresso Test Click Not Working











up vote
0
down vote

favorite












I was playing with espresso around and I noticed that one of my buttons is failing to click. I tried to move it around on the screen and everything to make it be automatically clicked, but failed. Then I noticed that it had a rotation=180. And by removing it The problem seemed to be resolved, but it is needed.



Here is my code for the test:



@Test
public void orderUp() throws Exception {
onView(ViewMatchers.withId(R.id.move_up)).perform(ViewActions.click());
onView(withText("Up")).inRoot(withDecorView(not(is(menuActivityTestRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}


So, how to make the test case work for a rotated button?



Edit: 'Error Log indicating that The Toast wasn't found I Think'



android.support.test.espresso.NoMatchingRootException: Matcher 'with decor view not is <DecorView@1ec572[MainActivity]>' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@449fd58, window-token=android.view.ViewRootImpl$W@449fd58, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1567)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at com.tabbara.mohammad.trailedsheetexample.ExampleInstrumentedTest.orderUp(ExampleInstrumentedTest.java:57)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1967)









share|improve this question
























  • What was the error log when the test clicks on a rotated button?
    – Aaron
    Nov 9 at 20:52










  • @Aaron added The error Log for the testcase
    – Mohammad Tabbara
    Nov 9 at 21:03















up vote
0
down vote

favorite












I was playing with espresso around and I noticed that one of my buttons is failing to click. I tried to move it around on the screen and everything to make it be automatically clicked, but failed. Then I noticed that it had a rotation=180. And by removing it The problem seemed to be resolved, but it is needed.



Here is my code for the test:



@Test
public void orderUp() throws Exception {
onView(ViewMatchers.withId(R.id.move_up)).perform(ViewActions.click());
onView(withText("Up")).inRoot(withDecorView(not(is(menuActivityTestRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}


So, how to make the test case work for a rotated button?



Edit: 'Error Log indicating that The Toast wasn't found I Think'



android.support.test.espresso.NoMatchingRootException: Matcher 'with decor view not is <DecorView@1ec572[MainActivity]>' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@449fd58, window-token=android.view.ViewRootImpl$W@449fd58, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1567)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at com.tabbara.mohammad.trailedsheetexample.ExampleInstrumentedTest.orderUp(ExampleInstrumentedTest.java:57)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1967)









share|improve this question
























  • What was the error log when the test clicks on a rotated button?
    – Aaron
    Nov 9 at 20:52










  • @Aaron added The error Log for the testcase
    – Mohammad Tabbara
    Nov 9 at 21:03













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I was playing with espresso around and I noticed that one of my buttons is failing to click. I tried to move it around on the screen and everything to make it be automatically clicked, but failed. Then I noticed that it had a rotation=180. And by removing it The problem seemed to be resolved, but it is needed.



Here is my code for the test:



@Test
public void orderUp() throws Exception {
onView(ViewMatchers.withId(R.id.move_up)).perform(ViewActions.click());
onView(withText("Up")).inRoot(withDecorView(not(is(menuActivityTestRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}


So, how to make the test case work for a rotated button?



Edit: 'Error Log indicating that The Toast wasn't found I Think'



android.support.test.espresso.NoMatchingRootException: Matcher 'with decor view not is <DecorView@1ec572[MainActivity]>' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@449fd58, window-token=android.view.ViewRootImpl$W@449fd58, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1567)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at com.tabbara.mohammad.trailedsheetexample.ExampleInstrumentedTest.orderUp(ExampleInstrumentedTest.java:57)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1967)









share|improve this question















I was playing with espresso around and I noticed that one of my buttons is failing to click. I tried to move it around on the screen and everything to make it be automatically clicked, but failed. Then I noticed that it had a rotation=180. And by removing it The problem seemed to be resolved, but it is needed.



Here is my code for the test:



@Test
public void orderUp() throws Exception {
onView(ViewMatchers.withId(R.id.move_up)).perform(ViewActions.click());
onView(withText("Up")).inRoot(withDecorView(not(is(menuActivityTestRule.getActivity().getWindow().getDecorView())))).check(matches(isDisplayed()));
}


So, how to make the test case work for a rotated button?



Edit: 'Error Log indicating that The Toast wasn't found I Think'



android.support.test.espresso.NoMatchingRootException: Matcher 'with decor view not is <DecorView@1ec572[MainActivity]>' did not match any of the following roots: [Root{application-window-token=android.view.ViewRootImpl$W@449fd58, window-token=android.view.ViewRootImpl$W@449fd58, has-window-focus=true, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x103046c needsMenuKey=2 naviIconColor=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}}]
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1567)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
at com.tabbara.mohammad.trailedsheetexample.ExampleInstrumentedTest.orderUp(ExampleInstrumentedTest.java:57)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1967)






android android-espresso






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 21:02

























asked Nov 9 at 20:37









Mohammad Tabbara

677521




677521












  • What was the error log when the test clicks on a rotated button?
    – Aaron
    Nov 9 at 20:52










  • @Aaron added The error Log for the testcase
    – Mohammad Tabbara
    Nov 9 at 21:03


















  • What was the error log when the test clicks on a rotated button?
    – Aaron
    Nov 9 at 20:52










  • @Aaron added The error Log for the testcase
    – Mohammad Tabbara
    Nov 9 at 21:03
















What was the error log when the test clicks on a rotated button?
– Aaron
Nov 9 at 20:52




What was the error log when the test clicks on a rotated button?
– Aaron
Nov 9 at 20:52












@Aaron added The error Log for the testcase
– Mohammad Tabbara
Nov 9 at 21:03




@Aaron added The error Log for the testcase
– Mohammad Tabbara
Nov 9 at 21:03












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










ViewActions.click finds coordinates of a view on the screen, and then performs/simulates a tap on the coordinates. I'm not exactly sure but it seems that setRotation may have affected coordinates calculation. An alternative solution would be creating a custom click action:



public static ViewAction forceClick() {
return new ViewAction() {
@Override public Matcher<View> getConstraints() {
return allOf(isClickable(), isEnabled());
}

@Override public String getDescription() {
return "force click";
}

@Override public void perform(UiController uiController, View view) {
view.performClick();
uiController.loopMainThreadUntilIdle();
}
};
}


This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app



onView(withId(R.id.move_up)).perform(forceClick());





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232947%2frotated-button-espresso-test-click-not-working%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    ViewActions.click finds coordinates of a view on the screen, and then performs/simulates a tap on the coordinates. I'm not exactly sure but it seems that setRotation may have affected coordinates calculation. An alternative solution would be creating a custom click action:



    public static ViewAction forceClick() {
    return new ViewAction() {
    @Override public Matcher<View> getConstraints() {
    return allOf(isClickable(), isEnabled());
    }

    @Override public String getDescription() {
    return "force click";
    }

    @Override public void perform(UiController uiController, View view) {
    view.performClick();
    uiController.loopMainThreadUntilIdle();
    }
    };
    }


    This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app



    onView(withId(R.id.move_up)).perform(forceClick());





    share|improve this answer

























      up vote
      0
      down vote



      accepted










      ViewActions.click finds coordinates of a view on the screen, and then performs/simulates a tap on the coordinates. I'm not exactly sure but it seems that setRotation may have affected coordinates calculation. An alternative solution would be creating a custom click action:



      public static ViewAction forceClick() {
      return new ViewAction() {
      @Override public Matcher<View> getConstraints() {
      return allOf(isClickable(), isEnabled());
      }

      @Override public String getDescription() {
      return "force click";
      }

      @Override public void perform(UiController uiController, View view) {
      view.performClick();
      uiController.loopMainThreadUntilIdle();
      }
      };
      }


      This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app



      onView(withId(R.id.move_up)).perform(forceClick());





      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        ViewActions.click finds coordinates of a view on the screen, and then performs/simulates a tap on the coordinates. I'm not exactly sure but it seems that setRotation may have affected coordinates calculation. An alternative solution would be creating a custom click action:



        public static ViewAction forceClick() {
        return new ViewAction() {
        @Override public Matcher<View> getConstraints() {
        return allOf(isClickable(), isEnabled());
        }

        @Override public String getDescription() {
        return "force click";
        }

        @Override public void perform(UiController uiController, View view) {
        view.performClick();
        uiController.loopMainThreadUntilIdle();
        }
        };
        }


        This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app



        onView(withId(R.id.move_up)).perform(forceClick());





        share|improve this answer












        ViewActions.click finds coordinates of a view on the screen, and then performs/simulates a tap on the coordinates. I'm not exactly sure but it seems that setRotation may have affected coordinates calculation. An alternative solution would be creating a custom click action:



        public static ViewAction forceClick() {
        return new ViewAction() {
        @Override public Matcher<View> getConstraints() {
        return allOf(isClickable(), isEnabled());
        }

        @Override public String getDescription() {
        return "force click";
        }

        @Override public void perform(UiController uiController, View view) {
        view.performClick();
        uiController.loopMainThreadUntilIdle();
        }
        };
        }


        This action performs click on the view by invoking performClick() without finding its coordinates. But make sure the view has the click listener attached in the app



        onView(withId(R.id.move_up)).perform(forceClick());






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 9 at 22:01









        Aaron

        1,5541212




        1,5541212






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232947%2frotated-button-espresso-test-click-not-working%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Liste der Kulturdenkmale in Wilsdruff

            Android Play Services Check