Created
December 4, 2014 09:18
-
-
Save elleryq/af9977c0ca91c8606bf5 to your computer and use it in GitHub Desktop.
MonkeyRunner script to send mail.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from com.android.monkeyrunner import MonkeyRunner | |
from com.android.monkeyrunner import MonkeyDevice | |
from com.android.monkeyrunner.easy import EasyMonkeyDevice,By | |
device=MonkeyRunner.waitForConnection(10) | |
if device: | |
print("Connect device successful!") | |
else: | |
print("Connect device failed!") | |
sys.exit(-1) | |
easyDevice = EasyMonkeyDevice(device) | |
# start Email | |
device.startActivity( | |
component="com.android.email/" | |
"com.android.email.activity.MessageCompose", | |
) | |
# Fill 'To' field and send. | |
MonkeyRunner.sleep(5) | |
easyDevice.type(By.id('id/to'), "someone@somewhere.com") | |
easyDevice.touch(By.id('id/send'), MonkeyDevice.DOWN_AND_UP) | |
easyDevice.type(By.id('id/subject'), "Hello") | |
# tricky, need to click body_text first, or input text will fail. | |
body_text = By.id('id/body_text') | |
easyDevice.touch(body_text, MonkeyDevice.DOWN) | |
easyDevice.touch(body_text, MonkeyDevice.UP) | |
MonkeyRunner.sleep(1.0) | |
easyDevice.type(By.id('id/body_text'), "Hi, this is a test mail.") | |
# Actually 'SEND' won't be triggered, this mail will save as draft. | |
# Because Email app disallow monkeyrunner. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment