Skip to content

Commit 2762ebf

Browse files
committed
examples: updated browser-open-url.py
1 parent cb1909d commit 2762ebf

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

Lines changed: 17 additions & 17 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 Mar 13, 2012
@@ -12,37 +12,37 @@
1212
import os
1313
import string
1414

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-
2515
try:
2616
sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
2717
except:
2818
pass
2919

3020
from com.dtmilano.android.viewclient import ViewClient
31-
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
3221

22+
USE_BROWSER = True
3323
# 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'
3630
component = package + "/" + activity
3731
uri = 'http://dtmilano.blogspot.com'
3832

3933
device, serialno = ViewClient.connectToDeviceOrExit()
4034
device.startActivity(component=component, uri=uri)
41-
MonkeyRunner.sleep(3)
35+
ViewClient.sleep(5)
4236

4337
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:
4646
print "%s successfully loaded" % uri
4747
else:
4848
print "%s was not loaded, url=%s" % (uri, url)

0 commit comments

Comments
 (0)