I have a screen, which is a full screen with android navigation bar hidden on the app that I am testing using Robotium. When I try to click on the only button on that screen I get (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission) error. This is at the line solo.clickOnView(solo.getView(R.id.activate_homeBtn));
Interestingly, when I touch the screen with my finger once(the android navigation bar becomes active now), then the Robotium is able to click on the button. How Can I click on the button without touching the screen manually. Below is the failure trace and the test code.
junit.framework.AssertionFailedError: Click at (360.0, 592.0) can not be completed! (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission) at com.robotium.solo.Clicker.clickOnScreen(Clicker.java:106) at com.robotium.solo.Solo.clickOnScreen(Solo.java:839) at com.abbottdiabetescare.informatics.sugarsleuth.sherlock.ui.test.ApplicationTest2.testHomeScreenNavigation_StartSensorScreen(ApplicationTest2.java:68) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214) at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199) at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1792)
public class ApplicationTest2 extends ActivityInstrumentationTestCase2 { private Solo solo;
public ApplicationTest2(String name) {
super(HomeActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
Instrumentation instrumentation = getInstrumentation();
instrumentation.waitForIdleSync();
Solo.Config config = new Solo.Config();
config.screenshotFileType = Solo.Config.ScreenshotFileType.PNG;
solo = new Solo(getInstrumentation(), config);
getActivity();
}
@Override
protected void tearDown() throws Exception {
solo.finishOpenedActivities();
super.tearDown();
}
public void testHomeScreenNavigation_StartSensorScreen() {
solo.unlockScreen();
// verify initial state
solo.assertCurrentActivity("Expected to start on Home Screen",
HomeActivity.class);
// activate
solo.clickOnView(solo.getView(R.id.activationBtn));
assertTrue(solo.waitForActivity(ActivateActivity.class));
solo.takeScreenshot("HomeScrnNvgn_StartSensorScreen");
assertTrue(solo.waitForActivity(ActivateActivity.class));
solo.clickOnView(solo.getView(R.id.activate_homeBtn));
assertTrue(solo.waitForActivity(HomeActivity.class));
}
}