몽키 스크립트
구글 안드로이드 개발시 제공되어진 몽키라는 자동화 테스트 프로그램이 있습니다. 이는 반복적으로 이벤트를 랜덤하게 발생시켜 특정 앱이나 혹은 임의 앱을 자동으로 테스트 할 수 있게 해 주는 프로그램으로 스크립트 실행을 지원하고 있습니다.
스크립트를 이용한 테스트는 일련의 동작을 계속 반복 함으로써, 스트레스 테스트나 재현이 잘 되지 않는 테스트에 이용할 수 있습니다. 이를 잘 이용하면 턴 게임이나 특정 좌표를 옮겨야 하는 모바일 게임의 경우 오토마우스의 효과를 가지게 할 수 있습니다.
몽키 스크립트는 실행 방법에 따라 2가지로 나눌 수 있으며 사용법은 다음과 같습니다.
1. 스크립트 작성후 adb push를 이용하여 단말에 올린 후 단말에서 직접 실행하는 방법
▶ 소스 :
▶ 문법 :
count= number of events
speed= in ms
start data >>
DispatchPointer(long downTime, long eventTime, int action,
float x, float y, float pressure, float size, int metaState,
float xPrecision, float yPrecision, int device, int edgeFlags)
DispatchTrackball same as DispatchPointer
DispatchKey(long downTime, long eventTime, int action, int code,
int repeat, int metaState, int device, int scancode)
DispatchFlip(boolean keyboardOpen)
DispatchPress(int keyCode)
LaunchActivity(String pkg_name, String cl_name)
UserWait(long sleeptime)
LongPress()
▶ 예제 : example.txt
type= user
speed= 1000
start data >>
DispatchPointer(0, 0, 0, 1120, 736, 0,0,0,0,0,0,0)
DispatchPointer(0, 0, 1, 1120, 736, 0,0,0,0,0,0,0)
UserWait(1000)
▶ 실행 :
$adb push example.txt /sdcard/example.txt
$adb shell monkey -f /sdcard/example.txt 1(반복횟수)
2. 소켓 프로그램을 이용한 PC에서 간접 실행 할 수 있는 방법
▶ 개념 : Simple Protocol for Automated Network Control 을 이용하여, ADB위에 TCP를 이용하여 테스트 하는 방법으로, 이는 소켓 프로그램이 가능한 다른 언어로 다른 형태의 테스트 프로그램을 작성 가능하게 합니다.
SIMPLE PROTOCOL FOR AUTOMATED NETWORK CONTROL
The Simple Protocol for Automated Network Control was designed to be a low-level way to programmability inject KeyEvents and MotionEvents into the input system. The idea is that a process will run on a host computer that will support higher-level operations (like conditionals, etc.) and will talk (via TCP over ADB) to the device in Simple Protocol for Automated Network Control. For security reasons, the Monkey only binds to localhost, so you will need to use adb to setup port forwarding to actually talk to the device.
▶ 문법 : monkey 소스에 포함되어 있는 example_script.txt 를 보면 아래와 같습니다.
# Touch the android
touch down 160 200
touch up 160 200
sleep 1000
# Hit Next
touch down 300 450
touch up 300 450
sleep 1000
# Hit Next
touch down 300 450
touch up 300 450
sleep 1000
# Hit Next
touch down 300 450
touch up 300 450
sleep 1000
# Go down and select the account username
key down dpad_down
key up dpad_down
key down dpad_down
key up dpad_down
key down dpad_center
key up dpad_center
# account name: bill
key down b
key up b
key down i
key up i
key down l
key up l
key down l
key up l
# Go down to the password field
key down dpad_down
key up dpad_down
# password: bill
key down b
key up b
key down i
key up i
key down l
key up l
key down l
key up l
# Select next
touch down 300 450
touch up 300 450
# quit
quit
▶ 예제 : monkeyscript.py로 python으로 작성되어 있습니다.
#!/usr/bin/python
import socket
TCP_IP='127.0.0.1'
TCP_PORT = 1080
BUFFER_SIZE = 1024
MONKEY_COMMAND = \
'touch down 1120 736\ntouch up 1120 736\nsleep 1000\n' \
'touch down 568 293\ntouch up 568 293\nsleep 3000\n' \
\
'touch down 1230 400\ntouch up 1230 400\nsleep 2000\n' \
'touch down 50 730\ntouch up 50 730\nsleep 4000\n' \
'touch down 1000 400\ntouch up 1000 400\nsleep 100\n' \
'touch down 1255 32\ntouch up 1255 32\nsleep 2000\n' \
'touch down 780 460\ntouch up 780 460\nsleep 4000\n' \
\
'touch down 1230 400\ntouch up 1230 400\nsleep 2000\n' \
'touch down 50 730\ntouch up 50 730\nsleep 4000\n' \
'touch down 1000 400\ntouch up 1000 400\nsleep 100\n' \
'touch down 1255 32\ntouch up 1255 32\nsleep 2000\n' \
'touch down 780 460\ntouch up 780 460\nsleep 1000\n' \
\
'key down 3\nkey up 3\nsleep 2000\n'
for x in range(0, 1000):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
s.send(MONKEY_COMMAND)
data = s.recv(BUFFER_SIZE)
print "Test Count : ", x
print "Test Result : ", data
s.close()
▶ 실행 :
끝.
'프로그램 > 안드로이드' 카테고리의 다른 글
안드로이드 롤리팝 퀵 스타트 가이드 (0) | 2014.11.19 |
---|---|
SELinux 정책파일(.te) 사용법 (2) | 2014.11.14 |
안드로이드 킷캣과 롤리팝 버전 비교 및 모바일 운영체제 정리 (0) | 2014.11.11 |
abd shell command 백그라운드 실행 (0) | 2014.09.17 |
댓글