|
1 | | -#! /usr/bin/env monkeyrunner |
| 1 | +#! /usr/bin/env python |
2 | 2 | ''' |
3 | 3 | Copyright (C) 2012 Diego Torres Milano |
4 | 4 | Created on Mar 13, 2012 |
|
12 | 12 | import os |
13 | 13 | import string |
14 | 14 |
|
15 | | -# This must be imported before MonkeyRunner and MonkeyDevice, |
16 | | -# otherwise the import fails. |
17 | | -# PyDev sets PYTHONPATH, use it |
18 | | -try: |
19 | | - for p in os.environ['PYTHONPATH'].split(':'): |
20 | | - if not p in sys.path: |
21 | | - sys.path.append(p) |
22 | | -except: |
23 | | - pass |
24 | | - |
25 | 15 | try: |
26 | 16 | sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src')) |
27 | 17 | except: |
28 | 18 | pass |
29 | 19 |
|
30 | 20 | from com.dtmilano.android.viewclient import ViewClient |
31 | | -from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice |
32 | 21 |
|
| 22 | +USE_BROWSER = True |
33 | 23 | # Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity } |
34 | | -package = 'com.android.browser' |
35 | | -activity = '.BrowserActivity' |
| 24 | +if USE_BROWSER: |
| 25 | + package = 'com.android.browser' |
| 26 | + activity = '.BrowserActivity' |
| 27 | +else: |
| 28 | + package = 'com.android.chrome' |
| 29 | + activity = 'com.google.android.apps.chrome.Main' |
36 | 30 | component = package + "/" + activity |
37 | 31 | uri = 'http://dtmilano.blogspot.com' |
38 | 32 |
|
39 | 33 | device, serialno = ViewClient.connectToDeviceOrExit() |
40 | 34 | device.startActivity(component=component, uri=uri) |
41 | | -MonkeyRunner.sleep(3) |
| 35 | +ViewClient.sleep(5) |
42 | 36 |
|
43 | 37 | vc = ViewClient(device, serialno) |
44 | | -url = vc.findViewByIdOrRaise("id/url").getText() |
45 | | -if string.find(url, uri) != -1: |
| 38 | +if vc.getSdkVersion() >= 16: |
| 39 | + if USE_BROWSER: |
| 40 | + url = vc.findViewByIdOrRaise("id/no_id/12").getText() |
| 41 | + else: |
| 42 | + url = vc.findViewWithContentDescription("Search or type url").getText() |
| 43 | +else: |
| 44 | + url = vc.findViewByIdOrRaise("id/url").getText() |
| 45 | +if string.find(uri, url) != -1: |
46 | 46 | print "%s successfully loaded" % uri |
47 | 47 | else: |
48 | 48 | print "%s was not loaded, url=%s" % (uri, url) |
0 commit comments