Пример #1
0
    def test_adb_cmd_server_host(self):
        adb = Adb(adb_server_host="localhost", adb_server_port=5037)
        adb.adb = MagicMock()
        adb.adb.return_value = "adb"
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        args = ["a", "b", "c"]
        with patch("subprocess.Popen") as Popen:
            os.name = "nt"
            adb.raw_cmd(*args)
            Popen.assert_called_once_with(
                [adb.adb()] + args,
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )

        adb = Adb(adb_server_host="test.com", adb_server_port=1000)
        adb.adb = MagicMock()
        adb.adb.return_value = "adb"
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        args = ["a", "b", "c"]
        with patch("subprocess.Popen") as Popen:
            os.name = "posix"
            adb.raw_cmd(*args)
            Popen.assert_called_once_with(
                [" ".join([adb.adb()] + ["-H", "test.com", "-P", "1000"] + args)],
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE
            )
Пример #2
0
 def test_adb_cmd(self):
     adb = Adb()
     adb.device_serial = MagicMock()
     adb.device_serial.return_value = "ANDROID_SERIAL"
     adb.raw_cmd = MagicMock()
     args = ["a", "b", "c"]
     adb.cmd(*args)
     adb.raw_cmd.assert_called_once_with("-s", adb.device_serial(), *args)
Пример #3
0
    def test_device_serial(self):
        with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device"}
            self.assertEqual(adb.device_serial(), "ABCDEF123456")
        with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
            self.assertEqual(adb.device_serial(), "ABCDEF123456")
        with patch.dict('os.environ', {'ANDROID_SERIAL': "HIJKLMN098765"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
            with self.assertRaises(EnvironmentError):
                adb.device_serial()
        with patch.dict('os.environ', {}, clear=True):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device", "123456ABCDEF": "device"}
            with self.assertRaises(EnvironmentError):
                adb.device_serial()
        with patch.dict('os.environ', {}, clear=True):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device"}
            print(adb.devices())
            self.assertEqual(adb.device_serial(), "ABCDEF123456")

        with self.assertRaises(EnvironmentError):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {}
            adb.device_serial()
Пример #4
0
    def test_adb_cmd(self):
        adb = Adb()
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-s", "%s" % adb.device_serial(),
                                            *args)

        adb.device_serial.return_value = "ANDROID SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-s", "'%s'" % adb.device_serial(),
                                            *args)
Пример #5
0
class adb(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        self.instAdb=Adb()
        
        self.devSerialNoms= self.instAdb.devices().keys()
        self.devcount = len(self.devSerialNoms)
        self.devSerial = self.instAdb.device_serial()
        
        
    def getSerials(self):
        return self.devSerialNoms
        #return self.devSerialNoms
    
    def getDeviceCount(self):
        return self.devcount
    
    def getSerial(self):
        return self.devSerial
Пример #6
0
    def test_adb_cmd_server_host(self):
        adb = Adb(adb_server_host="localhost", adb_server_port=5037)
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-H", "localhost", "-P", "5037", "-s", "%s" % adb.device_serial(), *args)

        adb = Adb(adb_server_host="localhost")
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-H", "localhost", "-s", "%s" % adb.device_serial(), *args)
Пример #7
0
    def test_serial(self):
        serial = "abcdef1234567890"
        adb = Adb(serial)
        self.assertEqual(adb.default_serial, serial)

        adb.devices = MagicMock()
        adb.devices.return_value = [serial, "123456"]
        self.assertEqual(adb.device_serial(), serial)
Пример #8
0
    def test_serial(self):
        serial = "abcdef1234567890"
        adb = Adb(serial)
        self.assertEqual(adb.default_serial, serial)

        adb.devices = MagicMock()
        adb.devices.return_value = [serial, "123456"]
        self.assertEqual(adb.device_serial(), serial)
Пример #9
0
    def test_adb_cmd_server_host(self):
        adb = Adb(adb_server_host="localhost", adb_server_port=5037)
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-H", "localhost", "-P", "5037",
                                            "-s", "%s" % adb.device_serial(),
                                            *args)

        adb = Adb(adb_server_host="localhost")
        adb.device_serial = MagicMock()
        adb.device_serial.return_value = "ANDROID_SERIAL"
        adb.raw_cmd = MagicMock()
        args = ["a", "b", "c"]
        adb.cmd(*args)
        adb.raw_cmd.assert_called_once_with("-H", "localhost", "-s",
                                            "%s" % adb.device_serial(), *args)
Пример #10
0
    def test_device_serial(self):
        with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device"}
            self.assertEqual(adb.device_serial(), "ABCDEF123456")
        with patch.dict('os.environ', {'ANDROID_SERIAL': "ABCDEF123456"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {
                "ABCDEF123456": "device",
                "123456ABCDEF": "device"
            }
            self.assertEqual(adb.device_serial(), "ABCDEF123456")
        with patch.dict('os.environ', {'ANDROID_SERIAL': "HIJKLMN098765"}):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {
                "ABCDEF123456": "device",
                "123456ABCDEF": "device"
            }
            with self.assertRaises(EnvironmentError):
                adb.device_serial()
        with patch.dict('os.environ', {}, clear=True):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {
                "ABCDEF123456": "device",
                "123456ABCDEF": "device"
            }
            with self.assertRaises(EnvironmentError):
                adb.device_serial()
        with patch.dict('os.environ', {}, clear=True):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {"ABCDEF123456": "device"}
            print(adb.devices())
            self.assertEqual(adb.device_serial(), "ABCDEF123456")

        with self.assertRaises(EnvironmentError):
            adb = Adb()
            adb.devices = MagicMock()
            adb.devices.return_value = {}
            adb.device_serial()
Пример #11
0
class adb(object):
    '''
    classdocs
    '''
    def __init__(self):
        '''
        Constructor
        '''
        self.instAdb = Adb()

        self.devSerialNoms = self.instAdb.devices().keys()
        self.devcount = len(self.devSerialNoms)
        self.devSerial = self.instAdb.device_serial()

    def getSerials(self):
        return self.devSerialNoms
        #return self.devSerialNoms

    def getDeviceCount(self):
        return self.devcount

    def getSerial(self):
        return self.devSerial
Пример #12
0
class AutomatorServer(uiautomator.AutomatorServer, object):
    """start and quit rpc server on device.
    """
    __jar_files = {
        "bundle.jar": "libs/bundle.jar",
        "uiautomator-stub.jar": "libs/uiautomator-stub.jar"
    }
    handlers = NotFoundHandler()  # handler UI Not Found exception

    def __init__(self, serial=None, local_port=None):
        self.uiautomator_process = None
        self.adb = Adb(serial=serial)
        self.device_port = 9008
        if local_port:
            self.local_port = local_port
        else:
            try:  # first we will try to use the local port already adb forwarded
                for s, lp, rp in self.adb.forward_list():
                    if s == self.adb.device_serial(
                    ) and rp == 'tcp:%d' % self.device_port:
                        self.local_port = int(lp[4:])
                        break
                else:
                    self.local_port = next_local_port()
            except:
                self.local_port = next_local_port()

    @property
    def jsonrpc(self):
        server = self
        ERROR_CODE_BASE = -32000

        def _JsonRPCMethod(url, method, timeout, restart=True):
            _method_obj = JsonRPCMethod(url, method, timeout)

            def wrapper(*args, **kwargs):
                URLError = urllib3.exceptions.HTTPError if os.name == "nt" else urllib2.URLError
                try:
                    return _method_obj(*args, **kwargs)
                except (URLError, socket.error, HTTPException) as e:
                    if restart:
                        server.stop()
                        server.start()
                        return _JsonRPCMethod(url, method, timeout,
                                              False)(*args, **kwargs)
                    else:
                        raise
                except JsonRPCError as e:
                    if e.code >= ERROR_CODE_BASE - 2:
                        server.stop()
                        server.start()
                        print "i am here & do something in this place will work!"
                        Exception_analyze.analysis_crash()
                        return _method_obj(*args, **kwargs)
                    raise

            return wrapper

        return JsonRPCClient(self.rpc_uri,
                             timeout=int(os.environ.get("JSONRPC_TIMEOUT",
                                                        90)),
                             method_class=_JsonRPCMethod)
Пример #13
0
from uiautomator import Device, Adb, AutomatorDevice
from Libs import SaveToLog as saveLog
from Libs import ModelInfo
import Libs.ClsKeyCode


instAdb=Adb()
devSerials= instAdb.devices().keys()
print(type(devSerials))
osType = sys.platform
sndLog = saveLog()

#sndLog = CLS("test", "test")

if len(devSerials) == 1:
    devSerials = instAdb.device_serial()
    mstrDevice = Device(devSerials)
    mstrInfo = mstrDevice.info
else:
    mstrDevSerial, slavDevSerial = devSerials
    mstrDevice = Device(mstrDevSerial)
    slvDevice = Device(slavDevSerial)
    mstrInfo = mstrDevice.info
    slvInfo = slvDevice.info

sndLog.SendToLog("start")

modinfo = ModelInfo(mstrInfo)