import os
import time


# 捕获验证码
def get_validate_code(self):
    cmd_c = 'adb logcat -c'
    os.popen(cmd_c)
    for i in range(30):
        try:
            cmd_d = 'adb logcat -d | findstr codeString'
            value = os.popen(cmd_d).read()
            code = value.split('验证码：')[1].split('，')[0]
            break
        except:
            pass
        time.sleep(1)
    else:
        raise ValueError
    return code


# app running log
def get_app_log(name):
    # cmd_log = "adb logcat -c && adb logcat > " + get_app_log_dir(name)
    # os.popen(cmd_log)
    pass


def save_log(log):
    pass


# 保存截图地址
def get_screenshot_dir(name):
    return set_file_path('images/') + name + '.png'


# 保存app运行日志地址
def get_app_log_dir(name):
    return set_file_path('appLogs/') + name + '.log'


# 保存case运行日志地址
def get_case_log_dir(name):
    return set_file_path('caseLogs/') + name + '.log'


# 保存appium运行日志地址
def get_appium_log_dir(name):
    return set_file_path('appiumLogs/') + name + '.log'


# 获取配置地址
def get_config_dir():
    return set_file_path('configs/')


# 获取绝对地址
def get_dir_by_name(name):
    return set_file_path(name + '/')


# 保存报告地址
def get_report_dir():
    return set_file_path('reports/')


def get_project_path():
    return os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir))


def set_file_path(pathname):
    par_dir = get_project_path()

    return os.path.join(par_dir, pathname)
