Skip to content

Commit cb1909d

Browse files
committed
examples: updated apidemos-*
1 parent 1af91c9 commit cb1909d

2 files changed

Lines changed: 15 additions & 33 deletions

File tree

AndroidViewClient/examples/apidemos-app-alert_dialog-list_dialog-command_three.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env monkeyrunner
1+
#! /usr/bin/env python
22
'''
33
Copyright (C) 2012 Diego Torres Milano
44
Created on Sep 5, 2012
@@ -11,23 +11,12 @@
1111
import sys
1212
import os
1313

14-
# This must be imported before MonkeyRunner and MonkeyDevice,
15-
# otherwise the import fails.
16-
# PyDev sets PYTHONPATH, use it
17-
try:
18-
for p in os.environ['PYTHONPATH'].split(':'):
19-
if not p in sys.path:
20-
sys.path.append(p)
21-
except:
22-
pass
23-
2414
try:
2515
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
2616
except:
2717
pass
2818

2919
from com.dtmilano.android.viewclient import ViewClient, View
30-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
3120

3221
device, serialno = ViewClient.connectToDeviceOrExit()
3322

@@ -36,31 +25,31 @@
3625
componentName = 'com.example.android.apis/.ApiDemos'
3726
device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK)
3827

39-
MonkeyRunner.sleep(3)
28+
ViewClient.sleep(3)
4029
vc = ViewClient(device=device, serialno=serialno)
4130
app = vc.findViewWithText('App')
4231
if app:
4332
app.touch()
44-
MonkeyRunner.sleep(3)
33+
ViewClient.sleep(3)
4534
# windows changed, request a new dump
4635
vc.dump()
4736
ad = vc.findViewWithText('Alert Dialogs')
4837
if ad:
4938
ad.touch()
50-
MonkeyRunner.sleep(3)
39+
ViewClient.sleep(3)
5140
# windows changed, request a new dump
5241
vc.dump()
5342
ld = vc.findViewWithText('List dialog')
5443
if ld:
5544
ld.touch()
56-
MonkeyRunner.sleep(3)
45+
ViewClient.sleep(3)
5746
# windows changed, request a new dump
5847
vc.dump()
5948
c3 = vc.findViewWithText('Command three')
6049
if c3:
6150
c3.touch()
62-
MonkeyRunner.sleep(10)
63-
device.press('KEYCODE_BACK', MonkeyDevice.DOWN_AND_UP)
51+
ViewClient.sleep(10)
52+
device.press('KEYCODE_BACK')
6453
else:
6554
print >> sys.stderr, "Cannot find 'Command three'"
6655
else:
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env monkeyrunner
1+
#! /usr/bin/env python
22
'''
33
Copyright (C) 2012 Diego Torres Milano
44
Created on Sep 18, 2012
@@ -11,16 +11,6 @@
1111
import sys
1212
import os
1313

14-
# This must be imported before MonkeyRunner and MonkeyDevice,
15-
# otherwise the import fails.
16-
# PyDev sets PYTHONPATH, use it
17-
try:
18-
for p in os.environ['PYTHONPATH'].split(':'):
19-
if not p in sys.path:
20-
sys.path.append(p)
21-
except:
22-
pass
23-
2414
try:
2515
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
2616
except:
@@ -30,7 +20,6 @@
3020
if viewclient.__version__ < '1.0':
3121
print >> sys.stderr, "%s: This script requires viewclient 1.0 or greater." % os.path.basename(sys.argv[0])
3222
sys.exit(1)
33-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
3423

3524
device, serialno = viewclient.ViewClient.connectToDeviceOrExit()
3625

@@ -39,16 +28,20 @@
3928
componentName = 'com.example.android.apis/.ApiDemos'
4029
device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK)
4130

42-
MonkeyRunner.sleep(3)
31+
viewclient.ViewClient.sleep(3)
4332
vc = viewclient.ViewClient(device=device, serialno=serialno)
4433
vc.findViewWithTextOrRaise('Preference').touch()
4534
vc.dump()
4635
vc.findViewWithTextOrRaise(re.compile('.*Advanced preferences')).touch()
4736
vc.dump()
48-
value0 = vc.findViewByIdOrRaise('id/mypreference_widget').getText()
4937
myPreference = vc.findViewWithTextOrRaise('My preference')
38+
if vc.getSdkVersion() >= 16:
39+
_id = 'id/no_id/22'
40+
else:
41+
_id = 'id/mypreference_widget'
42+
value0 = vc.findViewByIdOrRaise(_id).getText()
5043
for i in range(10):
5144
myPreference.touch()
5245
vc.dump()
53-
value1 = vc.findViewByIdOrRaise('id/mypreference_widget').getText()
46+
value1 = vc.findViewByIdOrRaise(_id).getText()
5447
print "My preference started with value %s and is now %s" % (value0, value1)

0 commit comments

Comments
 (0)