Confused on how to use a created file for a function in the robot framework. Normally I would do something along the lines of f = open("logFileTest.txt", "w")
and then pass f into the function like so getAddresses(f)
This getAddresses function is written to use a passed argument for logging.
def getAddresses(logFile=None):
print("Entering getAddresses!", file=logFile)
So when translating this to the robot framework I attempt to create a file and set that created file into a variable and then call the function with that newly created variable.
${logFile}= Create File log.txt
${addresses}= Get Addresses ${logFile}
This however sets logFile equal to none rather than the newly created log.txt that I would like it to be set to.
Is there another way in the robot framework to open the file than Get File? Get file in this case doesn't work as it only returns the contents of the file.
Create File does not return path to the file (or anything according to documentation [1]). You could set path as variable and give that to Create File keyword as argument and then also to your Get Addresses keyword.
${path}= Set Variable log.txt
Create File ${path}
${addresses}= Get Addresses ${path}
Then in the keyword implementation you need to open it (as path is only passed):
def getAddresses(logFile):
with open(logFile, 'w') as f:
print('Entering getAddresses!', file=f)
[1] https://robotframework.org/robotframework/latest/libraries/OperatingSystem.html#Create%20File