Ejemplo n.º 1
0
    def test_LaunchBrowser(self):
            print("Back to home")
            self.device.press('KEYCODE_BACK')
            self.device.press('KEYCODE_HOME')
            self.device.press('KEYCODE_HOME')
            self.device.press('KEYCODE_BACK')
            VPS = "javascript:alert(document.getElementsByTagName('html')[0].innerHTML);"
            USE_BROWSER = False
            if USE_BROWSER:
                package = 'com.android.browser'
                activity = '.BrowserActivity'
                _id = 'id/no_id/12'
            else:
                package = 'com.android.chrome'
                activity = 'com.google.android.apps.chrome.Main'
                _id = 'id/no_id/28'
            component = package + "/" + activity
            uri = 'http://dtmilano.blogspot.com'


            print("Open Browser")
            self.device.startActivity(component=component, uri=uri)
            print("Waite for 5 sec")
            ViewClient.sleep(5)

            vc = ViewClient(device=self.device, serialno=self.serialno)
            sdkVersion = vc.getSdkVersion()
            print("Get SDK Version:"+str(sdkVersion))

            if sdkVersion > 10:
                print("Show search bar")
                self.device.drag((240, 180), (240, 420), 1, 20)
            else:
                for i in range(10):
                    self.device.press('KEYCODE_DPAD_UP')
                    ViewClient.sleep(1)
            print("Delete search bar")
            self.device.press('KEYCODE_DEL')
            ViewClient.sleep(1)

            print("Input JS and go")
            self.device.type(VPS)
            ViewClient.sleep(1)
            self.device.press('KEYCODE_ENTER')
            ViewClient.sleep(3)
            print("dump ViewClient data")
            vc.dump()
            print vc.findViewByIdOrRaise('com.android.chrome:id/js_modal_dialog_message' if sdkVersion >= 16 else 'id/message').getText().replace('\\n', "\n")
            self.device.press('KEYCODE_BACK' if sdkVersion > 10 else 'KEYCODE_ENTER')
            ViewClient.sleep(1)
    _id = 'id/no_id/12'
else:
    package = 'com.android.chrome'
    activity = 'com.google.android.apps.chrome.Main'
    _id = 'id/no_id/28'
component = package + "/" + activity
uri = 'http://dtmilano.blogspot.com'
                   

device, serialno = ViewClient.connectToDeviceOrExit()

device.startActivity(component=component, uri=uri)
ViewClient.sleep(5)

vc = ViewClient(device=device, serialno=serialno)
sdkVersion = vc.getSdkVersion()

if sdkVersion > 10:
    device.drag((240, 180), (240, 420), 1, 20)
else:
    for i in range(10):
        device.press('KEYCODE_DPAD_UP')
        ViewClient.sleep(1)

vc.findViewByIdOrRaise(_id if sdkVersion >= 16 else 'id/url' if sdkVersion > 10 else 'id/title').touch()
ViewClient.sleep(1)

device.press('KEYCODE_DEL')
device.type(VPS)
ViewClient.sleep(1)
device.press('KEYCODE_ENTER')
    activity = '.BrowserActivity'
    _id = 'id/no_id/12'
else:
    package = 'com.android.chrome'
    activity = 'com.google.android.apps.chrome.Main'
    _id = 'id/no_id/28'
component = package + "/" + activity
uri = 'http://dtmilano.blogspot.com'

device, serialno = ViewClient.connectToDeviceOrExit()

device.startActivity(component=component, uri=uri)
ViewClient.sleep(5)

vc = ViewClient(device=device, serialno=serialno)
sdkVersion = vc.getSdkVersion()

if sdkVersion > 10:
    device.drag((240, 180), (240, 420), 1, 20)
else:
    for i in range(10):
        device.press('KEYCODE_DPAD_UP')
        ViewClient.sleep(1)

vc.findViewByIdOrRaise(_id if sdkVersion >= 16 else
                       'id/url' if sdkVersion > 10 else 'id/title').touch()
ViewClient.sleep(1)

device.press('KEYCODE_DEL')
device.type(VPS)
ViewClient.sleep(1)
from com.dtmilano.android.viewclient import ViewClient

USE_BROWSER = True
# Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity }
if USE_BROWSER:
    package = 'com.android.browser'
    activity = '.BrowserActivity'
else:
    package = 'com.android.chrome'
    activity = 'com.google.android.apps.chrome.Main'
component = package + "/" + activity
uri = 'http://dtmilano.blogspot.com'

device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component, uri=uri)
ViewClient.sleep(5)

vc = ViewClient(device, serialno)
if vc.getSdkVersion() >= 16:
    if USE_BROWSER:
        url = vc.findViewByIdOrRaise("id/no_id/12").getText()
    else:
        url = vc.findViewWithContentDescription("Search or type url").getText()
else:
    url = vc.findViewByIdOrRaise("id/url").getText()
if string.find(uri, url) != -1:
    print "%s successfully loaded" % uri
else:
    print "%s was not loaded, url=%s" % (uri, url)
Ejemplo n.º 5
0
from com.dtmilano.android.viewclient import ViewClient

USE_BROWSER = True
# Starting: Intent { act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.browser/.BrowserActivity }
if USE_BROWSER:
    package = 'com.android.browser'
    activity = '.BrowserActivity'
else:
    package = 'com.android.chrome'
    activity = 'com.google.android.apps.chrome.Main'
component = package + "/" + activity
uri = 'http://dtmilano.blogspot.com'

device, serialno = ViewClient.connectToDeviceOrExit()
device.startActivity(component=component, uri=uri)
ViewClient.sleep(5)

vc = ViewClient(device, serialno)
if vc.getSdkVersion() >= 16:
    if USE_BROWSER:
        url = vc.findViewByIdOrRaise("id/no_id/12").getText()
    else:
        url = vc.findViewWithContentDescription("Search or type url").getText()
else:
    url = vc.findViewByIdOrRaise("id/url").getText()
if string.find(uri, url) != -1:
    print "%s successfully loaded" % uri
else:
    print "%s was not loaded, url=%s" % (uri, url)