def setUp(self):
     if DEBUG:
         print >>sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
     (self.device, self.serialno) = ViewClient.connectToDeviceOrExit(serialno=".*")
     self.assertIsNotNone(self.device)
     self.uiAutomatorHelper = UiAutomatorHelper(self.device)
Esempio n. 2
0
 def setUp(self):
     if DEBUG:
         print >> sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
     (self.device,
      self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
     self.assertIsNotNone(self.device)
     self.uiAutomatorHelper = UiAutomatorHelper(self.device)
 def setUp(self):
     if DEBUG:
         print("@@@ UiAutomatorHelperTests.setUp", file=sys.stderr)
     (self.device,
      self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
     self.assertIsNotNone(self.device)
     self.uiAutomatorHelper = UiAutomatorHelper(self.device)
     self.uiAutomatorHelper.ui_device.press_home()
Esempio n. 4
0
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
        (self.device,
         self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)

    def tearDown(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.tearDown"
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.dumpWindowHierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.dumpWindowHierarchy()
            self.assertIsNotNone(dump)

    def testPressKeyCode(self):
        response = self.uiAutomatorHelper.pressKeyCode(4)
        '''4 is KEYCODE_BACK'''
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testTakeScreenshot(self):
        buf = self.uiAutomatorHelper.takeScreenshot()
        self.assertIsNotNone(buf)
        self.assertTrue(len(buf) > 0)
        image = Image.open(cStringIO.StringIO(buf))
        self.assertIsNotNone(image)
        self.assertEqual(image.format, 'PNG')

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.click(x=x, y=y)
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.swipe(startX=x0,
                                                startY=y0,
                                                endX=x1,
                                                endY=y1,
                                                steps=steps)
        if DEBUG:
            print >> sys.stderr, "response=", response
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print >>sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
        (self.device, self.serialno) = ViewClient.connectToDeviceOrExit(serialno=".*")
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)

    def tearDown(self):
        if DEBUG:
            print >>sys.stderr, "@@@ UiAutomatorHelperTests.tearDown"
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.dumpWindowHierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.dumpWindowHierarchy()
            self.assertIsNotNone(dump)

    def testPressKeyCode(self):
        response = self.uiAutomatorHelper.pressKeyCode(4)
        """4 is KEYCODE_BACK"""
        if DEBUG:
            print >>sys.stderr, "response=", response

    def testTakeScreenshot(self):
        buf = self.uiAutomatorHelper.takeScreenshot()
        self.assertIsNotNone(buf)
        self.assertTrue(len(buf) > 0)
        image = Image.open(cStringIO.StringIO(buf))
        self.assertIsNotNone(image)
        self.assertEqual(image.format, "PNG")

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.click(x=x, y=y)
        if DEBUG:
            print >>sys.stderr, "response=", response

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.swipe(startX=x0, startY=y0, endX=x1, endY=y1, steps=steps)
        if DEBUG:
            print >>sys.stderr, "response=", response
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
        (self.device, self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)

    def tearDown(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.tearDown"
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.dumpWindowHierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.dumpWindowHierarchy()
            self.assertIsNotNone(dump)

    def testTakeScreenshot(self):
        buf = self.uiAutomatorHelper.takeScreenshot()
        self.assertIsNotNone(buf)
        self.assertTrue(len(buf) > 0)
        image = Image.open(cStringIO.StringIO(buf))
        self.assertIsNotNone(image)
        self.assertEqual(image.format, 'PNG')

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.click(x, y)
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.swipe((x0, y0), (x1, y1), steps)
        if DEBUG:
            print >> sys.stderr, "response=", response
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.setUp"
        (self.device, self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)

    def tearDown(self):
        if DEBUG:
            print >> sys.stderr, "@@@ UiAutomatorHelperTests.tearDown"
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.dumpWindowHierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.dumpWindowHierarchy()
            self.assertIsNotNone(dump)

    def testPressKeyCode(self):
        response = self.uiAutomatorHelper.pressKeyCode(4)
        '''4 is KEYCODE_BACK'''
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testTakeScreenshot(self):
        buf = self.uiAutomatorHelper.takeScreenshot()
        self.assertIsNotNone(buf)
        self.assertTrue(len(buf) > 0)
        image = Image.open(cStringIO.StringIO(buf))
        self.assertIsNotNone(image)
        self.assertEqual(image.format, 'PNG')

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.click(x=x, y=y)
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.swipe(startX=x0, startY=y0, endX=x1, endY=y1, steps=steps)
        if DEBUG:
            print >> sys.stderr, "response=", response

    def testSetText_UiObject2_Chinese_text(self):
        # This enters a Reminder using Calendar
        # See https://github.com/dtmilano/AndroidViewClient/issues/242
        uio = self.uiAutomatorHelper.findObject(
            bySelector=u'[email protected]:id/title_edit_text,[email protected],text@$Remind me to…,[email protected]')
        self.assertIsNotNone(uio)
        self.assertTrue(isinstance(uio, UiObject2))
        uio.setText(u"提醒我包括中文支持")
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print("@@@ UiAutomatorHelperTests.setUp", file=sys.stderr)
        (self.device,
         self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)
        self.uiAutomatorHelper.ui_device.press_home()

    def tearDown(self):
        if DEBUG:
            print("@@@ UiAutomatorHelperTests.tearDown", file=sys.stderr)
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.ui_device.dump_window_hierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.ui_device.dump_window_hierarchy()
            self.assertIsNotNone(dump)

    def testPressKeyCode(self):
        response = self.uiAutomatorHelper.ui_device.press_key_code(4)
        '''4 is KEYCODE_BACK'''
        if DEBUG:
            print("response=", response, file=sys.stderr)
        self.assertEqual(response.status, 'OK')

    def testTakeScreenshot(self):
        received = self.uiAutomatorHelper.ui_device.take_screenshot()
        self.assertIsNotNone(received)
        stream = io.BytesIO(received.read())
        self.assertIsNotNone(stream)
        from PIL import Image
        image = Image.open(stream)
        self.assertIsNotNone(image)
        self.assertEqual(image.format, 'PNG')
        filename = f'/tmp/uiautomatorhelpertests-{os.getpid()}.png'
        image.save(filename, 'PNG')
        print(f'Screenshot saved to file://{filename}')

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.ui_device.click(x=x, y=y)
        if DEBUG:
            print("response=", response, file=sys.stderr)
        self.assertEqual(response.status, 'OK')

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.ui_device.swipe(start_x=x0,
                                                          start_y=y0,
                                                          end_x=x1,
                                                          end_y=y1,
                                                          steps=steps)
        if DEBUG:
            print("response=", response, file=sys.stderr)
        self.assertEqual(response.status, 'OK')

    def testSetText_UiObject2_Chinese_text(self):
        # This enters a Reminder using Calendar
        # See https://github.com/dtmilano/AndroidViewClient/issues/242
        self.uiAutomatorHelper.ui_device.press_home()

        obj_ref: ObjectRef = self.uiAutomatorHelper.until.find_object(
            by_selector=
            'checkable@false,[email protected],desc@Google Search,[email protected],[email protected]:id/search_edit_frame'
        )
        self.assertIsNotNone(obj_ref)
        self.assertGreater(obj_ref.oid, 0)
        self.assertTrue(
            isinstance(obj_ref, ObjectRef),
            f'obj_ref type is {type(obj_ref)} instead of ObjectRef')
        obj_ref: ObjectRef = self.uiAutomatorHelper.ui_device.wait(
            search_condition_ref=obj_ref.oid, timeout=3000)
        self.uiAutomatorHelper.ui_object2.click(obj_ref.oid)

        obj_ref: ObjectRef = self.uiAutomatorHelper.until.find_object(
            by_selector=
            'checkable@false,[email protected],[email protected],[email protected]:id/search_box,text@Search…'
        )
        self.assertIsNotNone(obj_ref)
        self.assertGreater(obj_ref.oid, 0)
        self.assertTrue(
            isinstance(obj_ref, ObjectRef),
            f'obj_ref type is {type(obj_ref)} instead of ObjectRef')
        obj_ref: ObjectRef = self.uiAutomatorHelper.ui_device.wait(
            search_condition_ref=obj_ref.oid, timeout=3000)
        self.uiAutomatorHelper.ui_object2.set_text(obj_ref.oid, '提醒我包括中文支持')
        self.uiAutomatorHelper.ui_device.press_enter()
class UiAutomatorHelperTests(unittest.TestCase):
    def setUp(self):
        if DEBUG:
            print("@@@ UiAutomatorHelperTests.setUp", file=sys.stderr)
        (self.device, self.serialno) = ViewClient.connectToDeviceOrExit(serialno='.*')
        self.assertIsNotNone(self.device)
        self.uiAutomatorHelper = UiAutomatorHelper(self.device)

    def tearDown(self):
        if DEBUG:
            print("@@@ UiAutomatorHelperTests.tearDown", file=sys.stderr)
        self.uiAutomatorHelper.quit()

    def testDumpWindowHierarchy(self):
        dump = self.uiAutomatorHelper.dumpWindowHierarchy()
        self.assertIsNotNone(dump)

    def testDumpWindowHierarchy_repeat(self):
        for _ in range(10):
            dump = self.uiAutomatorHelper.dumpWindowHierarchy()
            self.assertIsNotNone(dump)

    def testPressKeyCode(self):
        response = self.uiAutomatorHelper.pressKeyCode(4)
        '''4 is KEYCODE_BACK'''
        if DEBUG:
            print("response=", response, file=sys.stderr)

    def testTakeScreenshot(self):
        buf = self.uiAutomatorHelper.takeScreenshot()
        self.assertIsNotNone(buf)
        self.assertTrue(len(buf) > 0)
        image = Image.open(io.StringIO(buf))
        self.assertIsNotNone(image)
        self.assertEqual(image.format, 'PNG')

    def testClick_random(self):
        x = random.randint(0, 1000)
        y = random.randint(0, 1000)
        response = self.uiAutomatorHelper.click(x=x, y=y)
        if DEBUG:
            print("response=", response, file=sys.stderr)

    def testSwipe_random(self):
        x0 = random.randint(0, 1000)
        y0 = random.randint(0, 1000)
        x1 = random.randint(0, 1000)
        y1 = random.randint(0, 1000)
        steps = random.randint(10, 100)
        response = self.uiAutomatorHelper.swipe(startX=x0, startY=y0, endX=x1, endY=y1, steps=steps)
        if DEBUG:
            print("response=", response, file=sys.stderr)

    def testSetText_UiObject2_Chinese_text(self):
        # This enters a Reminder using Calendar
        # See https://github.com/dtmilano/AndroidViewClient/issues/242
        uio = self.uiAutomatorHelper.findObject(
            bySelector='[email protected]:id/title_edit_text,[email protected],text@$Remind me to…,[email protected]')
        self.assertIsNotNone(uio)
        self.assertTrue(isinstance(uio, UiObject2))
        uio.setText("提醒我包括中文支持")