def push_result() -> None:
    """Push result.

    This function pushes execution result to report sever.

    Returns
    -------
    None
    """
    server_meta_data = dict()
    with open(inter_path().report_server_info) as data:
        server_meta_data = load(data)
    server_address = server_meta_data['server_address']
    send_results_endpoint = server_meta_data['send-results_api_endpoint']

    result_dir = inter_path().current_allure_result_folder
    result_files = listdir(result_dir)

    results = list()
    for file in result_files:
        result = dict()

        file_path = f'{result_dir}/{file}'
        if path.isfile(file_path):
            try:
                with open(file_path, 'rb') as file_obj:
                    content = file_obj.read()
                    if content.strip():
                        base64_content = base64.b64encode(content)
                        result['file_name'] = file
                        result['content_base64'] =\
                            base64_content.decode('UTF-8')
                        results.append(result)
                    else:
                        print('Empty file skipped: ' + file_path)
            finally:
                file_obj.close()
        else:
            print('Directory skipped: ' + file_path)

    headers = {'Content-type': 'application/json'}
    request_body = {'results': results}
    json_request_body = dumps(request_body)

    print(f'{server_address}{send_results_endpoint}')

    response =\
        post(f'{server_address}{send_results_endpoint}',
             headers=headers, data=json_request_body)

    # print('RESPONSE:')
    # json_response_body = loads(response.content)
    # json_prettier_response_body =\
    #     dumps(json_response_body, indent=4, sort_keys=True)
    # print(json_prettier_response_body)
    print('STATUS CODE:')
    print(response.status_code)
def run_allure_report_server() -> None:
    """Run Allure report server.

    This function run Allure server with the latest log information.

    Returns
    -------
    None
    """
    run([
        inter_path().allure_bin, 'open',
        inter_path().current_allure_report_folder
    ])
    return
def generate_allure_report() -> None:
    """Generate Allure report.

    This function generates Allure report from Allure result.

    Returns
    -------
    None
    """
    run([
        inter_path().allure_bin, 'generate',
        inter_path().current_allure_result_folder, '--output',
        inter_path().current_allure_report_folder
    ])
    return
Пример #4
0
def generate_docs_folder(module_name: str, test_design: str,
                         version: str) -> None:
    """Generate folder for documentation.

    This function generates folder that stores documentations before generate
    document files.

    The folder structure are classified by:
        workspace/{date}/{module}/{version}/{current_time}-{test_design}

    Parameters
    ----------
    module_name : str
        Module name {mobile_app, web_portal, rest_api}
    test_design : str
        Test suite specification domain
    version : str
        Version of documentations

    Returns
    -------
    None
    """
    today = datetime.now().strftime("%Y-%m-%d")
    current_time = datetime.now().strftime("%H-%M-%S")
    doc_path = inter_path().document_folder

    today_doc_folder = f'{doc_path}/{today}'
    module_doc_folder = f'{today_doc_folder}/{module_name}'
    version_doc_folder = f'{module_doc_folder}/{version}'
    executing_doc_folder = f'{version_doc_folder}/{current_time}-{test_design}'

    if not path.exists(doc_path):
        mkdir(doc_path)
    if not path.exists(today_doc_folder):
        mkdir(today_doc_folder)
    if not path.exists(module_doc_folder):
        mkdir(module_doc_folder)
    if not path.exists(version_doc_folder):
        mkdir(version_doc_folder)
    if not path.exists(executing_doc_folder):
        mkdir(executing_doc_folder)

    # update path to InternalPath instance attribute.
    inter_path().current_doc_folder = executing_doc_folder

    return
Пример #5
0
def generate_logs_folder(module_name: str, test_design: str) -> None:
    """Create and return path of folder that stores log files.

    This function takes the timestamp when test cases are run, then create
    directories to store log files. The directories are classified by Module,
    TDS.

    The structure of generated folders:
        workspace/{today}/{module}/{test_design}-{current_time}

    Parameters
    ----------
    module_name : str
        The name of module to be tested {REST, web, app}.
    test_design : str
        Test Domain Specification.

    Returns
    -------
    None
    """
    today = datetime.now().strftime("%Y-%m-%d")
    current_time = datetime.now().strftime("%H-%M-%S")
    logs_path = inter_path().logs_folder

    today_log_folder = f'{logs_path}/{today}'
    module_log_folder = f'{today_log_folder}/{module_name}'
    executing_log_folder = f'{module_log_folder}/{current_time}-{test_design}'
    robot_report_folder = f'{executing_log_folder}/robot'
    allure_report_folder = f'{executing_log_folder}/allure-report'
    allure_result_folder = f'{executing_log_folder}/allure-results'
    screenshot_folder = f'{executing_log_folder}/screenshots'

    if not path.exists(logs_path):
        mkdir(logs_path)
    if not path.exists(today_log_folder):
        mkdir(today_log_folder)
    if not path.exists(module_log_folder):
        mkdir(module_log_folder)
    if not path.exists(executing_log_folder):
        mkdir(executing_log_folder)
        mkdir(robot_report_folder)
        mkdir(allure_report_folder)
        mkdir(allure_result_folder)
        mkdir(screenshot_folder)
        create_empty_file(f'{robot_report_folder}/syslog.txt')

    # update path to InternalPath instance attribute.
    inter_path().current_allure_result_folder = allure_result_folder
    inter_path().current_allure_report_folder = allure_report_folder
    inter_path().current_robot_report_folder = robot_report_folder
    inter_path().current_log_folder = executing_log_folder
    inter_path().current_screenshot_folder = screenshot_folder
    inter_path().current_syslog_robot_path =\
        f'{robot_report_folder}/syslog.txt'

    return
Пример #6
0
def set_android_home_env_var() -> None:
    """Set Android home environ variable.

    This function set value for ANDROID_HOME to specify Android SDK directory.

    Returns
    -------
    None
    """
    environ['ANDROID_HOME'] = inter_path().android_sdk_dir
    environ['JAVA_HOME'] = '/usr/lib/jvm/java-8-openjdk-amd64'
    return
Пример #7
0
def set_python_path_env_var() -> None:
    """Setup Python path environment variable.

    This function setup PYTHONPATH environment variable that's used for
    robot file to understand the import libraries in entire project.

    Returns
    -------
    None
    """
    environ['PYTHONPATH'] = inter_path().workspace_path
    return
Пример #8
0
def set_robot_syslog_file_env_var() -> None:
    """Set Robot syslog file environ variable.

    This function set value for ROBOT_SYSLOG_FILE environ variable to specify
    path of robot syslog file, that will store log of system when running
    robot.

    Returns
    -------
    None
    """
    environ['ROBOT_SYSLOG_FILE'] = inter_path().current_syslog_robot_path
    return
def log_current_executor(logger: CustomLogger) -> None:
    """Log current executor's info.

    This function helps to log current tester, who executes the test case.

    Parameters
    ----------
    logger : CustomLogger

    Returns
    -------
    None
    """
    current_user = getuser()
    current_dir = inter_path().workspace_path
    logger.info(f'Test case ' +
                f'is conducted by: {current_user}')
    logger.info(f'Workspace locates at {current_dir}')
    logger.info(f'========== Test Case Begins ==========')
def run_android_emulator(name: str) -> Popen:
    """Run Android emulator.

    Run an Android emulator base on provided name.

    Returns
    -------
    Popen
        Android emulator session.
    """
    list_param = [
        inter_path().android_emulator_bin, '-avd', name, '-noaudio',
        '-no-boot-anim', '-no-window'
    ]
    if getuser() != 'root':
        list_param.insert(0, 'sudo')
        list_param.insert(1, '-E')
    emulator_session = Popen(list_param)
    sleep(10)
    return emulator_session