Exemplo n.º 1
0
def devices_list():
    detected_devices = subprocess.Popen('adb devices',
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        shell=True).stdout.read()
    detected_devices = detected_devices.decode()
    detected_devices = re.split('[\n\r]', detected_devices)
    detected_devices.remove("List of devices attached")
    while "" in detected_devices:
        detected_devices.remove("")
    duts = list()
    console_out("\nADB connection details:")
    for dev in detected_devices:
        dev = dev.split("\t")
        if dev[-1] == "device":
            duts.append(dev[0])
            print(
                "Device %s connected successfully, manufacturer: %s, model: %s, android version: %s."
                % (dev[0], manufacturer(dev[0]), model(
                    dev[0]), android_version(dev[0])))
        if dev[-1] == "offline":
            print(
                "Device %s is offline, please check device status and reconnect it."
                % dev[0])
        if dev[-1] == "unauthorized":
            print(
                "Device %s is unauthorized, please reconnect it and allow the USB debug permission."
                % dev[0])
    print("Total %s devices detected, %s devices online" %
          (str(len(detected_devices)), str(len(duts))))
    return duts
Exemplo n.º 2
0
def kill_jar(jar_name):
    jar_running = subprocess.Popen("jps -mlv | grep " + jar_name,
                                   stdout=subprocess.PIPE,
                                   shell=True).stdout.read()
    try:
        jar_pid = (jar_running.split()[0]).decode()
        subprocess.Popen("kill " + jar_pid, shell=True)
    except IndexError:
        console_out(jar_name + " is not running.")
Exemplo n.º 3
0
def init_selenium_server(start_time):
    save_log = create_server_log_dir(start_time) + "selenium_server_" + \
               time.strftime('%Y.%m.%d_%H-%M-%S', time.localtime()) + ".log"
    with open(
            create_temp_dir(create_time) + "selenium_running_output.log",
            "w") as file:
        subprocess.Popen(
            "java -jar ./libs/selenium-server-standalone-3.10.0.jar -port 4444 -role hub -log "
            + save_log,
            stdout=file,
            stderr=None,
            shell=True)
    console_out("Selenium server started, log saved in %s" % save_log)
Exemplo n.º 4
0
def start_appium_server(device_id, i, start_time):
    port = 4500 + i * 10
    bootstrap_port = port + 1
    node_json_create(start_time, device_id, "127.0.0.1", str(port))
    save_node_json = create_node_json_dir(start_time) + device_id + '.json'
    save_log = \
        create_appium_log_dir(start_time) + "appium_server_" + device_id + "_" + \
        time.strftime('%Y.%m.%d_%H-%M-%S', time.localtime()) + ".log"
    with open(
            create_temp_dir(create_time) + "appium_server_" + device_id +
            "_output.log", "w") as file:
        subprocess.Popen("appium --nodeconfig " + save_node_json + " -p " +
                         str(port) + " -bp " + str(bootstrap_port) + " -g " +
                         save_log,
                         stdout=file,
                         stderr=None,
                         shell=True)
    console_out("%s's appium server started, log saved in %s." %
                (device_id, save_log))
Exemplo n.º 5
0
def shutdown_servers():
    kill_jar('selenium')
    kill_process('node')
    console_out('Servers shutdown.')
Exemplo n.º 6
0
if __name__ == '__main__':
    create_time = time.strftime('%Y.%m.%d_%H-%M-%S', time.localtime())
    DUT_list = devices_list()
    is_ready = False
    while not is_ready:
        start_hint = "\nPlease check all the connections, press Y on the keyboard to start test, " \
                     "press R to restart connection check, press N to exit this test"
        start_input = input(start_hint).strip()
        if start_input.lower() == "y":
            is_ready = True
            kill_jar("selenium")
            kill_process('node')
            init_selenium_server(create_time)
            init_appium_server(create_time, DUT_list)
            console_out(
                "All appium server started, please wait 10s for test started.")
            time.sleep(10)
            console_out('Test started')
            runner_pool(create_time, DUT_list)
            shutdown_servers()
        elif start_input.lower() == "r":
            DUT_list = devices_list()
        elif start_input.lower() == "n":
            break
        else:
            print("Input wrong argument.")

    kill_jar('selenium')
    kill_process('node')