I'm automating the testing of a flow in my app where I install a device administrator. To activate a device administrator on most devices (let's assume here I don't have some enterprise API that lets me do this like what Samsung offers) the system displays a popup to the user who then has to click the "Activate" button.
I'm using Robotium and Android JUnit to drive my tests. In a normal testing case one can only interact with the app and process under test and not any system activities that come up.
The UiAutomation claims to allow you to interact with other applications by leveraging the Accessibility Framework, and then allowing one to inject arbitrary input events.
So - here's what I'm trying to do:
public class AbcTests extends ActivityInstrumentationTestCase2<AbcActivity> {
private Solo mSolo
@Override
public void setUp() {
mSolo = new Solo(getInstrumentation(), getActivity());
}
...
public void testAbc(){
final UiAutomation automation = getInstrumentation().getUiAutomation();
MotionEvent motionDown = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN,
100, 100, 0);
automation.injectInputEvent(motionDown, true)
MotionEvent motionUp = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), KeyEvent.ACTION_UP,
100, 100, 0);
automation.injectInputEvent(motionUp, true)
motionUp.recycle();
motionDown.recycle();
}
}
When this test is run the System popup to "Activate" the device administrator is active, and I want to just click on the screen. I've hardcoded in 100,100 as the position for clicks for the purposes of this question but realistically I'll click in the bottom right corner of the screen so I can hit the button.
I do not get any click events occurring on the screen. Does anyone have experience with this? Are there any alternatives to do what I want to do? From my understanding there are very few tools that do this.
Thanks.
Update
Added setSource
for right answer