Skip to content

Commit

Permalink
Merge pull request #4 from qahive/auto-generate-test-result-columns
Browse files Browse the repository at this point in the history
Auto generate test result columns
  • Loading branch information
atthaboon authored Sep 23, 2020
2 parents 654086a + 376ca81 commit 3f38d66
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Examples/AutoAddTestDataColumnsExample.robot
Original file line number Diff line number Diff line change
@@ -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}
Binary file modified Examples/test_data/BasicDemoData.xlsx
Binary file not shown.
Binary file not shown.
10 changes: 9 additions & 1 deletion ExcelDataDriver/ExcelParser/ParserContext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion ExcelDataDriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from ExcelDataDriver.Config.CaptureScreenShotOption import CaptureScreenShotOption


__version__ = '1.1.6'
__version__ = '1.1.7'


class ExcelDataDriver:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3f38d66

Please sign in to comment.