suli1 / android-test-kit

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

SecurityException performing 'single click' on view #28

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. mvn package
(I wasn't able to run the tests without following 
https://code.google.com/p/android-test-kit/issues/detail?id=4)
2. adb shell setprop dalvik.vm.dexopt-flags v=n,o=v
3. adb shell stop installd
4. adb shell start installd
5. adb shell am instrument -w -e class 
com.google.android.apps.common.testing.ui.espresso.tests.BasicTest#testTypingAnd
PressBack 
com.google.android.apps.common.testing.ui.espresso.tests/com.google.android.apps
.common.testing.testrunner.GoogleInstrumentationTestRunner

What is the expected output?

Test passes

What do you see instead?

com.google.android.apps.common.testing.ui.espresso.tests.BasicTest:
Error in testTypingAndPressBack:
com.google.android.apps.common.testing.ui.espresso.PerformException: Error 
performing 'single click' on view 'with id: is <2131034239>'.
    at com.google.android.apps.common.testing.ui.espresso.PerformException$Builder.build(PerformException.java:67)
    at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:57)
    at com.google.android.apps.common.testing.ui.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:40)
    at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:146)
    at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.doPerform(ViewInteraction.java:77)
    at com.google.android.apps.common.testing.ui.espresso.ViewInteraction.perform(ViewInteraction.java:69)
    at com.google.android.apps.common.testing.ui.espresso.tests.BasicTest.testTypingAndPressBack(BasicTest.java:57)
    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 com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:119)
    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.build(PerformException.java:67)
    at com.google.android.apps.common.testing.ui.espresso.action.Tap.sendDown(Tap.java:154)
    at com.google.android.apps.common.testing.ui.espresso.action.Tap.access$100(Tap.java:19)
    at com.google.android.apps.common.testing.ui.espresso.action.Tap$1.sendTap(Tap.java:27)
    at com.google.android.apps.common.testing.ui.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:81)
    at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$1.run(ViewInteraction.java:106)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at android.os.Handler.handleCallback(Handler.java:730)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
    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.InputManagerEventInjectionStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:131)
    at com.google.android.apps.common.testing.ui.espresso.base.EventInjector.injectMotionEvent(EventInjector.java:80)
    at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(UiControllerImpl.java:199)
    at com.google.android.apps.common.testing.ui.espresso.base.UiControllerImpl$3.call(UiControllerImpl.java:196)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
    at java.util.concurrent.FutureTask.run(FutureTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
    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:1431)
    at android.os.Parcel.readException(Parcel.java:1385)
    at android.hardware.input.IInputManager$Stub$Proxy.injectInputEvent(IInputManager.java:356)
    at android.hardware.input.InputManager.injectInputEvent(InputManager.java:623)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at com.google.android.apps.common.testing.ui.espresso.base.InputManagerEventInjectionStrategy.injectMotionEvent(InputManagerEventInjectionStrategy.java:122)
    ... 9 more

Test results for GoogleInstrumentationTestRunner$BridgeTestRunner=.E
Time: 2.552

FAILURES!!!
Tests run: 1,  Failures: 0,  Errors: 1

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

espresso-standalone/espresso-1.0-SNAPSHOT-bundled.jar
Nexus 4
Nexus 4 emulator image

Please provide any additional information below.

The problem was first observed running tests on an LG Nexus 4. The error was 
then reproduced in an emulator running the Nexus 4 preset (hardware keyboard 
not enabled).
Turning on the hardware keyboard option works around the crash (in the 
emulator). Using a different resolution emulator image (ex. 480x854) also seems 
to avoid the problem.

It appears that Espresso is not waiting for the completion of the 
closeSoftKeyboard() and the perform(click()) is being sent to the system UI 
view (soft keyboard) instead of the Button, as desired. 

Original issue reported on code.google.com by daniel.j...@jadedpixel.com on 28 Nov 2013 at 5:32

GoogleCodeExporter commented 9 years ago
I am running into the same problem with the Nexus 5 and the softkeyboard being 
open, before the button click.  I enter text into the edit text field then 
closeSoftKeyboard then preform click.  I put a 100 ms sleep in now for a short 
term fix and the test now pass.

        onView(withId(R.id.face_amount)).perform(typeText(testFaceAmt), closeSoftKeyboard());

        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        onView(withId(R.id.calculate_button)).perform(click());

Original comment by brandonb...@gmail.com on 5 Dec 2013 at 5:36

GoogleCodeExporter commented 9 years ago
This is likely due to animations delaying the close of the soft keyboard. Our 
deployment instructions say:

To avoid flakiness, we highly recommend that you turn off system animations on 
the virtual or physical device(s) used for testing.

Please try that.

Original comment by vale...@google.com on 16 Dec 2013 at 6:12

GoogleCodeExporter commented 9 years ago
System animations were turned off. Bug happens regardless.

Original comment by jette.da...@gmail.com on 17 Dec 2013 at 2:18