Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test swipe/fling event using jUnit in Android testcase

I find that in android.test.TouchUtils there is a drag method, I try it, but onfling() seems not react to this action. I also try robotium's scrollToSide(int), not working either. Any suggestions that how I can achieve this in my test case?

like image 305
Wei Yang Avatar asked Dec 06 '25 13:12

Wei Yang


2 Answers

drag(float fromX, float toX, float fromY, float toY, int stepCount) in Robotium does work too, where as swipe and scrollToSide don't seem to work.

Using android.support.v4.view.ViewPager, following code works for me:

solo.drag(300,0,100,100,1);
like image 115
Chris Avatar answered Dec 08 '25 03:12

Chris


I believe you could use MotionEvent class and it's obtain() method to simulate all kinds of swipe/touch gestures. Here's the first tutorial I found on this, it should get you started: http://softteco.blogspot.com/2011/02/touch-hold-swipe-release-gesture.html

like image 29
Anton Cherkashyn Avatar answered Dec 08 '25 04:12

Anton Cherkashyn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!