Exemple #1
0
def parse(filename, options=None):
    """
    Parse Selenium IDE - Test Results Plugin output files.

    """
    options = options or {}
    try:
        parsed_html = html.parse(filename)
    except html.HTMLSyntaxError:
        raise importer.ParserError('TEST invalid XML syntax')

    suite = parsed_html.find("//table[@id='suiteSummaryTable']/thead/tr/td")
    if suite is None:
        raise importer.ParserError('Test Suite not found')
    suite = suite.text
    if not suite.startswith(_SUITE_HEADER):
        raise importer.ParserError('invalid test results')
    # get suite name from 'Test Suite: <testname>'
    suitename = suite[len(_SUITE_HEADER) + 1:].strip()
    root = parsed_html.getroot()
    suitetbls = root.find_class('test_case')
    if suitetbls is None:
        raise importer.ParserError('no test cases found')

    return [_parse_test(tbl, suitename) for tbl in suitetbls]
Exemple #2
0
def _load_datatable(xls_path):
    if not os.path.isfile(xls_path):
        raise importer.ParserError('xls file not found: %s', xls_path)

    xls_book = xlrd.open_workbook(xls_path)
    xls_sheet = xls_book.sheet_by_name(_SHEET_NAME)
    return xls_sheet
Exemple #3
0
    def _parse_test_xls(row):
        diter = parsed_xml.find("//DIter[@iterID='{}']".format(row))
        if diter is None:
            raise importer.ParserError('diter was null')

        test = _get_col_value(xls_sheet, row, _test)
        subject = _get_col_value(xls_sheet, row, _subject)
        suite = _get_col_value(xls_sheet, row, _suite)
        description = _get_col_value(xls_sheet, row, _description)

        result = diter.find('./NodeArgs[@eType="StartIteration"]')
        status = result.attrib['status']
        status = status.replace('Warning', 'Passed')

        # get run duration
        summary = diter.find('.//Summary')
        start_time = summary.attrib['sTime']
        start_time = datetime.strptime(start_time, '%m/%d/%Y - %H:%M:%S')
        end_time = summary.attrib['eTime']
        end_time = datetime.strptime(end_time, '%m/%d/%Y - %H:%M:%S')
        test_duration = (end_time - start_time).total_seconds()
        test_duration = int(test_duration)

        test_exec_date = start_time.strftime('%Y-%m-%d')
        test_exec_time = start_time.strftime('%I:%M:%S %p')

        step_results = []
        steps = diter.xpath(_TEST_STEPS_QUERY)
        step_results = [_parse_step(step) for step in steps]

        return {
            'name': test,
            'subject': subject,
            'status': status,
            'suite': suite,
            'steps': step_results,
            'description': description,
            'exec_date': test_exec_date,
            'exec_time': test_exec_time,
            'duration': test_duration
        }
Exemple #4
0
def _parse_test(tbl, suitename):
    testhead = tbl.xpath("./thead/tr/td")[0].text
    if not testhead.startswith(_TEST_HEADER):
        raise importer.ParserError('invalid test')
    test_name = testhead[len(_TEST_HEADER):]
    rows = tbl.xpath(".//tr")
    test_steps = []
    test_status = 'Passed'
    for row in rows[1:]:
        step = _parse_step(row)
        if step['status'] == 'Failed':
            test_status = 'Failed'
        test_steps.append(step)

    return {
        'name': test_name,
        'subject': '',
        'status': test_status,
        'suite': suitename,
        'steps': test_steps,
        'description': ''
    }
Exemple #5
0
def parse(filename, options=None):
    """
    The UFT Parser.

    Versions tested to work:
     * 12.52
     * 12.53
    """
    options = options or {}
    try:
        parsed_xml = etree.parse(filename)
    except etree.XMLSyntaxError:
        raise importer.ParserError('invalid XML syntax')

    xls_filename = _get_xls_filename(parsed_xml)
    if not xls_filename:
        raise importer.ParserError('did not find xls_filename_node')

    xls_path = os.path.join(os.path.dirname(filename), xls_filename)
    xls_sheet = _load_datatable(xls_path)
    xls_rows = xls_sheet.nrows

    _description = options.get('description_column', 'description')
    _suite = options.get('suite_column', 'suite')
    _subject = options.get('subject_column', 'subject')
    _test = options.get('test_column', 'test')

    def _parse_test_xls(row):
        diter = parsed_xml.find("//DIter[@iterID='{}']".format(row))
        if diter is None:
            raise importer.ParserError('diter was null')

        test = _get_col_value(xls_sheet, row, _test)
        subject = _get_col_value(xls_sheet, row, _subject)
        suite = _get_col_value(xls_sheet, row, _suite)
        description = _get_col_value(xls_sheet, row, _description)

        result = diter.find('./NodeArgs[@eType="StartIteration"]')
        status = result.attrib['status']
        status = status.replace('Warning', 'Passed')

        # get run duration
        summary = diter.find('.//Summary')
        start_time = summary.attrib['sTime']
        start_time = datetime.strptime(start_time, '%m/%d/%Y - %H:%M:%S')
        end_time = summary.attrib['eTime']
        end_time = datetime.strptime(end_time, '%m/%d/%Y - %H:%M:%S')
        test_duration = (end_time - start_time).total_seconds()
        test_duration = int(test_duration)

        test_exec_date = start_time.strftime('%Y-%m-%d')
        test_exec_time = start_time.strftime('%I:%M:%S %p')

        step_results = []
        steps = diter.xpath(_TEST_STEPS_QUERY)
        step_results = [_parse_step(step) for step in steps]

        return {
            'name': test,
            'subject': subject,
            'status': status,
            'suite': suite,
            'steps': step_results,
            'description': description,
            'exec_date': test_exec_date,
            'exec_time': test_exec_time,
            'duration': test_duration
        }

    test_results = [_parse_test_xls(r) for r in range(1, xls_rows)]

    return test_results
Exemple #6
0
def _get_col_value(xls_sheet, row, col_name):
    for col_index in range(xls_sheet.ncols):
        if xls_sheet.cell(0, col_index).value == col_name:
            return xls_sheet.cell(row, col_index).value
    raise importer.ParserError('column not found: {}'.format(col_name))