Example #1
0
def run_test(instances):


    """
    adb
     -s
     192.168.56.101:5555
     shell
     am
     instrument
     -w
     -e
     class
     com.example.android.notepad.NotePadTest com.example.android.notepad.test/android.test.InstrumentationTestRunner
    :return:
    """

    for instance in instances:
        adb = config.config_file_reader('adb')
        directory = config.config_file_reader('directory')
        #print(adb)
        apk = config.config_file_reader('apk')
        #print(directory + apk)
        test_class = config.config_file_reader('test_class')
        test_method = config.config_file_reader('test_method')
        #print(test_method)
        print(subprocess.check_output([adb, '-s', 'emulator-'+instance.port, 'shell', 'am','instrument', '-w', '-r', '-e', 'debug', 'false','-e','class', test_class, test_method]))
Example #2
0
def instances_manager():
    adb = config.config_file_reader('adb')
    adb_devices = str(subprocess.check_output([adb, 'devices']))
    # print(adb_devices)
    adb_devices = adb_devices.split('\n')
    # print(adb_devices)
    adb_devices = adb_devices[1:]
    # print(adb_devices)
    emulator_ports = []
    emulators = []
    for adb_device in adb_devices:
        emulator_port = adb_device.split('\t')[:1][0][9:]
        # print ("hello")
        # print adb_device.split('\t')[:1][0][9:]
        if (len(emulator_port) > 3):
            emulator_ports.append(emulator_port)
            # pid = str(subprocess.check_output(['netstat', '-tulpn' ,'|', 'grep', emulator_port]))[9:]
            # print(emulator_port, len(emulator_port), pid)
            # print(emulator_port)
            pid = str(
                subprocess.check_output(['lsof', '-i', 'tcp:' + emulator_port
                                         ])).split('\n')[1:][0].split(' ')[1]
            # print(pid)
            device_details_in_ps = str(subprocess.check_output(['ps', pid]))
            # print (device_details_in_ps)
            model = get_device_emulator_model(device_details_in_ps)
            # print(model)

            current_emulator = Emulator(emulator_port, pid, model)
            emulators.append(current_emulator)
            # print(current_emulator)
    return emulators
Example #3
0
def create_emulator():
    android = config.config_file_reader('android')
    target_id = 5
    emulator_create = subprocess.Popen([
        android, 'create', 'avd', '-n', context_list['emulator_name'], '-t',
        str(target_id), '-b', context_list['abi']
    ],
                                       stdin=subprocess.PIPE)
    stri = str('n').encode('utf-8')
    emulator_create.stdin.write(stri)
    return emulator_create
Example #4
0
 def get_running_avd_port():
     adb = config.config_file_reader('adb')
     adb_devices = str(subprocess.check_output([adb, 'devices']))
     adb_devices = adb_devices.split('\n')
     adb_devices = adb_devices[1:]
     emulator_ports = []
     for adb_device in adb_devices:
         emulator_port = adb_device.split('\t')[:1][0][9:]
         if (len(emulator_port) > 3):
             emulator_ports.append(emulator_port)
     return "emulator_ports"
Example #5
0
def app_installer(emulator_instances):
    # print emulator_instances
    adb = config.config_file_reader('adb')
    directory = config.config_file_reader('directory')
    #print(adb)
    apk = config.config_file_reader('apk')
    #print(directory + apk)
    installed_app_port = {}
    for instance in emulator_instances:
        #print instance
        emulator_port = instance.port
        if (emulator_port not in installed_app_port):
            # string = "app is not there"
            string = subprocess.check_output([
                adb, '-s', 'emulator-' + emulator_port, 'install',
                directory + apk
            ])
            installed_app_port.update({emulator_port: apk})
            print(string)

        else:
            print("app is there")
Example #6
0
 def check_emulator_running():
     adb = config.config_file_reader('adb')
     adb_devices = str(subprocess.check_output([adb, 'devices']))
     adb_devices = adb_devices.split('\n')
     adb_devices = adb_devices[1:]
     emulator_ports = []
     for adb_device in adb_devices:
         emulator_port = adb_device.split('\t')[:1][0][9:]
         if (len(emulator_port) > 3):
             emulator_ports.append(emulator_port)
     if not emulator_ports:
         emulator_state = 0
     else:
         emulator_state = 1
     return emulator_state
Example #7
0
def emulator_runner():
    print(context_list['emulator_name'])

    # adb = config.config_file_reader('adb')
    # p = subprocess.Popen([adb,'start-server'])

    # avds = check_running_avd()
    # if avds:
    #     emulator_port = get_running_avd_port()
    #     if emulator_port:
    #         emulator_port = int(emulator_port[-1]) + 2
    #     else:
    emulator_port = 5555
    # print(emulator_port)
    #
    # The console port number must be an even integer between 5554 and 5584,
    # inclusive. <port>+1 must also be free and will be reserved for ADB.

    #########################################################
    # for name in avds:
    #     print(name)
    command = config.config_file_reader("emulator")
    # command_argument = " -avd " + name
    #     print(command_argument)
    #     print(command + command_argument)
    current_process = subprocess.Popen([
        command, '-port',
        str(emulator_port), '-avd', context_list['emulator_name']
    ],
                                       stdout=subprocess.PIPE)
    # print(current_process.pid, emulator_port)
    check = check_avd_botted_completely(emulator_port)
    if check == 1:
        print(context_list['emulator_name'] + " has booted cpmpletely")
        flag = True
        return flag
    else:
        print(context_list['emulator_name'] + " has not booted cpmpletely")
        flag = False
        return flag
Example #8
0
def check_avd_botted_completely(emulator_port):
    port = "emulator-"
    port = port + str(emulator_port)

    adb = config.config_file_reader('adb')
    print(port)
    print("going to sleep")
    time.sleep(20)
    i = 0
    while (True):
        check = str(
            subprocess.check_output(
                [adb, '-s', port, 'shell', 'getprop', 'sys.boot_completed']))
        check = check.strip('b\'')
        check = check.strip('\\r')
        check = check.strip('\\n')
        check = check.strip()
        print(check)
        if check == "1":
            print("completed")
            return 1
        time.sleep(2)
        i = i + 1
        print("wait" + str(i))
Example #9
0
def kill_emulator():
    android = config.config_file_reader('android')
    process = subprocess.Popen(
        [android, 'delete', 'avd', '-n', context_list['emulator_name']])
Example #10
0
def get_avd_list():
    command = config.config_file_reader('emulator')
    avd = str(subprocess.check_output([command, 'emulator', '-list-avds']))
    avd = avd.split('\n')
    avd.pop(-1)
    return avd