Issue
EDIT
After some debugging, I realised that the entire test was not running. However strangely, it worked a few times and when I tried it again, it failed to run. Under the progress tab, it was always stuck at "Launching: Creating source locator..." and the test was not executed.
I tried restarting eclipse but I could not get it to work.
I am a newbie to android testing and I want to generate touch events to test the pause and play of a video in an android app. I use the Android Testing Framework to select the video and play it, and the video starts running fine, but the touch event does not execute, nor does the test end. I tried debugging, but the touchlistener was never called when the tests ran. I am not sure why the code execution doesn't reach the MotionEvents part. Really would appreciate your help!
public class VideoPlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> {
private Activity activity;
private Fragment localvideosfragment;
private VideoPlayer videoplayer;
private ZoomState zoomstate;
private RenderView renderView;
public VideoPlaybackTest() {
super(MainActivity.class);
}
@Before
public void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(true);
activity = getActivity();
FragmentManager fragmentmanager = activity.getFragmentManager();
localvideosfragment = fragmentmanager.findFragmentById(R.id.frame_container);
}
@Test
public void testVideoSelection() {
activity.runOnUiThread(new Runnable() {
public void run() {
assertNotNull(localvideosfragment);
View rootView = (View) localvideosfragment.getView();
ListView videolist = (ListView) rootView.findViewById(R.id.list);
assertNotNull(videolist);
// Select video to play
videolist.performItemClick(videolist.getChildAt(0), 0, videolist.getChildAt(0).getId());
}
});
// Wait for VideoPlayer Activity to be started
ActivityMonitor monitor = getInstrumentation().addMonitor(VideoPlayer.class.getName(), null, false);
Instrumentation instrumentation = getInstrumentation();
instrumentation.waitForIdleSync();
// get the started video player Activity
videoplayer = (VideoPlayer) instrumentation.waitForMonitor(monitor);
assertNotNull(videoplayer);
// Get zoomstate and assert that video is playing
renderView = videoplayer.getRenderView();
assertNotNull(renderView);
zoomstate = renderView.getZoomState();
assertNotNull(zoomstate);
ROIState roistate = renderView.getROIState();
Boolean isPlaying = roistate.isPlaying;
assertTrue(zoomstate.isPlaying());
assertTrue(isPlaying);
// Obtain MotionEvent object
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
float x = 0.0f;
float y = 0.0f;
int metaState = 0;
MotionEvent motionEventup = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_UP,
x,
y,
metaState
);
MotionEvent motionEventdown = MotionEvent.obtain(
downTime,
eventTime,
MotionEvent.ACTION_DOWN,
x,
y,
metaState
);
renderView.dispatchTouchEvent(motionEventdown);
renderView.dispatchTouchEvent(motionEventup);
roistate = renderView.getROIState();
isPlaying = roistate.isPlaying;
zoomstate = renderView.getZoomState();
Boolean state = zoomstate.isPlaying();
assertFalse(state);
assertFalse(isPlaying);
}
}
Solution
Okay I found a way to make it work. I had uninstall the existing app from the device, and start afresh. The tests ran fine after that.
Answered By - miazima
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.