Search code examples
androidandroid-cameramonkeyrunner

How to set the specific android monkey test?


I want to do the frequent operations about the the camera. The frequent operations are consist of launching camera -> taking picture -> doing onBackPressed -> launching camera -> ...

Is there a way to do this ?


Solution

  • This is an interesting example to demonstrate the use of AndroidViewClient/culebra and how they can simplify such a task.

    Run (using the long options to be self-explanatory):

    culebra --start-activity=com.google.android.gallery3d/com.android.camera.Camera \
        --verbose --verbose-comments \
        --find-views-with-content-description=on \
        --output myscript.py
    

    Once culebra finishes, myscript.py contains the autogenerated script. This script will start Camera and try to find all the Views. One of these Views is the shutter button, the one we would like to touch to take a picture. It's something like

    # class=android.widget.ImageView
    no_id29 = vc.findViewWithContentDescriptionOrRaise('Shutter button')
    

    Edit the autogenerated script and add at the end (your Camera application may be different, just check the generated script to see if your values are the same as mine)

    no_id29.touch()                                # take the picture
    vc.sleep(3)                                    # wait a bit
    device.press('BACK', MonkeyDevice.DOWN_AND_UP) # exit
    

    Save it.

    That's it!, run myscript.py and all the steps will be done. You can add a loop inside the script if you want to repeat it many times or even run myscript.py inside a loop in the shell.