I am trying to test a python file using robot framework and part of my file takes in a -i option with the input file being provided from the command line. I want to be able to set the inputFile from the command line. If using the -i option in Robot Framework isn't an option, is there a way to explicitly set the inputFile variable in my .robot file?
Here is some code for reference:
parser = argparse.ArgumentParser(add_help=True, description='Usage')
parser.add_argument('-i', dest='input_file', required=True, help='Input module (servicenow, nagios, splunk etc.) containing its implementation')
parser.add_argument('-c', '--check', action='store_true', required=False, help='Flag to check connections to OVGD and input module.')
# Check and parse the input arguments into python's format
inputFile = parser.parse_args()
#inputFile = "duplicate_module_simple_logging.py"
inputModuleName = inputFile.input_file.split(".")[0]
#inputModuleName = inputFile.split(".")[0]
#gModuleName = inputModuleName
separator = os.sep
temp = inputModuleName.split(separator)
Here are some of the options I was trying but I'm not sure I understand how to pass in input arguments in Robot:
[root@xxxxxx]# robot --variable inputFile:duplicate_module_simple_logging.py test2.robot
==============================================================================
Test2
==============================================================================
Case1 | PASS |
------------------------------------------------------------------------------
Case2 | FAIL |
TypeError: string indices must be integers
------------------------------------------------------------------------------
Case3 | PASS |
------------------------------------------------------------------------------
Case4 | PASS |
------------------------------------------------------------------------------
Case5 usage: robot [-h] -i INPUT_FILE [-c]
robot: error: the following arguments are required: -i
[ ERROR ] Execution stopped by user.
Here is what my test file looks like:
*** Settings ***
Library String
Library Collections
Library duplicate_main.py
Library duplicate_module_simple_logging.py
*** Variables ***
${inputFile} duplicate_module_simple_logging.py
*** Test Cases ***
Case1
${result1} = init logger_module
Should Be Equal As Integers ${result1} 0
Case2
${result2} = execute alert
Should Be Equal As Integers ${result2} 0
Case3
${result3} = cleanup
Should Be Equal As Integers ${result3} 0
Case4
${result4} = init 8
Should Be Equal As Integers ${result4} 0
Case5
${result5} = main
Should Be Equal As Integers ${result5} 0