jxs1211 / android-test-kit

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

Performing a click on an AlertDialog button throws "InjectEventSecurityException: Injecting to another application requires INJECT_EVENTS permission" #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an activity with an AlertDialog. Don't give the button an ID. 
Instead, use the defaults, android.R.id.button1 and android.R.id.button2.

2. In the test, attempt to click on the negative button using

onView(withId(android.R.id.button2)).perform(click());

3. an Exception is thrown.

What is the expected output? What do you see instead?

I expect the dialog to dismiss itself, instead an Exception is thrown:

com.google.android.apps.common.testing.ui.espresso.PerformException: Error 
performing 'single click' on view 'with id: is <16908314>'.
at 
com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.buil
d(PerformException.java:67)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ge
tUserFriendlyError(DefaultFailureHandler.java:57)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ha
ndle(DefaultFailureHandler.java:40)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronou
slyOnUiThread(ViewInteraction.java:159)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(Vie
wInteraction.java:90)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewI
nteraction.java:73)
at 
net.he.networktools.test.BaseUiTest.selectNegativeDialogButton(BaseUiTest.java:9
2)
at 
net.he.networktools.test.DialogIpVerificationTest.testDialog(DialogIpVerificatio
nTest.java:25)
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(ActivityInstrumentationTes
tCase2.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:55
4)
at 
com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunne
r.onStart(GoogleInstrumentationTestRunner.java:167)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: com.google.android.apps.common.testing.ui.espresso.PerformException: 
Error performing 'Send down montion event' on view 'unknown'.
at 
com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.buil
d(PerformException.java:67)
at 
com.google.android.apps.common.testing.ui.espresso.action.MotionEvents.sendDown(
MotionEvents.java:90)
at 
com.google.android.apps.common.testing.ui.espresso.action.Tap$1.sendTap(Tap.java
:24)
at 
com.google.android.apps.common.testing.ui.espresso.action.GeneralClickAction.per
form(GeneralClickAction.java:82)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInt
eraction.java:119)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4998)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
Caused by: 
com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException:
 java.lang.SecurityException: Injecting to another application requires 
INJECT_EVENTS permission
at 
com.google.android.apps.common.testing.ui.espresso.base.InputManagerEventInjecti
onStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:131)
at 
com.google.android.apps.common.testing.ui.espresso.base.EventInjector.injectMoti
onEvent(EventInjector.java:80)
at 
com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(
UiControllerImpl.java:201)
at 
com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(
UiControllerImpl.java:198)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Injecting to another application 
requires INJECT_EVENTS permission
at android.os.Parcel.readException(Parcel.java:1461)
at android.os.Parcel.readException(Parcel.java:1415)
at 
android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.j
ava:356)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:641)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.google.android.apps.common.testing.ui.espresso.base.InputManagerEventInjecti
onStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:122)
... 9 more

What version of the product are you using? On what operating system?

espresso-contrib-1.1-bundled.jar on Mac OS X version 10.9 running Android 4.4.2 
in an Intel x86 w/ HAXM emulator. Using Android Studio IDE.

Please provide any additional information below.

Adding the permission "android.permissions.INJECT_EVENTS", a warning is shown 
in the manifest "Permission is only granted to system apps" but compiles anyway.

Original issue reported on code.google.com by matthew....@gmail.com on 1 Mar 2014 at 1:25

GoogleCodeExporter commented 9 years ago
Same error is shown (after many tests) when using,

onView(withText(R.string.cancel)).perform(click());

com.google.android.apps.common.testing.ui.espresso.PerformException: Error 
performing 'single click' on view 'with text: is "Cancel"'.
at 
com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.buil
d(PerformException.java:67)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ge
tUserFriendlyError(DefaultFailureHandler.java:57)
at 
com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.ha
ndle(DefaultFailureHandler.java:40)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronou
slyOnUiThread(ViewInteraction.java:159)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(Vie
wInteraction.java:90)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewI
nteraction.java:73)
at <package>.test.BaseUiTest.selectNegativeDialogButton(BaseUiTest.java:92)
at 
<package>.test.DialogIpVerificationTest.testDialog(DialogIpVerificationTest.java
:25)
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(ActivityInstrumentationTes
tCase2.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:55
4)
at 
com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunne
r.onStart(GoogleInstrumentationTestRunner.java:167)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Caused by: com.google.android.apps.common.testing.ui.espresso.PerformException: 
Error performing 'Send down montion event' on view 'unknown'.
at 
com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.buil
d(PerformException.java:67)
at 
com.google.android.apps.common.testing.ui.espresso.action.MotionEvents.sendDown(
MotionEvents.java:90)
at 
com.google.android.apps.common.testing.ui.espresso.action.Tap$1.sendTap(Tap.java
:24)
at 
com.google.android.apps.common.testing.ui.espresso.action.GeneralClickAction.per
form(GeneralClickAction.java:82)
at 
com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInt
eraction.java:119)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4998)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
Caused by: 
com.google.android.apps.common.testing.ui.espresso.InjectEventSecurityException:
 java.lang.SecurityException: Injecting to another application requires 
INJECT_EVENTS permission
at 
com.google.android.apps.common.testing.ui.espresso.base.InputManagerEventInjecti
onStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:131)
at 
com.google.android.apps.common.testing.ui.espresso.base.EventInjector.injectMoti
onEvent(EventInjector.java:80)
at 
com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(
UiControllerImpl.java:201)
at 
com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(
UiControllerImpl.java:198)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by: java.lang.SecurityException: Injecting to another application 
requires INJECT_EVENTS permission
at android.os.Parcel.readException(Parcel.java:1461)
at android.os.Parcel.readException(Parcel.java:1415)
at 
android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.j
ava:356)
at android.hardware.input.InputManager.injectInputEvent(InputManager.java:641)
at java.lang.reflect.Method.invokeNative(Native Method)
at 
com.google.android.apps.common.testing.ui.espresso.base.InputManagerEventInjecti
onStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:122)
... 9 more

Original comment by matthew....@gmail.com on 1 Mar 2014 at 1:42

GoogleCodeExporter commented 9 years ago
I'm facing this same issue intermittently with menu items in the action bar.

Original comment by GoncaloS...@gmail.com on 4 Mar 2014 at 5:10

GoogleCodeExporter commented 9 years ago
Same issue here, but with Robotium. This may be an issue of the x86 system 
image and not of espresso.

Original comment by kn...@synyx.de on 7 Apr 2014 at 1:31

GoogleCodeExporter commented 9 years ago
Same here on HW device with KitKat 4.4.2. Anims off.

Original comment by seva...@gmail.com on 1 May 2014 at 1:58

GoogleCodeExporter commented 9 years ago
This means that something (e.g. a system ANR dialog or keyguard) is blocking 
the view you're trying to click. This is outside Espresso scope and should be 
fixed on a device setup level.

Original comment by vale...@google.com on 6 May 2014 at 11:58

GoogleCodeExporter commented 9 years ago
At least in my case this only happens with menu items on the action bar. It's 
intermittent, but easily reproducible. I doubt there's any ANR involved, 
otherwise I'd probably see it with regular views. No?

Original comment by GoncaloS...@gmail.com on 8 May 2014 at 10:45