def save_report(self, newfile=None):
     if newfile is None:
         newfile = self.fileName
     OpenpyxlHelper.save_excel_file(newfile, self.wb)
     self.wb = None
     self.ws_test_datas = {}
     ExcelTestDataService.select_test_data = None
Example #2
0
 def save_report(self, newfile=None):
     if newfile is None:
         newfile = self.fileName
     OpenpyxlHelper.save_excel_file(newfile, self.wb)
     self.wb = None
     self.ws_test_datas = {}
     CoreExcelKeywords.select_test_data = None
Example #3
0
    def load_reference_data(
            self,
            alias_name,
            filename,
            main_column_key,
            custom_parser_module='ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy',
            custom_parser_class='DefaultReferenceParserStrategy'):
        """
        Load reference data with specific Parser

        Arguments:
        |  alias_name           |   alias_name for refer to the reference data |
        |  filename (string)    |   The file name string value that will be used to open the excel file to perform tests upon. |
        |  main_column_key      |   Identify unique key for use as reference when parse the data |
        |  custom_parser_module |   Test data parser module is ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy |
        |  custom_parser_class  |   Test data parser class is DefaultReferenceParserStrategy |
        """
        reference_wb = OpenpyxlHelper.load_excel_file(filename)
        CustomExcelParser = getattr(
            importlib.import_module(custom_parser_module), custom_parser_class)
        # CustomExcelParser = __import__(custom_parser_module)
        # parser_context = ParserContext(CustomExcelParser.CustomExcelBreakdownParser())
        parser_context = ParserContext(CustomExcelParser(main_column_key))
        references_data_sheets = parser_context.parse(reference_wb)
        reference_row_data = []
        for sheet_name in references_data_sheets:
            reference_row_data += references_data_sheets[sheet_name]
        self.reference_data[alias_name] = {
            'selected': None,
            'data': reference_row_data
        }
        reference_wb.close()
Example #4
0
 def auto_insert_extra_columns(
         self,
         filename,
         main_column_key,
         columns=[],
         custom_parser_module='ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy',
         custom_parser_class='DefaultReferenceParserStrategy'):
     reference_wb = OpenpyxlHelper.load_excel_file(filename)
     CustomExcelParser = getattr(
         importlib.import_module(custom_parser_module), custom_parser_class)
     parser_context = ParserContext(CustomExcelParser(main_column_key))
     parser_context.insert_extra_columns(reference_wb, columns)
     reference_wb.save(filename)
    def load_test_data(self, filename, custom_parser):
        """
        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 [Default=DefaultParserStrategy]                                             |

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

        """
        self.fileName = filename
        self.custom_parser = custom_parser

        self.ws_test_datas = {}
        self.total_datas = []
        self.wb = OpenpyxlHelper.load_excel_file(self.fileName)
        ExcelTestDataService.parser_strategy = custom_parser
        self.parser_context = ParserContext(
            ExcelTestDataService.parser_strategy)
        self.ws_test_datas = self.parser_context.parse(self.wb)
Example #6
0
    def load_reference_data(
            self,
            alias_name,
            filename,
            custom_parser_module='ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy',
            custom_parser_class='DefaultReferenceParserStrategy'):
        """
        Load reference data with specific Parser

        Arguments:
        |  alias_name           |   alias_name for refer to the reference data |
        |  filename (string)    |   The file name string value that will be used to open the excel file to perform tests upon. |
        |  custom_parser_module |   Test data parser module is ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy |
        |  custom_parser_class  |   Test data parser class is DefaultReferenceParserStrategy |
        """
        reference_wb = OpenpyxlHelper.load_excel_file(filename)
        CustomExcelParser = self._load_customer_class_from_module(
            custom_parser_module, custom_parser_class)
        parser_context = ParserContext(CustomExcelParser())
        self.reference_data[alias_name] = {
            'selected': None,
            'data': parser_context.parse(reference_wb)
        }
        reference_wb.close()
Example #7
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)