Search code examples
androidandroid-testingcts

simulate the swipe event to make screen scroll in Android


The reason why I intend to do this because I want to do some tests on my Android device.

I remember that there are some ways to implement this:

  1. Write a python script which can simulate the swipe event. Left, right, up and down. All events and speed should be configurable. This way can be done via adb.

  2. Android unit test.

  3. Can CTS archive the tests that I am expecting to have?

Is my understanding correct?

Kindly give me further information.

Thanks in advance


Solution

  • You can use monkeyrunner with a python script: http://developer.android.com/tools/help/MonkeyDevice.html#drag

    This blog post might help you with using monkeyrunner (it allows for getViewById in the mr script): http://dtmilano.blogspot.com/2012/03/monkeyrunner-running-unit-tests.html

    You can use a ProcessBuilder in a JUnitTest to run monkeyrunner and test the output.

    Once you have it working in a JUnitTest, you should be able to use them with CTS.