20
20
https://github.com/robotframework/robotframework/tree/master/doc/userguide/src/ExtendingRobotFramework
21
21
"""
22
22
import glob
23
+ import importlib
23
24
import re
24
25
import sys
25
26
import os .path
@@ -76,6 +77,8 @@ def __init__(self, file=None, custom_parser=None, capture_screenshot='Always', m
76
77
self .custom_parser = CustomExcelParser .CustomExcelParser ()
77
78
self .capture_screenshot_option = CaptureScreenShotOption [capture_screenshot ]
78
79
self .manually_test = manually_test
80
+ if self .file is None :
81
+ self .manually_test = True
79
82
80
83
self .excelTestDataService = ExcelTestDataService ()
81
84
self .suite_source = None
@@ -93,6 +96,8 @@ def __init__(self, file=None, custom_parser=None, capture_screenshot='Always', m
93
96
94
97
self .screenshot_running_id = 0
95
98
99
+ self .reference_data = dict ()
100
+
96
101
def load_module (self , module ):
97
102
"""``Important`` using by local library only."""
98
103
# module_path = "mypackage.%s" % module
@@ -516,3 +521,63 @@ def save_report(self, newfile=None):
516
521
517
522
"""
518
523
self .excelTestDataService .save_report (newfile )
524
+
525
+ ####################################################
526
+ #
527
+ # Load reference excel data
528
+ #
529
+ ####################################################
530
+ @keyword
531
+ def load_reference_data (self , alias_name , filename ,
532
+ custom_parser_module = 'ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy' ,
533
+ custom_parser_class = 'DefaultReferenceParserStrategy' ):
534
+ """
535
+ Load reference data with specific Parser
536
+
537
+ Arguments:
538
+ | alias_name | alias_name for refer to the reference data |
539
+ | filename (string) | The file name string value that will be used to open the excel file to perform tests upon. |
540
+ | custom_parser_module | Test data parser module is ExcelDataDriver.ExcelParser.DefaultReferenceParserStrategy |
541
+ | custom_parser_class | Test data parser class is DefaultReferenceParserStrategy |
542
+ """
543
+ reference_wb = OpenpyxlHelper .load_excel_file (filename )
544
+ CustomExcelParser = getattr (importlib .import_module (custom_parser_module ), custom_parser_class )
545
+ # CustomExcelParser = __import__(custom_parser_module)
546
+ # parser_context = ParserContext(CustomExcelParser.CustomExcelBreakdownParser())
547
+ parser_context = ParserContext (CustomExcelParser ())
548
+ references_data_sheets = parser_context .parse (reference_wb )
549
+ reference_row_data = []
550
+ for sheet_name in references_data_sheets :
551
+ reference_row_data += references_data_sheets [sheet_name ]
552
+ self .reference_data [alias_name ] = {
553
+ 'selected' : None ,
554
+ 'data' : reference_row_data
555
+ }
556
+ reference_wb .close ()
557
+
558
+ @keyword
559
+ def select_reference_data_based_on_condition (self , alias_name , condition ):
560
+ """
561
+ Select reference data based on condition
562
+
563
+ Arguments:
564
+ | alias_name | alias_name for refer to the reference data |
565
+ | condition | refer variable name 'data' |
566
+
567
+ Default Data Properties:
568
+ excel_title string
569
+ excel_row_index string
570
+ row_no string
571
+ sheet_name string
572
+ properties_list dictionary: access to excel property with lower case and use _ instead of space
573
+ """
574
+ self .reference_data [alias_name ]['selected' ] = next (data for data in self .reference_data [alias_name ]['data' ] if eval (condition ))
575
+
576
+ @keyword
577
+ def get_selected_reference_data_property (self , alias_name , property_name ):
578
+ return self .reference_data [alias_name ]['selected' ].properties_list [property_name ]
579
+
580
+ @keyword
581
+ def get_reference_data_property (self , alias_name , property_name , condition ):
582
+ select = next (data for data in self .reference_data [alias_name ]['data' ] if eval (condition ))
583
+ return select .properties_list [property_name ]
0 commit comments