Esempio n. 1
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)

    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("提醒我包括中文支持")