Wednesday, March 5, 2014

MonkeyRunner简介(2)

如果是第三方app, Monkeyruuner 不能install这个package,所以必须用actual device进行测试


Decryption:
Now we decrypt the AndroidManifest.xml to get the package and main activity name
In CMD, execute:
apktool.jar d Pandora_apkfiles.com.apk ./Pandora

after decrypted, open the xml and search keyword: package and LAUNCHER and find the activity name=android:name
package: com.pandora.android
entry activity: .Main

Jython code:
Now we can put this into the Jython code
device.startActivity(component="com.pandora.android/.Main")


If the installation can't be done, you can ignore this statement:
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.startActivity(component="com.pandora.android/.Main")

If the connection is wrong or it might connects to emulator:
Run your custom android app and see where it launches

MonkeyRunner operations:
http://developer.android.com/tools/help/MonkeyDevice.html

Android key events:
http://developer.android.com/reference/android/view/KeyEvent.html

Final test:
This is to launch the installed Pandora and sign in with an existing user
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
device.startActivity(component="com.pandora.android/.Main")
MonkeyRunner.sleep(10)
device.type('aaa413@gmail.com')
MonkeyRunner.sleep(2)
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.type('111111')
MonkeyRunner.sleep(2)
device.press('KEYCODE_DPAD_DOWN','DOWN_AND_UP')
MonkeyRunner.sleep(2)
device.press("DPAD_CENTER", MonkeyDevice.DOWN_AND_UP)
MonkeyRunner.sleep(2)
result=device.takeSnapshot()
result.writeToFile('C:/Users/KK/Documents/Coding/Python/Test1_001.png','png')

关于MonkeyRunner的基本设置请参见MonkeyRunner简介(1)

No comments:

Post a Comment