Android monkey test choose a specific activity

前端 未结 4 2041
野的像风
野的像风 2020-12-30 13:45

I\'m using the Android monkey test to test my android apps, it\'s works for my app, and is very cool. but I\'d like to test an application activity in specific, how could i

4条回答
  •  -上瘾入骨i
    2020-12-30 14:36

    With Android monkey test i cannot test a specific activity, but with Android monkey runner i can do python scripts to simulate a monkey test, so i did a python script open the my activity and init the monkey test :)

    #! /usr/bin/env monkeyrunner
    
    from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
    from random import randint
    
    print "get device"
    device = MonkeyRunner.waitForConnection()
    package = 'my.packaget'
    activity = 'my.package.activity'
    runComponent = package + '/' + activity
    device.startActivity(component=runComponent)
    
    #use commands like device.touch and device.drag to simulate a navigation and open my activity
    
    #with your activity opened start your monkey test
    print "start monkey test"
    for i in range(1, 1000):
        #here i go emulate only simple touchs, but i can emulate swiper keyevents and more... :D
        device.touch(randint(0, 1000), randint(0, 800), 'DOWN_AND_UP')
    
    print "end monkey test"
    

    save teste.py and run

    $ monkeyrunner teste.py
    

提交回复
热议问题