-
Notifications
You must be signed in to change notification settings - Fork 347
/
Copy pathmonkeyrunner-issue-36544-workaround.py
executable file
·93 lines (81 loc) · 2.78 KB
/
monkeyrunner-issue-36544-workaround.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! /usr/bin/env python
'''
Copyright (C) 2012 Diego Torres Milano
Created on Sep 8, 2012
@author: diego
@see: http://code.google.com/p/android/issues/detail?id=36544
'''
import re
import sys
import os
# This must be imported before MonkeyRunner and MonkeyDevice,
# otherwise the import fails.
# PyDev sets PYTHONPATH, use it
try:
for p in os.environ['PYTHONPATH'].split(':'):
if not p in sys.path:
sys.path.append(p)
except:
pass
try:
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
pass
from com.dtmilano.android.viewclient import ViewClient, View
device, serialno = ViewClient.connectToDeviceOrExit()
FLAG_ACTIVITY_NEW_TASK = 0x10000000
# We are not using Settings as the bug describes because there's no WiFi dialog in emulator
#componentName = 'com.android.settings/.Settings'
componentName = 'com.dtmilano.android.sampleui/.MainActivity'
device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK)
ViewClient.sleep(3)
# Set it to True or False to decide if AndroidViewClient or plain monkeyrunner is used
USE_AVC = True
if USE_AVC:
# AndroidViewClient
vc = ViewClient(device=device, serialno=serialno)
showDialogButton = vc.findViewById('id/show_dialog_button')
if showDialogButton:
showDialogButton.touch()
vc.dump()
vc.findViewById('id/0x123456').type('Donald')
ok = vc.findViewWithText('OK')
if ok:
# 09-08 20:17:47.860: D/MonkeyStub(2033): translateCommand: tap 265 518
ok.touch()
vc.dump()
hello = vc.findViewById('id/hello')
if hello:
if hello.getText() == "Hello Donald":
print "OK"
else:
print "FAIL"
else:
print >> sys.stderr, "'hello' not found"
else:
print >> sys.stderr, "'Show Dialog' button not found"
else:
# MonkeyRunner
from com.android.monkeyrunner.easy import EasyMonkeyDevice
from com.android.monkeyrunner.easy import By
easyDevice = EasyMonkeyDevice(device)
showDialogButton = By.id('id/show_dialog_button')
if showDialogButton:
easyDevice.touch(showDialogButton, MonkeyDevice.DOWN_AND_UP)
ViewClient.sleep(3)
editText = By.id('id/0x123456')
print editText
easyDevice.type(editText, 'Donald')
ViewClient.sleep(3)
ok = By.id('id/button1')
if ok:
# 09-08 20:16:41.119: D/MonkeyStub(1992): translateCommand: tap 348 268
easyDevice.touch(ok, MonkeyDevice.DOWN_AND_UP)
hello = By.id('id/hello')
if hello:
if easyDevice.getText(hello) == "Hello Donald":
print "OK"
else:
print "FAIL"
else:
print >> sys.stderr, "'hello' not found"