def testSerialno_none(self):
     try:
         adbClient = AdbClient(None)
         self.assertTrue(adbClient.checkConnected())
         # because serialno is None, transport cannot be set, so next statement
         # will raise an exception
         adbClient.getSdkVersion()
         self.fail("No exception was generated")
     except RuntimeError as ex:
         self.assertIsNotNone(
             re.search("ERROR: Transport is not set", str(ex)),
             "Couldn't find error message: %s" % ex)
Example #2
0
def main():
    devices = adb.get_attached_devices()

    print """ prerequisiti:
    1) Telefono connesso in USB,
    2) USB Debugging enabled (settings/developer options/usb debugging)
    3) connesso wifi a RSSM
    4) screen time 2m (settings/display/sleep)
    """

    print "devices connessi:"
    for device in devices:
        print device

    dev = None
    if not devices:
        print "non ci sono device connessi"
    else:

        if len(devices) > 1:
            dev = raw_input("su quale device si vuole eseguire il test? ")
            print "Eseguo il test su %s" % dev

        #device = MonkeyRunner.waitForConnection(dev)
        if len(sys.argv) >= 2:
            serialno = sys.argv[1]
        else:
            serialno = '.*'
        device = AdbClient(serialno=serialno)
        do_test(device)

    print "Fine."
Example #3
0
def touch(t):
	x = 500
	y = 500
	shell = 'input touchscreen swipe %d %d %d %d %d' % (x, y, x, y, t)
	print t
	# shell = 'input touchscreen tap %d %d %d' % (x, y, t)
	AdbClient(serialno=serialno).shell(shell)
 def testSerialno_nonExistent(self):
     try:
         AdbClient('doesnotexist')
     except RuntimeError as ex:
         self.assertIsNotNone(
             re.search(
                 "ERROR: couldn't find device that matches 'doesnotexist'",
                 str(ex)), "Couldn't find error message: %s" % ex)
 def __runTests(self):
     if DEBUG:
         print("__runTests: start", file=sys.stderr)
     # We need a new AdbClient instance with timeout=None (means, no timeout) for the long running test service
     newAdbClient = AdbClient(self.adbClient.serialno, self.adbClient.hostname, self.adbClient.port, timeout=None)
     self.thread = RunTestsThread(adbClient=newAdbClient, testClass=self.TEST_CLASS, testRunner=self.TEST_RUNNER)
     if DEBUG:
         print("__runTests: starting thread", file=sys.stderr)
     self.thread.start()
     if DEBUG:
         print("__runTests: end", file=sys.stderr)
 def setUpClass(cls):
     cls.adb = obtainAdbPath()
     # we use 'fakeserialno' and settransport=False so AdbClient does not try to find the
     # serialno in setTransport()
     try:
         adbClient = AdbClient('fakeserialno', settransport=False)
     except RuntimeError as ex:
         if re.search('Connection refused', str(ex)):
             raise RuntimeError("adb is not running")
         raise (ex)
     devices = adbClient.getDevices()
     if len(devices) == 0:
         raise RuntimeError(
             "This tests require at least one device connected. None was found."
         )
     for device in devices:
         if device.status == 'device':
             cls.androidSerial = device.serialno
             if VERBOSE:
                 print("AdbClientTest: using device %s" % cls.androidSerial)
             return
     raise RuntimeError("No on-line devices found")
class AdbClientTest(unittest.TestCase):

    androidSerial = None
    ''' The Android device serial number used by default'''
    @classmethod
    def setUpClass(cls):
        cls.adb = obtainAdbPath()
        # we use 'fakeserialno' and settransport=False so AdbClient does not try to find the
        # serialno in setTransport()
        try:
            adbClient = AdbClient('fakeserialno', settransport=False)
        except RuntimeError as ex:
            if re.search('Connection refused', str(ex)):
                raise RuntimeError("adb is not running")
            raise (ex)
        devices = adbClient.getDevices()
        if len(devices) == 0:
            raise RuntimeError(
                "This tests require at least one device connected. None was found."
            )
        for device in devices:
            if device.status == 'device':
                cls.androidSerial = device.serialno
                if VERBOSE:
                    print("AdbClientTest: using device %s" % cls.androidSerial)
                return
        raise RuntimeError("No on-line devices found")

    def setUp(self):
        subprocess.check_call(
            [self.adb, '-s', self.androidSerial, 'forward', '--remove-all'])
        self.adbClient = AdbClient(self.androidSerial)
        self.assertIsNotNone(self.adbClient, "adbClient is None")

    def tearDown(self):
        self.adbClient.close()
        subprocess.check_call(
            [self.adb, '-s', self.androidSerial, 'forward', '--remove-all'])

    def testSerialno_none(self):
        try:
            adbClient = AdbClient(None)
            self.assertTrue(adbClient.checkConnected())
            # because serialno is None, transport cannot be set, so next statement
            # will raise an exception
            adbClient.getSdkVersion()
            self.fail("No exception was generated")
        except RuntimeError as ex:
            self.assertIsNotNone(
                re.search("ERROR: Transport is not set", str(ex)),
                "Couldn't find error message: %s" % ex)

    def testSerialno_nonExistent(self):
        try:
            AdbClient('doesnotexist')
        except RuntimeError as ex:
            self.assertIsNotNone(
                re.search(
                    "ERROR: couldn't find device that matches 'doesnotexist'",
                    str(ex)), "Couldn't find error message: %s" % ex)

    def testSerialno_empty(self):
        try:
            AdbClient('')
            self.fail("No exception was generated")
        except ValueError:
            pass

    def testGetDevices(self):
        # we use 'fakeserialno' and settransport=False so AdbClient does not try to find the
        # serialno in setTransport()
        adbclient = AdbClient('fakeserialno', settransport=False)
        self.assertTrue(len(adbclient.getDevices()) >= 1)

    def testGetDevices_androidSerial(self):
        devs = self.adbClient.getDevices()
        self.assertTrue(self.androidSerial in [d.serialno for d in devs])

    def testGetDevices_regex(self):
        adbclient = AdbClient('.*', settransport=False)
        self.assertTrue(len(adbclient.getDevices()) >= 1)

    #@unittest.skipIf(not re.search('emulator-5554', AdbClientTest.androidSerial), "Supported only when emulator is connected")
    def testAdbClient_serialnoNoRegex(self):
        if re.search('emulator-5554', AdbClientTest.androidSerial):
            adbClient = AdbClient('emulator-5554')
            self.assertIsNotNone(adbClient)
            self.assertEqual('emulator-5554', adbClient.serialno)

    #@unittest.skipIf(not re.search('emulator', AdbClientTest.androidSerial), "Supported only when emulator is connected")
    def testAdbClient_serialnoRegex(self):
        if re.search('emulator', AdbClientTest.androidSerial):
            adbClient = AdbClient('emulator-.*')
            self.assertIsNotNone(adbClient)
            self.assertTrue(re.match('emulator-.*', adbClient.serialno))

    def testAdbClient_serialnoRegexIP(self):
        IPRE = re.compile('(\d+\.){3}\d+')
        if IPRE.search(AdbClientTest.androidSerial):
            adbClient = AdbClient('\d+.*')
            self.assertIsNotNone(adbClient)
            self.assertTrue(IPRE.match(adbClient.serialno))

    def testCheckVersion(self):
        self.adbClient.checkVersion()

    def testShell(self):
        date = self.adbClient.shell('date +"%Y/%m/%d"')
        # this raises a ValueError if the format is not correct
        time.strptime(date, '%Y/%m/%d\r\n')

    def testShell_noOutput(self):
        empty = self.adbClient.shell('sleep 3')
        self.assertIs('', empty,
                      "Expected empty output but found '%s'" % empty)

    def testGetProp_ro_serialno(self):
        IPRE = re.compile('(\d+\.){3}\d+')
        serialno = self.adbClient.getProperty('ro.serialno')
        self.assertIsNotNone(serialno)
        if re.search('emulator-.*', self.androidSerial):
            self.assertEqual(serialno, '')
        elif re.search('VirtualBox',
                       self.adbClient.getProperty('ro.product.model')):
            self.assertEqual(serialno, '')
        elif IPRE.search(self.androidSerial):
            # if we are connected over IP the serial number is the real one for the device
            self.assertIsNotNone(serialno)
        else:
            self.assertEqual(serialno, self.androidSerial)

    def testGetProp_ro_kernel_qemu(self):
        qemu = self.adbClient.getProperty('ro.kernel.qemu')
        self.assertIsNotNone(qemu)
        if re.search('emulator-.*', self.androidSerial):
            self.assertEqual(qemu, '1')
        else:
            self.assertEqual(qemu, '')

    def testPress(self):
        self.adbClient.press('KEYCODE_DPAD_UP')

    def testTouch(self):
        self.adbClient.touch(480, 1250)

    def testType(self):
        self.adbClient.type('Android is cool')

    def testType_digits(self):
        self.adbClient.type('1234')

    def testType_digits_asInt(self):
        self.adbClient.type(1234)

    def __checkPackageInstalled(self):
        packages = self.adbClient.shell('pm list packages').splitlines()
        self.assertTrue(packages, "Could not detect any packages installed")
        if TEST_TEMPERATURE_CONVERTER_APP:
            self.assertIn('package:' + TEMPERATURE_CONVERTER_PKG, packages,
                          TEMPERATURE_CONVERTER_PKG + " is not installed")
            return (TEMPERATURE_CONVERTER_PKG, TEMPERATURE_CONVERTER_ACTIVITY)
        else:
            for line in packages:
                if CALCULATOR_KEYWORD in line:
                    pkg = line[line.index(':') + 1:]
                    self.assertTrue(
                        pkg, "No calculator package to use for testing")
                    return (pkg, CALCULATOR_ACTIVITY)
            return False

    def testStartActivity_component(self):
        pkg = self.__checkPackageInstalled()
        if pkg:
            self.adbClient.startActivity(pkg[0] + '/.' + pkg[1])

    def testGetWindows(self):
        self.assertIsNotNone(self.adbClient.getWindows())

    def testGetFocusedWindow(self):

        pkg = self.__checkPackageInstalled()
        if pkg:
            self.adbClient.startActivity(pkg[0] + '/.' + pkg[1])
            time.sleep(3)
            w = self.adbClient.getFocusedWindow()
            self.assertIsNotNone(w)
            self.assertEqual(pkg[0] + '/' + pkg[0] + '.' + pkg[1], w.activity)

    def testGetFocusedWindowName(self):
        pkg = self.__checkPackageInstalled()
        if pkg:
            self.adbClient.startActivity(pkg[0] + '/.' + pkg[1])
            time.sleep(3)
            n = self.adbClient.getFocusedWindowName()
            self.assertIsNotNone(n)
            self.assertEqual(pkg[0] + '/' + pkg[0] + '.' + pkg[1], n)

    def testStartActivity_uri(self):
        self.adbClient.startActivity(uri='http://www.google.com')

    #@unittest.skip("sequence")
    def testCommandsSequence(self):
        self.adbClient.setReconnect(True)
        if VERBOSE:
            print("Sending touch(480, 800)")
        self.adbClient.touch(480, 800)
        self.assertTrue(self.adbClient.checkConnected())
        if VERBOSE:
            print("Typing 'command 1'")
        self.adbClient.type("command 1")
        self.assertTrue(self.adbClient.checkConnected())
        if VERBOSE:
            print("Typing 'command 2'")
        self.adbClient.type("command 2")
        self.assertTrue(self.adbClient.checkConnected())
        if VERBOSE:
            print("Pressing ENTER")
        self.adbClient.press('KEYCODE_ENTER')
        self.assertTrue(self.adbClient.checkConnected())

    def testPressRepeat(self):
        self.adbClient.press('DEL', repeat=4)
 def testAdbClient_serialnoRegexIP(self):
     IPRE = re.compile('(\d+\.){3}\d+')
     if IPRE.search(AdbClientTest.androidSerial):
         adbClient = AdbClient('\d+.*')
         self.assertIsNotNone(adbClient)
         self.assertTrue(IPRE.match(adbClient.serialno))
 def testAdbClient_serialnoRegex(self):
     if re.search('emulator', AdbClientTest.androidSerial):
         adbClient = AdbClient('emulator-.*')
         self.assertIsNotNone(adbClient)
         self.assertTrue(re.match('emulator-.*', adbClient.serialno))
 def testAdbClient_serialnoNoRegex(self):
     if re.search('emulator-5554', AdbClientTest.androidSerial):
         adbClient = AdbClient('emulator-5554')
         self.assertIsNotNone(adbClient)
         self.assertEqual('emulator-5554', adbClient.serialno)
def makeSwipeDown():
    print "Swiping down..."
    AdbClient(serialno='.*').drag((550, 450), (550, 150), 100)
    vc.sleep(4)
    makeDump()
    return;
Example #12
0
def main(serialno):
    global installer

    devices = adb.get_attached_devices()

    print """ prerequisiti:
    1) Telefono connesso in USB,
    2) USB Debugging enabled (settings/developer options/usb debugging)
    3) connesso wifi a RSSM
    4) screen time 2m (settings/display/sleep)
    """

    print "devices connessi:"
    for device in devices:
        print device

    dev = None
    if not devices:
        print "non ci sono device connessi"
    else:

        if len(devices) > 1:
            dev = raw_input("su quale device si vuole eseguire il test? ")
            print "Eseguo il test su %s" % dev

        device = AdbClient(serialno=serialno)

        # find properties of phone

        props = get_properties(device, "ro.product.manufacturer",
                               "ro.product.model", "ro.build.selinux.enforce",
                               "ro.build.version.release",
                               "ro.build.version.sdk")

        imei = device.shell("dumpsys iphonesubinfo").split("\n")[2].split(
            " ")[-1]
        print imei

        if imei == None:
            return

        props["imei"] = imei.strip()

        #installer = "default"

        # doing test here
        maj = props["release"].split(".")[0]
        min = props["release"].split(".")[1]

        print maj, min
        if maj == "2":
            installer = "v2"

        try:
            ret = test_device(device, props)
            props["return"] = ret
            print "return: %s " % ret
        except Exception, ex:
            traceback.print_exc(props["id"])
            props['error'] = "%s" % ex

        # write results
        write_results(props)
Example #13
0
def main(serialno):
    global installer

    devices = adb.get_attached_devices()

    print """ prerequisiti:
    1) Telefono connesso in USB,
    2) USB Debugging enabled (settings/developer options/usb debugging)
    3) connesso wifi a RSSM
    4) screen time 2m (settings/display/sleep)
    """

    print "devices connessi:"
    for device in devices:
        print device

    dev = None
    if not devices:
        print "non ci sono device connessi"
    else:

        if len(devices) > 1:
            dev = raw_input("su quale device si vuole eseguire il test? ")
            print "Eseguo il test su %s" % dev

        device = AdbClient(serialno=serialno)

        # find properties of phone

        props = get_properties(
            device, "ro.product.manufacturer", "ro.product.model",
            "ro.build.selinux.enforce", "ro.build.version.release",
            "ro.build.version.sdk"
        )

        imei = device.shell("dumpsys iphonesubinfo").split("\n")[2].split(" ")[-1]
        print imei

        if imei == None:
            return

        props["imei"] = imei.strip()

        #installer = "default"

        # doing test here
        maj = props["release"].split(".")[0]
        min = props["release"].split(".")[1]

        print maj, min
        if maj == "2":
            installer = "v2"

        try:
            ret = test_device(device, props)
            props["return"] = ret
            print "return: %s " % ret
        except Exception, ex:
            traceback.print_exc(props["id"])
            props['error'] = "%s" % ex

        # write results
        write_results(props)
Example #14
0
lastDir = True # true right  false left

# kernel1 = np.array([(3, 10, 3), (0, 0, 0) , (-3, -10, -3)])
# kernel2 = np.array([(-3, -10, -3), (0, 0, 0) , (3, 10, 3)])

kernel1 = np.array([(0, 10, 0), (0, 0, 0), (0, -10, 0)])
kernel2 = np.array([(0, -10, 0), (0, 0, 0), (0, 10, 0)])

while True:
	imagePath = "./image-%d.png" % (imageId)
	print('takeSnapshot : ' + imagePath)

	if not isTest:
		imageId += 1
		AdbClient(serialno=serialno).takeSnapshot().save(imagePath)

	img = cv2.imread(imagePath)

	# if gray is None:
	# 	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #
	# for i in xrange(len(img)):
	# 	for j in xrange(len(img[0])):
	# 		gray[i][j] = img[i][j][0]

	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

	# edges = gray.copy()
	# for i in xrange(len(img) - 1):
	# 	for j in xrange(len(img[0])):
 def setUp(self):
     subprocess.check_call(
         [self.adb, '-s', self.androidSerial, 'forward', '--remove-all'])
     self.adbClient = AdbClient(self.androidSerial)
     self.assertIsNotNone(self.adbClient, "adbClient is None")
 def testGetDevices(self):
     # we use 'fakeserialno' and settransport=False so AdbClient does not try to find the
     # serialno in setTransport()
     adbclient = AdbClient('fakeserialno', settransport=False)
     self.assertTrue(len(adbclient.getDevices()) >= 1)
 def testGetDevices_regex(self):
     adbclient = AdbClient('.*', settransport=False)
     self.assertTrue(len(adbclient.getDevices()) >= 1)
 def testSerialno_empty(self):
     try:
         AdbClient('')
         self.fail("No exception was generated")
     except ValueError:
         pass
def makeSwipeForNavigationDrawer():
    print "Swiping..."
    AdbClient(serialno='.*').drag((5, 150), (550, 150), 100)
    vc.sleep(4)
    makeDump()
    return;