diff --git a/Examples/AutoAddTestDataColumnsExample.robot b/Examples/AutoAddTestDataColumnsExample.robot new file mode 100644 index 0000000..39b1655 --- /dev/null +++ b/Examples/AutoAddTestDataColumnsExample.robot @@ -0,0 +1,8 @@ +*** Setting *** +Library ExcelDataDriver + + +*** Test Cases *** +Add basic test result column + ${extra columns} = Create List [Status] [Log Message] [Screenshot] [Tags] + Auto Insert Extra Columns ./test_data/BasicNonTestResultColumnsMultipleSheet.xlsx username ${extra columns} diff --git a/Examples/test_data/BasicDemoData.xlsx b/Examples/test_data/BasicDemoData.xlsx index c611aab..876f213 100644 Binary files a/Examples/test_data/BasicDemoData.xlsx and b/Examples/test_data/BasicDemoData.xlsx differ diff --git a/Examples/test_data/BasicNonTestResultColumnsMultipleSheet.xlsx b/Examples/test_data/BasicNonTestResultColumnsMultipleSheet.xlsx new file mode 100644 index 0000000..6b06c74 Binary files /dev/null and b/Examples/test_data/BasicNonTestResultColumnsMultipleSheet.xlsx differ diff --git a/ExcelDataDriver/ExcelParser/ParserContext.py b/ExcelDataDriver/ExcelParser/ParserContext.py index 09a1414..cd759cc 100644 --- a/ExcelDataDriver/ExcelParser/ParserContext.py +++ b/ExcelDataDriver/ExcelParser/ParserContext.py @@ -29,5 +29,13 @@ def parse(self, wb): test_data_rows = self.parser_strategy.parse_test_data_properties(ws, ws_column_indexs) ws_test_data_rows[ws.title] = test_data_rows print('Done validate reference data') - return ws_test_data_rows + + def insert_extra_columns(self, wb, columns): + for ws in list(wb): + ws_column_indexs = self.parser_strategy.parsing_column_indexs(ws) + for column in reversed(columns): + if column in ws_column_indexs: + continue + ws.insert_cols(1) + ws['A' + str(self.parser_strategy.start_row)] = column diff --git a/ExcelDataDriver/__init__.py b/ExcelDataDriver/__init__.py index ac080fd..8d4ca74 100644 --- a/ExcelDataDriver/__init__.py +++ b/ExcelDataDriver/__init__.py @@ -39,7 +39,7 @@ from ExcelDataDriver.Config.CaptureScreenShotOption import CaptureScreenShotOption -__version__ = '1.1.6' +__version__ = '1.1.7' class ExcelDataDriver: @@ -523,6 +523,21 @@ def save_report(self, newfile=None): """ self.excelTestDataService.save_report(newfile) + #################################################### + # + # Insert selective columns + # + #################################################### + @keyword + 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) + #################################################### # # Load reference excel data