3

Is there a way to save the random run of Android Monkey into a script with the proper format to later replay it by running:

adb shell monkey -p <package_name> -f script_file 1

EDIT:

I know there is a seed flag (-s), but that's not what I want. I have to be able to work with the generated script before feeding it back to the Monkey.

FlyingPumba
  • 1,015
  • 2
  • 15
  • 37
  • Note that the `-f` switch is undocumented. – CommonsWare Apr 19 '18 at 21:16
  • Yes, it seems a bit obscure. I'm looking at another question that seems related: https://stackoverflow.com/questions/46669486/reproduce-android-monkey-script/49930319#49930319 Somehow op there was able to make it, so there might be a way to do it. – FlyingPumba Apr 19 '18 at 21:19

2 Answers2

2

Not an easy way, but you could do a reverse engineering on the monkey script source to create a script that takes the output of the monkey command and generates the monkey script.

So you could run:

adb shell monkey -p <package_name> -v -v 1 > monkey-logs.txt

And then*:

convert-to-monkey-script.sh monkey-logs.txt

For example, one output of the monkey call:

Replaying 11 events with speed 1.0
:Sending Touch (ACTION_DOWN): 0:(450.0,450.0)
:Sending Touch (ACTION_UP): 0:(450.0,450.0)
Sleeping for 45 milliseconds
...

Becomes the following monkey script (read the monkey source to understand better the arguments):

type= raw events
count= 2
speed= 1.0
start data >>
DispatchPointer(6934862,6934862,0,450.0,450.0,0.0,0.0,0,1.0,1.0,0,0)
DispatchPointer(6934862,6934862,1,450.0,450.0,0.0,0.0,0,1.0,1.0,0,0)

Which can be run with (with the content above in the monkey.script file and after a adb push):

adb shell monkey -p <package_name> -f monkey.script 1

I've made a simple gist for myself that convert adb taps commands into monkey script format (because they're faster) here, so I think that is possible to make a general script for that.

*Note: convert-to-monkey-script.sh doesn't exist. As I said, someone COULD do it

Gabriel Rohden
  • 1,307
  • 9
  • 19
1

There is no option for saving script, but you can use seed that acts like a seed in random number generator so same seed leads to same events. Here is an example:

adb shell monkey -p com.package -s 123 500

This will run Monkey on package 'com.package' with seed value of '123' and produce 500 events.

jelic98
  • 723
  • 1
  • 12
  • 28