How to use long_click method in uiautomator

Best Python code snippet using uiautomator

test_device_obj.py

Source:test_device_obj.py Github

copy

Full Screen

...118 def test_click_wait(self):119 self.jsonrpc.clickAndWaitForNewWindow.return_value = True120 self.assertTrue(self.obj.click.wait(timeout=321))121 self.jsonrpc.clickAndWaitForNewWindow.assert_called_once_with(self.obj.selector, 321)122 def test_long_click(self):123 self.jsonrpc.longClick.return_value = False124 corners = ["tl", "topleft", "br", "bottomright"]125 for c in corners:126 self.assertFalse(self.obj.long_click(c))127 self.assertEqual(self.jsonrpc.longClick.call_args_list,128 [call(self.obj.selector, c) for c in corners])129 self.jsonrpc.longClick = MagicMock()130 self.jsonrpc.longClick.return_value = True131 corners = ["tl", "topleft", "br", "bottomright"]132 for c in corners:133 self.assertTrue(getattr(self.obj.long_click, c)())134 self.assertEqual(self.jsonrpc.longClick.call_args_list,135 [call(self.obj.selector, c) for c in corners])136 self.jsonrpc.longClick = MagicMock()137 self.jsonrpc.longClick.return_value = True138 self.assertTrue(self.obj.long_click())139 self.jsonrpc.longClick.assert_called_once_with(self.obj.selector)140 def test_long_click_using_swipe(self):141 self.device.long_click.return_value = False142 self.jsonrpc.objInfo.return_value = {143 'longClickable': False,144 'visibleBounds': {145 'top': 0,146 'bottom': 60,147 'left': 0,148 'right': 60149 }150 }151 corners = ["tl", "topleft", "br", "bottomright"]152 for c in corners:153 self.assertFalse(self.obj.long_click(c))154 self.assertEqual(self.device.long_click.call_args_list,155 [call(10, 10), call(10, 10), call(50, 50), call(50, 50)])156 self.device.long_click = MagicMock()157 self.device.long_click.return_value = True158 corners = ["tl", "topleft", "br", "bottomright"]159 for c in corners:160 self.assertTrue(getattr(self.obj.long_click, c)())161 self.assertEqual(self.device.long_click.call_args_list,162 [call(10, 10), call(10, 10), call(50, 50), call(50, 50)])163 self.device.long_click = MagicMock()164 self.device.long_click.return_value = True165 self.assertTrue(self.obj.long_click())166 self.device.long_click.assert_called_once_with(30, 30)167 def test_drag_to(self):168 self.jsonrpc.dragTo.return_value = False169 self.assertFalse(self.obj.drag.to(10, 20, steps=10))170 self.jsonrpc.dragTo.return_value = True171 self.assertTrue(self.obj.drag.to(x=10, y=20, steps=20))172 sel = {"text": "text..."}173 self.assertTrue(self.obj.drag.to(steps=30, **sel))174 self.assertEqual(self.jsonrpc.dragTo.call_args_list,175 [call(self.obj.selector, 10, 20, 10),176 call(self.obj.selector, 10, 20, 20),177 call(self.obj.selector, Selector(**sel), 30)])178 def test_gesture(self):179 self.jsonrpc.gesture.return_value = True...

Full Screen

Full Screen

MyUiautomator.py

Source:MyUiautomator.py Github

copy

Full Screen

...156 log.info('sucess double_click coordinate: {}'.format(css))157 else:158 log.error('double_click Positioning syntax errors: {}, 请传入以下类型: str、 list、 tuble'.format(css))159 raise NameError('double_click Positioning syntax errors: {}, 请传入以下类型: str、 list、 tuble'.format(css))160 def long_click(self, css, secs=0.5):161 """162 uiautomator2长按点击事件163 :param css:传入定位元素或坐标,元素如:text->收藏; 坐标如:[1, 2]/(1, 2)164 :param secs;长按时间165 :return:166 """167 if type(css) is str:168 self.find_ele(css).long_click(duration=secs)169 log.info('sucess long_click ele: {}'.format(css))170 elif type(css) is list or type(css) is tuple:171 self.app.long_click(css[0], css[1], duration=secs)172 log.info('sucess long_click coordinate: {}'.format(css))173 else:174 log.error('long_click Positioning syntax errors: {}, 请传入以下类型: str、 list、 tuble'.format(css))175 raise NameError('long_click Positioning syntax errors: {}, 请传入以下类型: str、 list、 tuble'.format(css))176 def set_text(self, css, text):177 """输入值,不调用输入法输入"""178 app_element = self.find_ele(css)179 app_element.set_text(text)180 log.info('sucess set text: "{}" / "{}"'.format(css, text))181 def send_keys(self, text):182 """183 无法定位时,使用输入法输入,在光标处输入184 :param text: 文本185 :return:...

Full Screen

Full Screen

local_positioning1.py

Source:local_positioning1.py Github

copy

Full Screen

...3from poco.drivers.unity3d.test.tutorial.case import TutorialCase4class LocalPositioning1Tutorial(TutorialCase):5 def runTest(self):6 image = self.poco('fish').child(type='Image')7 image.focus('center').long_click()8 time.sleep(0.2)9 image.focus([0.1, 0.1]).long_click()10 time.sleep(0.2)11 image.focus([0.9, 0.9]).long_click()12 time.sleep(0.2)13 image.focus([0.5, 0.9]).long_click()14 time.sleep(0.2)15if __name__ == '__main__':16 import pocounit...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run uiautomator automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful