Skip to content

Commit 3bda500

Browse files
committed
Updated examples
1 parent d8a5845 commit 3bda500

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

AndroidViewClient/examples/check-import.py

Lines changed: 1 addition & 3 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
Created on Aug 29, 2012
44
@@ -45,5 +45,3 @@
4545
import com.dtmilano.android.viewclient
4646
from com.dtmilano.android.viewclient import ViewClient, View
4747
print "OK"
48-
49-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

AndroidViewClient/examples/dump.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /usr/bin/env monkeyrunner
1+
#! /usr/bin/env python
22

33
print '''
44
Notice:

AndroidViewClient/examples/temperature-converter-get-conversion.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
#! /usr/bin/env monkeyrunner
1+
#! /usr/bin/env python
22
'''
33
Copyright (C) 2012 Diego Torres Milano
44
Created on Feb 3, 2012
55
66
This example starts the TemperatureConverter activity then type '123' into the 'Celsius' field.
77
Then a ViewClient is created to obtain the view dump and the current values of the views with
8-
id/celsius and id/fahrenheith are obtained and the conversion printed to stdout.
8+
id/celsius and id/fahrenheit are obtained and the conversion printed to stdout.
99
Finally, the fields are obtained by using their tags and again, conversion printed to stdout.
10-
10+
11+
If --localViewServer is passed in the command line then LocalViewServer provided by
12+
TemperatureConverter is used. This is very useful when the device is secure and ViewServer
13+
cannot be started.
14+
1115
@author: diego
1216
'''
1317

1418

1519
import re
1620
import sys
1721
import os
22+
import time
1823

19-
# This must be imported before MonkeyRunner and MonkeyDevice,
20-
# otherwise the import fails.
2124
# PyDev sets PYTHONPATH, use it
2225
try:
2326
for p in os.environ['PYTHONPATH'].split(':'):
@@ -33,8 +36,6 @@
3336

3437
from com.dtmilano.android.viewclient import ViewClient
3538

36-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
37-
3839
localViewServer = False
3940
if len(sys.argv) > 1 and sys.argv[1] == '--localViewServer':
4041
localViewServer = True
@@ -48,17 +49,22 @@
4849
componentName = package + "/" + activity
4950

5051
device.startActivity(component=componentName, flags=FLAG_ACTIVITY_NEW_TASK)
51-
MonkeyRunner.sleep(5)
52+
time.sleep(5)
5253

5354

5455
device.type("123")
55-
MonkeyRunner.sleep(3)
56+
time.sleep(3)
5657

5758
vc = ViewClient(device, serialno, startviewserver=(not localViewServer))
5859

59-
# obtain the views by id
60-
celsius = vc.findViewByIdOrRaise("id/celsius")
61-
fahrenheit = vc.findViewByIdOrRaise("id/fahrenheit")
60+
if vc.build['ro.build.version.sdk'] >= 16:
61+
# obtain the views by contentDescription
62+
celsius = vc.findViewWithContentDescriptionOrRaise("celsius")
63+
fahrenheit = vc.findViewWithContentDescriptionOrRaise("fahrenheit")
64+
else:
65+
# obtain the views by id
66+
celsius = vc.findViewByIdOrRaise("id/celsius")
67+
fahrenheit = vc.findViewByIdOrRaise("id/fahrenheit")
6268

6369
ct = celsius.getText()
6470
if ct:

0 commit comments

Comments
 (0)