mocks.MockDevice

Here are the examples of the python api mocks.MockDevice taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

56 Examples 7

Example 1

View license
    def testTextPropertyForDifferentSdkVersions_device(self):
        VP = { -1:TEXT_PROPERTY, 8:TEXT_PROPERTY_API_10, 10:TEXT_PROPERTY_API_10, 15:TEXT_PROPERTY, 16:TEXT_PROPERTY_UI_AUTOMATOR, 17:TEXT_PROPERTY_UI_AUTOMATOR}
        for version, textProperty in VP.items():
            device = MockDevice(version=version)
            view = View(None, device, -1)
            self.assertEqual(textProperty, view.textProperty, msg='version %d' % version)

Example 2

View license
    def testLeftPropertyForDifferentSdkVersions_device(self):
        VP = { -1:LEFT_PROPERTY, 8:LEFT_PROPERTY_API_8, 10:LEFT_PROPERTY, 15:LEFT_PROPERTY, 16:LEFT_PROPERTY, 17:LEFT_PROPERTY}
        for version, leftProperty in VP.items():
            device = MockDevice(version=version)
            view = View(None, device, -1)
            self.assertEqual(leftProperty, view.leftProperty, msg='version %d' % version)

Example 3

View license
    def testTopPropertyForDifferentSdkVersions_device(self):
        VP = { -1:TOP_PROPERTY, 8:TOP_PROPERTY_API_8, 10:TOP_PROPERTY, 15:TOP_PROPERTY, 16:TOP_PROPERTY, 17:TOP_PROPERTY}
        for version, topProperty in VP.items():
            device = MockDevice(version=version)
            view = View(None, device, -1)
            self.assertEqual(topProperty, view.topProperty, msg='version %d' % version)

Example 4

View license
    def testWidthPropertyForDifferentSdkVersions_device(self):
        VP = { -1:WIDTH_PROPERTY, 8:WIDTH_PROPERTY_API_8, 10:WIDTH_PROPERTY, 15:WIDTH_PROPERTY, 16:WIDTH_PROPERTY, 17:WIDTH_PROPERTY}
        for version, widthProperty in VP.items():
            device = MockDevice(version=version)
            view = View(None, device, -1)
            self.assertEqual(widthProperty, view.widthProperty, msg='version %d' % version)

Example 5

View license
    def testHeightPropertyForDifferentSdkVersions_device(self):
        VP = { -1:HEIGHT_PROPERTY, 8:HEIGHT_PROPERTY_API_8, 10:HEIGHT_PROPERTY, 15:HEIGHT_PROPERTY, 16:HEIGHT_PROPERTY, 17:HEIGHT_PROPERTY}
        for version, heightProperty in VP.items():
            device = MockDevice(version=version)
            view = View(None, device, -1)
            self.assertEqual(heightProperty, view.heightProperty, msg='version %d' % version)

Example 6

View license
    def testContainsPoint_api15(self):
        v = View(VIEW_MAP, MockDevice(), 15)
        (X, Y, W, H) = v.getPositionAndSize()
        self.assertEqual(X, v.getX())
        self.assertEqual(Y, v.getY())
        self.assertEqual(W, v.getWidth())
        self.assertEqual(H, v.getHeight())
        self.assertTrue(v.containsPoint((v.getCenter())))

Example 7

View license
    def testContainsPoint_api17(self):
        v = View(VIEW_MAP_API_17, MockDevice(), 17)
        (X, Y, W, H) = v.getPositionAndSize()
        self.assertEqual(X, v.getX())
        self.assertEqual(Y, v.getY())
        self.assertEqual(W, v.getWidth())
        self.assertEqual(H, v.getHeight())
        self.assertTrue(v.containsPoint((v.getCenter())))

Example 8

View license
    def testInit_adbNone(self):
        # FIXME: there's a problem here when the mock device is created,
        # it's intended to be API=15, mock ViewServer is started and then
        # adb tries (unsuccessfuly) to forward the ports (expected because
        # adb does not know anything about mock devices).
        # Then
        #    error: device not found
        # appears in the console
        device = MockDevice()
        try:
            vc = ViewClient(device, device.serialno, adb=None, autodump=False)
            self.assertIsNotNone(vc)
        except subprocess.CalledProcessError:
            # This is needed because the ports cannot be forwarded if there is no device connected
            pass

Example 9

View license
    def testMapSerialNo_regex(self):
        # This is an edge case. A regex should not be used as the serialno in ViewClient as it's
        # behavior is not well defined.
        # MonkeyRunner.waitForConnection() accepts a regexp as serialno but adb -s doesn't
        try:
            ViewClient(MockDevice(),  serialno='.*', adb=TRUE, autodump=False)
            self.fail()
        except ValueError:
            pass

Example 10

View license
    def testMapSerialNo_None(self):
        device = MockDevice()
        try:
            ViewClient(device, None, adb=TRUE, autodump=False)
            self.fail()
        except ValueError:
            pass

Example 11

View license
    def __mockTree(self, dump=DUMP, version=15, language='en'):
        device = MockDevice(version=version, language=language)
        vc = ViewClient(device, serialno=device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        if version <= 15:
            # We don't want to invoke the ViewServer or MockViewServer for this
            vc.setViews(dump)
        else:
            vc.dump()
        return vc

Example 12

View license
    def __mockWindows(self, windows=WINDOWS):
        device = MockDevice()
        vc = ViewClient(device, serialno=device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.windows = windows
        return vc

Example 13

View license
    def testServiceStoppedAfterDestructor(self):
        device = MockDevice()
        self.assertTrue(device.service == STOPPED)
        if True:
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            self.assertTrue(device.service == RUNNING)
            vc.__del__()

Example 14

View license
    def testUiAutomatorKilled(self):
        device = MockDevice(version=16, uiautomatorkilled=True)
        try:
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=True, ignoreuiautomatorkilled=True)
        except Exception, e:
            self.assertIsNotNone(re.search('''ERROR: UiAutomator output contains no valid information. UiAutomator was killed, no reason given.''', str(e)))

Example 15

View license
    def testUiViewServerDump(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            vc.dump()
            vc.findViewByIdOrRaise('id/home')
        finally:
            if device:
                device.shutdownMockViewServer()

Example 16

View license
    def testUiViewServerDump_windowStr(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            vc.dump(window='StatusBar')
            vc.findViewByIdOrRaise('id/status_bar')
        finally:
            if device:
                device.shutdownMockViewServer()

Example 17

View license
    def testUiViewServerDump_windowInt(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            vc.dump(window=0xb52f7c88)
            vc.findViewByIdOrRaise('id/status_bar')
        finally:
            if device:
                device.shutdownMockViewServer()

Example 18

View license
    def testUiViewServerDump_windowIntStr(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            vc.dump(window='0xb52f7c88')
            vc.findViewByIdOrRaise('id/status_bar')
        finally:
            if device:
                device.shutdownMockViewServer()

Example 19

View license
    def testUiViewServerDump_windowIntM1(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
            vc.dump(window=-1)
            vc.findViewByIdOrRaise('id/home')
        finally:
            if device:
                device.shutdownMockViewServer()

Example 20

View license
    def testFindViewsContainingPoint_api15(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE)
            list = vc.findViewsContainingPoint((200, 200))
            self.assertNotEquals(None, list)
            self.assertNotEquals(0, len(list))
        finally:
            if device:
                device.shutdownMockViewServer()

Example 21

View license
    def testFindViewsContainingPoint_api17(self):
        device = MockDevice(version=17)
        vc = ViewClient(device, device.serialno, adb=TRUE)
        list = vc.findViewsContainingPoint((55, 75))
        self.assertNotEquals(None, list)
        self.assertNotEquals(0, len(list))

Example 22

View license
    def testFindViewsContainingPoint_filterApi15(self):
        device = None
        try:
            device = MockDevice(version=15, startviewserver=True)
            vc = ViewClient(device, device.serialno, adb=TRUE)
            list = vc.findViewsContainingPoint((200, 200), _filter=View.isClickable)
            self.assertNotEquals(None, list)
            self.assertNotEquals(0, len(list))
        finally:
            if device:
                device.shutdownMockViewServer()

Example 23

View license
    def testFindViewsContainingPoint_filterApi17(self):
        device = MockDevice(version=17)
        vc = ViewClient(device, device.serialno, adb=TRUE)
        list = vc.findViewsContainingPoint((55, 75), _filter=View.isClickable)
        self.assertNotEquals(None, list)
        self.assertNotEquals(0, len(list))

Example 24

View license
    @unittest.skip("icannot connect adb to mock device")
    def testInit_adbNone(self):
        device = MockDevice()
        vc = ViewClient(device, serialno=device.serialno, adb=None, autodump=False)
        self.assertNotEqual(None, vc)

Example 25

View license
    def testView_notSpecifiedSdkVersion(self):
        device = MockDevice()
        view = View(VIEW_MAP, device, -1)
        self.assertEqual(device.version, view.build[VERSION_SDK_PROPERTY])

Example 26

View license
    def testView_specifiedSdkVersion_8(self):
        view = View(VIEW_MAP_API_8, MockDevice(), 8)
        self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])

Example 27

View license
    def testView_specifiedSdkVersion_10(self):
        view = View(VIEW_MAP, MockDevice(), 10)
        self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])

Example 28

View license
    def testView_specifiedSdkVersion_16(self):
        view = View(VIEW_MAP, MockDevice(), 16)
        self.assertEqual(16, view.build[VERSION_SDK_PROPERTY])

Example 29

View license
    def testGetX_specifiedSdkVersion_8(self):
        view = View(VIEW_MAP_API_8, MockDevice(), 8)
        self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])
        self.assertEqual(50, view.getX())

Example 30

View license
    def testGetX_specifiedSdkVersion_10(self):
        view = View(VIEW_MAP, MockDevice(), 10)
        self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])
        self.assertEqual(50, view.getX())

Example 31

View license
    def testGetY_specifiedSdkVersion_8(self):
        view = View(VIEW_MAP_API_8, MockDevice(), 8)
        self.assertEqual(8, view.build[VERSION_SDK_PROPERTY])
        self.assertEqual(316, view.getY())

Example 32

View license
    def testGetY_specifiedSdkVersion_10(self):
        view = View(VIEW_MAP, MockDevice(), 10)
        self.assertEqual(10, view.build[VERSION_SDK_PROPERTY])
        self.assertEqual(316, view.getY())

Example 33

View license
    def testIsClickable_api15(self):
        v = View(VIEW_MAP, MockDevice(), 15)
        self.assertTrue(v.isClickable())

Example 34

View license
    def testIsClickable_api17(self):
        v = View(VIEW_MAP_API_17, MockDevice(), 17)
        self.assertTrue(v.isClickable())

Example 35

View license
    def testInit_adb(self):
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEqual(None, vc)

Example 36

View license
    def testConstructor(self):
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)

Example 37

View license
    def testMapSerialNo_noPortSpecified(self):
        vc = ViewClient(MockDevice(), serialno='192.168.1.100', adb=TRUE, autodump=False)
        self.assertEqual('192.168.1.100:5555', vc.serialno)

Example 38

View license
    def testMapSerialNo_portSpecified(self):
        vc = ViewClient(MockDevice(), serialno='192.168.1.100:5555', adb=TRUE, autodump=False)
        self.assertEqual('192.168.1.100:5555', vc.serialno)

Example 39

View license
    def testMapSerialNo_emulator(self):
        vc = ViewClient(MockDevice(), serialno='emulator-5556', adb=TRUE, autodump=False)
        self.assertEqual('emulator-5556', vc.serialno)

Example 40

View license
    def testGetProperty_displayWidth(self):
        device = MockDevice()
        self.assertEqual(768, device.getProperty('display.width'))

Example 41

View license
    def testGetProperty_displayHeight(self):
        device = MockDevice()
        self.assertEqual(1184, device.getProperty('display.height'))

Example 42

View license
    def testTraverseShowClassIdAndText(self):
        device = MockDevice()
        root = View({'text:mText':'0', 'class': 'android.widget.View', 'mID': 0}, device)
        root.add(View({'text:mText':'1', 'class': 'android.widget.View', 'mID': 1}, device))
        root.add(View({'text:mText':'2', 'class': 'android.widget.View', 'mID': 2}, device))
        v3 = View({'text:mText':'3', 'class': 'android.widget.View', 'mID':3}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35', 'class': 'android.widget.View', 'mID': 35}, device)
        v3.add(v35)
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        treeStr = StringIO.StringIO()
        vc.traverse(root=root, transform=ViewClient.TRAVERSE_CIT, stream=treeStr)
        self.assertNotEquals(None, treeStr.getvalue())
        lines = treeStr.getvalue().splitlines()
        self.assertEqual(5, len(lines), "lines=%s" % lines)
        self.assertEqual('android.widget.View 0 0', lines[0])
        citRE = re.compile(' +android.widget.View \d+ \d+')
        for l in lines[1:]:
            self.assertTrue(citRE.match(l), 'l=%s' % l)

Example 43

View license
    def testTraverseShowClassIdTextAndCenter(self):
        device = MockDevice()
        root = View({'mID':'0', 'text:mText':'0', 'layout:mLeft':0, 'layout:mTop':0}, device)
        root.add(View({'mID':'1', 'text:mText':'1', 'layout:mLeft':1, 'layout:mTop':1}, device))
        root.add(View({'mID':'2', 'text:mText':'2', 'layout:mLeft':2, 'layout:mTop':2}, device))
        v3 = View({'mID':'3', 'text:mText':'3', 'layout:mLeft':3, 'layout:mTop':3}, device)
        root.add(v3)
        v35 = View({'mID':'5', 'text:mText':'5', 'getTag()':'v35', 'layout:mLeft':5, 'layout:mTop':5}, device)
        v3.add(v35)
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        treeStr = StringIO.StringIO()
        vc.traverse(root=root, transform=ViewClient.TRAVERSE_CITC, stream=treeStr)
        self.assertNotEquals(None, treeStr.getvalue())
        lines = treeStr.getvalue().splitlines()
        self.assertEqual(5, len(lines))
        self.assertEqual('None 0 0 (0, 0)', lines[0])
        citRE = re.compile(' +None \d+ \d+ \(\d+, \d+\)')
        for l in lines[1:]:
            self.assertTrue(citRE.match(l))

Example 44

View license
    def testFindViewById_root(self):
        device = None
        root = View({'mID':'0'}, device)
        root.add(View({'mID':'1'}, device))
        root.add(View({'mID':'2'}, device))
        v3 = View({'mID':'3'}, device)
        root.add(v3)
        v35 = View({'mID':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'mID':'4'}, device)
        root.add(v4)
        v45 = View({'mID':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewById('5')
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewById('5', root=v4)
        self.assertNotEqual(v5, None)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewById('5', root=v3)
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())

Example 45

View license
    def testFindViewByIdOrRaise_root(self):
        device = None
        root = View({'mID':'0'}, device)
        root.add(View({'mID':'1'}, device))
        root.add(View({'mID':'2'}, device))
        v3 = View({'mID':'3'}, device)
        root.add(v3)
        v35 = View({'mID':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'mID':'4'}, device)
        root.add(v4)
        v45 = View({'mID':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewByIdOrRaise('5')
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewByIdOrRaise('5', root=v4)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewByIdOrRaise('5', root=v3)
        self.assertEqual('v35', v5.getTag())

Example 46

View license
    def testFindViewWithText_root(self):
        device = None
        root = View({'text:mText':'0'}, device)
        root.add(View({'text:mText':'1'}, device))
        root.add(View({'text:mText':'2'}, device))
        v3 = View({'text:mText':'3'}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'text:mText':'4'}, device)
        root.add(v4)
        v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewWithText('5')
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewWithText('5', root=v4)
        self.assertNotEqual(v5, None)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewWithText('5', root=v3)
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())

Example 47

View license
    def testFindViewWithText_regexRoot(self):
        device = None
        root = View({'text:mText':'0'}, device)
        root.add(View({'text:mText':'1'}, device))
        root.add(View({'text:mText':'2'}, device))
        v3 = View({'text:mText':'3'}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'text:mText':'4'}, device)
        root.add(v4)
        v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewWithText(re.compile('[5]'))
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewWithText(re.compile('[5]'), root=v4)
        self.assertNotEqual(v5, None)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewWithText(re.compile('[5]'), root=v3)
        self.assertNotEqual(v5, None)
        self.assertEqual('v35', v5.getTag())

Example 48

View license
    def testFindViewWithTextOrRaise_root(self):
        device = None
        root = View({'text:mText':'0'}, device)
        root.add(View({'text:mText':'1'}, device))
        root.add(View({'text:mText':'2'}, device))
        v3 = View({'text:mText':'3'}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'text:mText':'4'}, device)
        root.add(v4)
        v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewWithTextOrRaise('5')
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewWithTextOrRaise('5', root=v4)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewWithTextOrRaise('5', root=v3)
        self.assertEqual('v35', v5.getTag())

Example 49

View license
    def testFindViewWithTextOrRaise_root_disappearingView(self):
        device = None
        root = View({'text:mText':'0'}, device)
        root.add(View({'text:mText':'1'}, device))
        root.add(View({'text:mText':'2'}, device))
        v3 = View({'text:mText':'3'}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'text:mText':'4'}, device)
        root.add(v4)
        v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        v5 = vc.findViewWithTextOrRaise('5')
        self.assertEqual('v35', v5.getTag())
        v5 = vc.findViewWithTextOrRaise('5', root=v4)
        self.assertEqual('v45', v5.getTag())
        v5 = vc.findViewWithTextOrRaise('5', root=v3)
        self.assertEqual('v35', v5.getTag())
        # Then remove v4 and its children
        root.children.remove(v4)
        #vc.dump()
        v4 = vc.findViewWithText('4')
        self.assertEqual(v4, None, "v4 has not disappeared")

Example 50

View license
    def testFindViewWithTextOrRaise_rootNonExistent(self):
        device = None
        root = View({'text:mText':'0'}, device)
        root.add(View({'text:mText':'1'}, device))
        root.add(View({'text:mText':'2'}, device))
        v3 = View({'text:mText':'3'}, device)
        root.add(v3)
        v35 = View({'text:mText':'5', 'getTag()':'v35'}, device)
        v3.add(v35)
        v4 = View({'text:mText':'4'}, device)
        root.add(v4)
        v45 = View({'text:mText':'5', 'getTag()':'v45'}, device)
        v4.add(v45)
        device = MockDevice()
        vc = ViewClient(device, device.serialno, adb=TRUE, autodump=False)
        self.assertNotEquals(None, vc)
        vc.root = root
        try:
            vc.findViewWithTextOrRaise('Non Existent', root=v4)
            self.fail()
        except ViewNotFoundException:
            pass