Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.support.test.espresso.InjectEventSecurityException is thrown when I try to fill several edittexts using espresso

Here is my code:

onView(withId(R.id.first_name)).perform(
                typeText("John"), closeSoftKeyboard());
SystemClock.sleep(5000);
onView(withId(R.id.last_name)).perform(typeText("Smith"));

I tried answers from here Android :java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission and it didn't help.

Here are expresso versions I use:

// Android Test Support Libraries
    espressoRunnerVersion = "0.5"
    espressoRulesVersion = "0.5"
    espressoVersion = "2.2.2"

Here is the full stacktrace:

android.support.test.espresso.PerformException: Error performing 'type text(Smith)' on view 'with id: church.life.app:id/last_name'.
at android.support.test.espresso.PerformException$Builder.build(PerformException.java:84)
at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:81)
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.desugaredPerform(ViewInteraction.java:167)
at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:110)
at church.life.app.ui.profile.ProfileSignupTest.InvalidSignupTest(ProfileSignupTest.java:44)
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:2337)
Caused by: android.support.test.espresso.InjectEventSecurityException: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.support.test.espresso.base.InputManagerEventInjectionStrategy.injectKeyEvent(InputManagerEventInjectionStrategy.java:118)
at android.support.test.espresso.base.EventInjector.injectKeyEvent(EventInjector.java:84)
at android.support.test.espresso.base.UiControllerImpl$2.call(UiControllerImpl.java:195)
at android.support.test.espresso.base.UiControllerImpl$2.call(UiControllerImpl.java:192)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
at android.os.Parcel.createException(Parcel.java:1942)
at android.os.Parcel.readException(Parcel.java:1910)
at android.os.Parcel.readException(Parcel.java:1860)
at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:575)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:880)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.test.espresso.base.InputManagerEventInjectionStrategy.injectKeyEvent(InputManagerEventInjectionStrategy.java:109)
... 9 more
Caused by: android.os.RemoteException: Remote stack trace:
at com.android.server.input.InputManagerService.injectInputEventInternal(InputManagerService.java:627)
at com.android.server.input.InputManagerService.injectInputEvent(InputManagerService.java:601)
at android.hardware.input.IInputManager$Stub.onTransact(IInputManager.java:143)
at android.os.Binder.execTransact(Binder.java:752)

I tried with sleep and without, also I tried to move closeSoftKeyboard outside perform action.

like image 745
Semyon Avatar asked Oct 22 '18 13:10

Semyon


1 Answers

Place a breakpoint on the line

onView(withId(R.id.first_name)).perform(typeText("John"), closeSoftKeyboard());

When you step over that line, do you see an AutoComplete popover? If so, the problem is that the popover is changing the focus of the EditText and you are attempting to perform a typeText method at that time.

Simplest Solution: replace typeText() with replaceText(). The keyboard will not display, but if your integration test is not testing for UI placement during the presentation of the keyboard, this will work. It should look like:

onView(withId(R.id.first_name)).perform(replaceText("John"));
like image 173
Mark Filter Avatar answered Sep 18 '22 02:09

Mark Filter