def test_child_by_instance(self): method = self.fake_jsonrpc_method(method='childByInstance', return_value='myname') kwargs = {"className": "android", "text": "patern match text"} generic_obj = self.obj.child_by_instance(1234, **kwargs) method.assert_called_once_with(Selector(**self.kwargs), Selector(**kwargs), 1234) self.assertEqual("myname", generic_obj.selector)
def test_child_by_description(self): method = self.fake_jsonrpc_method(method='childByDescription', return_value='myname') kwargs = {"className": "android", "text": "patern match text"} generic_obj = self.obj.child_by_description("child text", **kwargs) method.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): method = self.fake_jsonrpc_method(method='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) method.assert_called_once_with(Selector(**self.kwargs), Selector(**kwargs), "child text", False) self.assertEqual("myname", generic_obj.selector)
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): method = fake_jsonrpc_method(self.rpc_client, method='getFromParent', return_value='another-name') kwargs = {"className": "android", "text": "patern match text"} generic_obj = self.obj.sibling(**kwargs) method.assert_called_once_with(self.name, Selector(**kwargs)) self.assertEqual(generic_obj.selector, method.return_value)
def test_device_obj(self): with patch("uiautomatorminus.AutomatorDeviceObject") as AutomatorDeviceObject: kwargs = {"text": "abc", "description": "description...", "clickable": True} self.device(**kwargs) AutomatorDeviceObject.assert_called_once_with(self.device, Selector(**kwargs)) with patch("uiautomatorminus.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): method = self.fake_jsonrpc_method(method='dragTo', return_value=False) self.assertFalse(self.obj.drag.to(10, 20, steps=10)) method.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(method.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_watcher(self): method = self.fake_jsonrpc_method('hasWatcherTriggered', return_value=False) self.assertFalse(self.device.watcher("name").triggered) method.assert_called_once_with("name") method = self.fake_jsonrpc_method('removeWatcher') self.device.watcher("a").remove() method.assert_called_once_with("a") method = self.fake_jsonrpc_method('registerClickUiObjectWatcher') 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) method.assert_called_once_with( "watcher", [Selector(**condition1), Selector(**condition2)], Selector(**target) ) method = self.fake_jsonrpc_method('registerPressKeyskWatcher') self.device.watcher("watcher2").when(**condition1).when(**condition2).press.back.home.power("menu") method.assert_called_once_with( "watcher2", [Selector(**condition1), Selector(**condition2)], ("back", "home", "power", "menu"))
def test_init(self): sel = Selector() self.assertEqual(sel[self.mask], 0) self.assertEqual(sel["childOrSibling"], []) self.assertEqual(sel["childOrSiblingSelector"], [])
def test_count(self): method = self.fake_jsonrpc_method(method='count', return_value=10) self.assertEqual(self.obj.count, 10) method.assert_called_once_with(Selector(**self.kwargs))
def test_error(self): with self.assertRaises(ReferenceError): Selector(text1="")
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))
def setUp(self): self.device = MagicMock() self.rpc_client = MagicMock() self.device.server.jsonrpc.return_value = self.rpc_client self.kwargs = {"text": "text", "className": "android"} self.obj = AutomatorDeviceObject(self.device, Selector(**self.kwargs))
def test_scroll(self): steps = 100 max_swipes = 1000 method = self.fake_jsonrpc_method(method='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=20)) self.assertEqual(method.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) ]) method = self.fake_jsonrpc_method(method='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(method.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) ]) method = self.fake_jsonrpc_method(method='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=100)) self.assertEqual(method.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) ]) method = self.fake_jsonrpc_method(method='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=100)) self.assertEqual(method.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": "..."} method = self.fake_jsonrpc_method(method='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(method.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) ])