Exemple #1
0
 def __call__(self, *args, **kwargs):
     el = MagnetoDeviceObject(self, Selector(**kwargs))
     if not el.exists:
         self.server.stop()
         self.server.start()
         el = MagnetoDeviceObject(self, Selector(**kwargs))
     return el
Exemple #2
0
    def test_watcher(self):
        self.device.server.jsonrpc.hasWatcherTriggered = MagicMock()
        self.device.server.jsonrpc.hasWatcherTriggered.return_value = False
        self.assertFalse(self.device.watcher("name").triggered)
        self.device.server.jsonrpc.hasWatcherTriggered.assert_called_once_with(
            "name")

        self.device.server.jsonrpc.removeWatcher = MagicMock()
        self.device.watcher("a").remove()
        self.device.server.jsonrpc.removeWatcher.assert_called_once_with("a")

        self.device.server.jsonrpc.registerClickUiObjectWatcher = MagicMock()
        condition1 = {"text": "my text", "className": "android"}
        condition2 = {"description": "my desc", "clickable": True}
        target = {"className": "android.widget.Button", "text": "OK"}
        self.device.watcher("watcher").when(**condition1).when(
            **condition2).click(**target)
        self.device.server.jsonrpc.registerClickUiObjectWatcher.assert_called_once_with(
            "watcher", [Selector(**condition1),
                        Selector(**condition2)], Selector(**target))

        self.device.server.jsonrpc.registerPressKeyskWatcher = MagicMock()
        self.device.watcher("watcher2").when(**condition1).when(
            **condition2).press.back.home.power("menu")
        self.device.server.jsonrpc.registerPressKeyskWatcher.assert_called_once_with(
            "watcher2", [Selector(**condition1),
                         Selector(**condition2)],
            ("back", "home", "power", "menu"))
 def test_child_by_instance(self):
     self.jsonrpc.childByInstance.return_value = "myname"
     kwargs = {"className": "android", "text": "patern match text"}
     generic_obj = self.obj.child_by_instance(1234, **kwargs)
     self.jsonrpc.childByInstance.assert_called_once_with(
         Selector(**self.kwargs), Selector(**kwargs), 1234)
     self.assertEqual("myname", generic_obj.selector)
 def test_child_by_description(self):
     self.jsonrpc.childByDescription.return_value = "myname"
     kwargs = {"className": "android", "text": "patern match text"}
     generic_obj = self.obj.child_by_description("child text", **kwargs)
     self.jsonrpc.childByDescription.assert_called_once_with(
         Selector(**self.kwargs), Selector(**kwargs), "child text")
     self.assertEqual("myname", generic_obj.selector)
 def test_child_by_text_allow_scroll_search(self):
     self.jsonrpc.childByText.return_value = "myname"
     kwargs = {"className": "android", "text": "patern match text"}
     generic_obj = self.obj.child_by_text("child text",
                                          allow_scroll_search=False,
                                          **kwargs)
     self.jsonrpc.childByText.assert_called_once_with(
         Selector(**self.kwargs), Selector(**kwargs), "child text", False)
     self.assertEqual("myname", generic_obj.selector)
    def test_child_and_sibling(self):
        sel = Selector()
        sel.child(text="...")
        self.assertEqual(sel["childOrSibling"], ["child"])
        self.assertEqual(sel["childOrSiblingSelector"], [Selector(text="...")])

        sel.sibling(text="---")
        self.assertEqual(sel["childOrSibling"], ["child", "sibling"])
        self.assertEqual(sel["childOrSiblingSelector"], [Selector(text="..."), Selector(text="---")])
    def test_add(self):
        for k, v in self.fields.items():
            kwargs = {k: v[1]}
            sel = Selector(**kwargs)
            self.assertEqual(sel[self.mask], v[0])

        for k1, v1 in self.fields.items():
            for k2, v2 in self.fields.items():
                if k1 != k2:
                    kwargs = {k1: v1[1], k2: v2[1]}
                    sel = Selector(**kwargs)
                    self.assertEqual(sel[self.mask], v1[0] | v2[0])
    def test_child_and_sibling(self):
        sel = Selector()
        sel.child(text="...")
        self.assertEqual(sel["childOrSibling"], ["child"])
        self.assertEqual(sel["childOrSiblingSelector"], [Selector(text="...")])

        sel.sibling(text="---")
        self.assertEqual(sel["childOrSibling"], ["child", "sibling"])
        self.assertEqual(
            sel["childOrSiblingSelector"],
            [Selector(text="..."), Selector(text="---")])
    def test_delete(self):
        for k, v in self.fields.items():
            kwargs = {k: v[1]}
            sel = Selector(**kwargs)
            del sel[k]
            self.assertEqual(sel[self.mask], 0)

        for k1, v1 in self.fields.items():
            for k2, v2 in self.fields.items():
                if k1 != k2:
                    kwargs = {k1: v1[1], k2: v2[1]}
                    sel = Selector(**kwargs)
                    del sel[k1]
                    self.assertEqual(sel[self.mask], v2[0])
                    del sel[k2]
                    self.assertEqual(sel[self.mask], 0)
 def test_from_parent(self):
     kwargs = {"text": "parent text", "className": "android"}
     obj = self.obj.from_parent(**kwargs)
     self.assertEqual(len(obj.selector['childOrSibling']), 1)
     self.assertEqual(obj.selector['childOrSibling'][0], 'sibling')
     self.assertEqual(len(obj.selector['childOrSiblingSelector']), 1)
     self.assertEqual(obj.selector['childOrSiblingSelector'][0],
                      Selector(**kwargs))
 def test_child_selector(self):
     kwargs = {"text": "child text", "className": "android"}
     obj = self.obj.child_selector(**kwargs)
     self.assertEqual(len(obj.selector['childOrSibling']), 1)
     self.assertEqual(obj.selector['childOrSibling'][0], 'child')
     self.assertEqual(len(obj.selector['childOrSiblingSelector']), 1)
     self.assertEqual(obj.selector['childOrSiblingSelector'][0],
                      Selector(**kwargs))
 def test_sibling(self):
     self.jsonrpc.getFromParent.return_value = "another-name"
     kwargs = {"className": "android", "text": "patern match text"}
     generic_obj = self.obj.sibling(**kwargs)
     self.jsonrpc.getFromParent.assert_called_once_with(
         self.name, Selector(**kwargs))
     self.assertEqual(generic_obj.selector,
                      self.jsonrpc.getFromParent.return_value)
Exemple #13
0
    def test_device_obj(self):
        with patch("uiautomator.AutomatorDeviceObject") as AutomatorDeviceObject:
            kwargs = {"text": "abc", "description": "description...", "clickable": True}
            self.device(**kwargs)
            AutomatorDeviceObject.assert_called_once_with(self.device, Selector(**kwargs))

        with patch("uiautomator.AutomatorDeviceObject") as AutomatorDeviceObject:
            AutomatorDeviceObject.return_value.exists = True
            self.assertTrue(self.device.exists(clickable=True))
            AutomatorDeviceObject.return_value.exists = False
            self.assertFalse(self.device.exists(text="..."))
    def test_drag_to(self):
        self.jsonrpc.dragTo.return_value = False
        self.assertFalse(self.obj.drag.to(10, 20, steps=10))
        self.jsonrpc.dragTo.return_value = True
        self.assertTrue(self.obj.drag.to(x=10, y=20, steps=20))

        sel = {"text": "text..."}
        self.assertTrue(self.obj.drag.to(steps=30, **sel))
        self.assertEqual(self.jsonrpc.dragTo.call_args_list, [
            call(self.obj.selector, 10, 20, 10),
            call(self.obj.selector, 10, 20, 20),
            call(self.obj.selector, Selector(**sel), 30)
        ])
    def test_clone(self):
        kwargs = {
            "text": "1234",
            "description": "desc...",
            "clickable": True,
            "focusable": False,
            "packageName": "android"
        }
        sel = Selector(**kwargs)
        sel.child(text="1")
        sel.sibling(text="1")
        sel.child(text="1")

        clone = sel.clone()
        for k in kwargs:
            self.assertEqual(sel[k], clone[k])
        self.assertEqual(sel["childOrSibling"], clone["childOrSibling"])
        self.assertEqual(sel["childOrSiblingSelector"],
                         clone["childOrSiblingSelector"])
    def test_clone(self):
        kwargs = {
            "text": "1234",
            "description": "desc...",
            "clickable": True,
            "focusable": False,
            "packageName": "android"
        }
        sel = Selector(**kwargs)
        sel.child(text="1")
        sel.sibling(text="1")
        sel.child(text="1")

        clone = sel.clone()
        for k in kwargs:
            self.assertEqual(sel[k], clone[k])
        self.assertEqual(sel["childOrSibling"], clone["childOrSibling"])
        self.assertEqual(sel["childOrSiblingSelector"], clone["childOrSiblingSelector"])
 def __call__(self, **kwargs):
     return ClickObjectImpl(self, Selector(**kwargs))
 def test_count(self):
     self.jsonrpc.count.return_value = 10
     self.assertEqual(self.obj.count, 10)
     self.jsonrpc.count.assert_called_once_with(Selector(**self.kwargs))
 def test_error(self):
     with self.assertRaises(ReferenceError):
         Selector(text1="")
 def test_init(self):
     sel = Selector()
     self.assertEqual(sel[self.mask], 0)
     self.assertEqual(sel["childOrSibling"], [])
     self.assertEqual(sel["childOrSiblingSelector"], [])
    def skip_test_scroll(self):
        steps = 100
        max_swipes = 500
        self.jsonrpc.scrollForward.return_value = True
        self.assertTrue(self.obj.scroll.horiz.forward())
        self.assertTrue(self.obj.scroll.horizentally.forward())
        self.assertTrue(self.obj.scroll.vert.forward())
        self.assertTrue(self.obj.scroll(steps=50))
        self.assertEqual(self.jsonrpc.scrollForward.call_args_list, [
            call(self.obj.selector, False, steps),
            call(self.obj.selector, False, steps),
            call(self.obj.selector, True, steps),
            call(self.obj.selector, True, 20)
        ])

        self.jsonrpc.scrollBackward.return_value = True
        self.assertTrue(self.obj.scroll.horiz.backward())
        self.assertTrue(self.obj.scroll.horizentally.backward())
        self.assertTrue(self.obj.scroll.vert.backward())
        self.assertTrue(self.obj.scroll.vertically.backward(steps=20))
        self.assertEqual(self.jsonrpc.scrollBackward.call_args_list, [
            call(self.obj.selector, False, steps),
            call(self.obj.selector, False, steps),
            call(self.obj.selector, True, steps),
            call(self.obj.selector, True, 20)
        ])

        self.jsonrpc.scrollToBeginning.return_value = True
        self.assertTrue(self.obj.scroll.horiz.toBeginning())
        self.assertTrue(self.obj.scroll.horizentally.toBeginning())
        self.assertTrue(self.obj.scroll.vert.toBeginning())
        self.assertTrue(
            self.obj.scroll.vertically.toBeginning(steps=20, max_swipes=200))
        self.assertEqual(self.jsonrpc.scrollToBeginning.call_args_list, [
            call(self.obj.selector, False, max_swipes, steps),
            call(self.obj.selector, False, max_swipes, steps),
            call(self.obj.selector, True, max_swipes, steps),
            call(self.obj.selector, True, 100, 20)
        ])

        self.jsonrpc.scrollToEnd.return_value = True
        self.assertTrue(self.obj.scroll.horiz.toEnd())
        self.assertTrue(self.obj.scroll.horizentally.toEnd())
        self.assertTrue(self.obj.scroll.vert.toEnd())
        self.assertTrue(
            self.obj.scroll.vertically.toEnd(steps=20, max_swipes=500))
        self.assertEqual(self.jsonrpc.scrollToEnd.call_args_list, [
            call(self.obj.selector, False, max_swipes, steps),
            call(self.obj.selector, False, max_swipes, steps),
            call(self.obj.selector, True, max_swipes, steps),
            call(self.obj.selector, True, 100, 20)
        ])

        info = {"text": "..."}
        self.jsonrpc.scrollTo.return_value = True
        self.assertTrue(self.obj.scroll.horiz.to(**info))
        self.assertTrue(self.obj.scroll.horizentally.to(**info))
        self.assertTrue(self.obj.scroll.vert.to(**info))
        self.assertTrue(self.obj.scroll.vertically.to(**info))
        self.assertEqual(self.jsonrpc.scrollTo.call_args_list, [
            call(self.obj.selector, Selector(**info), False),
            call(self.obj.selector, Selector(**info), False),
            call(self.obj.selector, Selector(**info), True),
            call(self.obj.selector, Selector(**info), True)
        ])
 def test_init(self):
     kwargs = {"text": "text", "className": "android"}
     self.device_obj = AutomatorDeviceObject(self.device,
                                             Selector(**kwargs))
     self.assertEqual(self.device_obj.selector, Selector(**kwargs))
     self.assertEqual(self.device_obj.jsonrpc, self.device.server.jsonrpc)
 def setUp(self):
     self.device = MagicMock()
     self.jsonrpc = self.device.server.jsonrpc = MagicMock()
     self.jsonrpc_wrap = self.device.server.jsonrpc_wrap = MagicMock()
     self.kwargs = {"text": "text", "className": "android"}
     self.obj = AutomatorDeviceObject(self.device, Selector(**self.kwargs))