Esempio n. 1
0
def get_response_file(testdatafile):
    """
        Build the response dict with response tag name and response text
    """
    from Framework.Utils.xml_Utils import getRoot, getElementListWithSpecificXpath
    tmp_list = getElementListWithSpecificXpath(testdatafile, "./global/response_file")
    response_file = tmp_list[0].text if tmp_list != [] else ""
    response_dict = {}
    cmd_specific_response_dict = {}
    if response_file != "":
        root = getRoot(response_file)
        # Parse global responses
        responses = root.find("responses")
        if responses is not None:
            for resp in responses:
                resp_name = resp.tag
                resp_text = resp.get("text", "")
                if resp_name in response_dict:
                    pNote("A response with tag name {} has been created before with value: {}"
                          "Please rename with a different tag name".\
                          format(resp_name, response_dict[resp_name]))
                else:
                    response_dict[resp_name] = resp_text
        else:
            pNote("Unable to find responses, please put all responses inside a responses tag",
                  "ERROR")
        # Parse cmd specific responses
        cmd_specific_response_dict = get_cmd_specific_response_file(root)
    else:
        pNote("Unable to retrieve response file from testdata file, please put the path in"
              " response_file tag inside global section of the testdata file", "ERROR")

    MockUtils.cli_Utils.response_dict = response_dict
    MockUtils.cli_Utils.cmd_specific_response_dict = cmd_specific_response_dict
def get_results_from_robot_xml(input_list):
    """
    Get the tests(and setup/teardown) executed by robot from the robot result xml file
    :Arguments:
        1. input_list(list) - Robot result xml files
    :Return:
        1. robot_tests(list) - Robot test xml elements
    """

    robot_tests = []
    for xml_file in input_list:
        suites = xml_Utils.getElementListWithSpecificXpath(xml_file, './/suite[@source]')
        for suite in suites:
            tests = suite.getchildren()
            for test in tests:
                if test.tag == "test" or test.tag == "kw":
                    robot_tests.append(test)
    return robot_tests
Esempio n. 3
0
def smart_analyze(prompt, testdatafile=None):
    """
        retrieve the correspond smart testdata file for smart cmd
        from either Tools/connection or testcase testdata file
        :param prompt:
            The string that will be analyzed in order to find the device system
        :param testdatafile:
            optional arg to provide a pre-defined device system in the test datafile
        :return:
            the smart datafile that contains the smart cmd to be sent
    """
    system_name = None

    if testdatafile is not None:
        # when the testdatafile is a dictionary - this happens only when
        # the testdatafile is taken from database server
        if isinstance(testdatafile, dict):
            db_td_obj = database_utils_class.\
             create_database_connection('dataservers', testdatafile.get('td_system'))
            root = db_td_obj.get_tdblock_as_xmlobj(testdatafile)
            db_td_obj.close_connection()
        else:
            root = xml_Utils.getRoot(testdatafile)
        system_name = data_Utils._get_global_var(root, "system_name")

    con_settings_dir = Tools.__path__[0] + os.sep + 'connection' + os.sep
    con_settings = con_settings_dir + "connect_settings.xml"

    if system_name is not None:
        sys_elem = xml_Utils.getElementWithTagAttribValueMatch(
            con_settings, "system", "name", system_name.text)
        if sys_elem is None or sys_elem.find("testdata") is None:
            return None
    else:
        system_list = xml_Utils.getElementListWithSpecificXpath(
            con_settings, "system[search_string]")
        for sys_elem in system_list:
            if sys_elem.find("search_string").text in prompt and sys_elem.find(
                    "testdata") is not None:
                return con_settings_dir + sys_elem.find("testdata").text
        return None

    return con_settings_dir + sys_elem.find("testdata").text