Exemple #1
0
    def __init__(self,
                 file=None,
                 main_column_key=None,
                 custom_parser=None,
                 capture_screenshot='Always',
                 manually_test=False,
                 validate_data_only=False):
        """ExcelDataDriver can be imported with several optional arguments.

        - ``file``: Excel xlsx test data file.
        - ``main_column_key``: Excel column key name.
        - ``custom_parser``: Default will use 'DefaultParserStrategy'.
        - ``capture_screenshot``: Config capture screen shot strategy. Option (Always, OnFailed, Skip) Default (Always).
        - ``validate_data_only``: For only validate the data in the excel file should be valid

        Run ARGS:
        - ``OFFSET_ROW``: Start from test data row. (default is 0)
        - ``MAXIMUM_ROW``: Maximum test data row. (default is None)

        """
        self.ROBOT_LIBRARY_LISTENER = self
        self.file = file

        self.custom_parser = DefaultParserStrategy(main_column_key)
        if custom_parser is not None:
            CustomExcelParser = self.load_module(custom_parser)
            self.custom_parser = CustomExcelParser.CustomExcelParser(
                main_column_key)
        self.capture_screenshot_option = CaptureScreenShotOption[
            capture_screenshot]
        self.manually_test = manually_test
        if self.file is None:
            self.manually_test = True

        self.excelTestDataService = ExcelTestDataService()
        self.suite_source = None
        self.template_test = None
        self.template_keyword = None
        self.data_table = None
        self.excel_test_data_dict = {}
        self.index = None

        self.wb = None
        self.ws_test_datas = {}
        self.total_datas = []
        self.rerun_failed = True
        self.validate_data_only = validate_data_only

        self.screenshot_running_id = 0

        self.reference_data = dict()
Exemple #2
0
    def load_test_data(self, filename, main_column_key, data_type=None):
        """
        Load excel test data

        Arguments:
        |  filename (string)    |   The file name string value that will be used to open the excel file to perform tests upon. |
        |  data_type            |   Test data type [If data type is None will use DefaultParserStrategy]                       |

        Examples:
        | *Keywords*           |  *Parameters*                                      |
        | Open Excel           |  C:\\Python27\\XLSXRobotTest\\XLSXRobotTest.xlsx   |

        """
        if data_type is not None:
            CustomExcelParser = self.load_module(data_type)
            custom_parser = CustomExcelParser.CustomExcelParser(
                main_column_key)
            self.excelTestDataService.load_test_data(filename, custom_parser)
        else:
            self.excelTestDataService.load_test_data(
                filename, DefaultParserStrategy(main_column_key))
Exemple #3
0
    def merged_excel_report(self,
                            main_column_key,
                            data_type='DefaultParserStrategy'):
        """
        Merged all test data from report folder into summary_report.xlsx under summary_report_folder

        Arguments:
            | *data_type* | Test data type [ DefaultParserStrategy, CustomExcelParser ] default=DefaultParserStrategy |

        Example:
            | *Keywords*                        |  *Parameters*       |   *Parameters*      | *Parameters*      |
            | Merged Postcomrun Excel Report    |            	      |                     |                   |
            | Merged Postcomrun Excel Report    |  CustomExcelParser  |                     |                   |
        """
        print('Merged test report...')

        # - List all xlsx file under report_folder
        reports = list(
            glob.iglob(os.path.join(ExcelDataDriver.REPORT_PATH, '*.xlsx')))
        if len(reports) == 0:
            raise IOError('No report xlsx found under "' +
                          ExcelDataDriver.REPORT_PATH + '" folder')

        # - Read all test result
        print('-------------------------------------------------------')
        print('Initial ws test datas')
        summary_wb = OpenpyxlHelper.load_excel_file(reports[0],
                                                    data_only=False,
                                                    keep_vba=False)
        reports.pop(0)

        print('Init Parser')
        overall_test_status_is_pass = True
        summary_error_message = ''

        parser_strategy = DefaultParserStrategy(main_column_key)
        if data_type != 'DefaultParserStrategy':
            CustomExcelParser = self.load_module(data_type)
            parser_strategy = CustomExcelParser.CustomExcelParser()
        parser_context = ParserContext(parser_strategy)

        print('Parse wb')
        summary_wb_test_datas = parser_context.parse(summary_wb)
        for test_datas in summary_wb_test_datas.values():
            for test_data in test_datas:
                if test_data.is_fail():
                    overall_test_status_is_pass = False
                    summary_error_message += str(
                        test_data.get_log_message()) + '\r\n'

        for report in reports:
            print('Merged ws test datas : ' + report)
            wb = OpenpyxlHelper.load_excel_file(report,
                                                data_only=False,
                                                keep_vba=False)
            parser_context = ParserContext(parser_strategy)
            wb_test_datas = parser_context.parse(wb)

            for index_ws, ws_test_datas in enumerate(wb_test_datas.values()):
                for index_test_data, test_data in enumerate(ws_test_datas):
                    if test_data.is_not_run() is False:
                        list(list(summary_wb_test_datas.values())
                             [index_ws])[index_test_data].update_result(
                                 test_data.get_status(),
                                 test_data.get_log_message(),
                                 test_data.get_screenshot())
                        if test_data.is_fail():
                            overall_test_status_is_pass = False
                            summary_error_message += str(
                                test_data.get_log_message()) + '\r\n'
            wb.close()

        # Save the result to a new excel files.
        summary_file = os.path.join(ExcelDataDriver.REPORT_PATH,
                                    'summary_report.xlsx')
        summary_wb.save(summary_file)

        # - Return summary test result if have test failed
        if overall_test_status_is_pass is False:
            raise AssertionError(summary_error_message)
Exemple #4
0
 def __get_parser_based_on_data_type(self, data_type):
     return DefaultParserStrategy()