Coliban
Coliban

Reputation: 671

How to pass arguments to a robot library

it seems as if in "Robotframework" a class is instantiated when it is defined as Library. I do this:

Library       /home/johann/xmlSockets.py   "./config.xml" "test"

In python, the class can be instantiated:

> class xmlSockets():
>     def __init__(self, configfile, Suchliste):

and there is no problem. With python it is working flawless.

When it try this in robotframework:

[ ERROR ] Error in file '/home/johann/robotest/Tests/fuenf.robot' on line 6: Initializing library 'xmlSockets' with arguments [ "config.xml" | test ] failed: FileNotFoundError: [Errno 2] No such file or directory: '"config.xml"'

I tried config.xml, "config.xml", 'config.xml', './config.xml', "./config.xml, @{config.xml device}...

no success.

Upvotes: 0

Views: 1536

Answers (3)

Bryan Oakley
Bryan Oakley

Reputation: 385860

Part of the problem is that you are adding quote marks to the name of the file. The error message isn't telling you that config.xml doesn't exist, it's telling you that "config.xml" doesn't exist. So, the first step is to remove the quotes:

Library       /home/johann/xmlSockets.py   ./config.xml  test

The second may be because you're assuming the library is looking in the same folder as the library rather than in the current working directory. In this context, "." represents the current working directory, which may not be the same as the directory with the robot file, nor the directory with the python file.

In a comment you said the config file is in the same folder as the robot file. If that's the case, I recommend you use the built-in robot variable ${CURDIR} to pass the full path to your library:

Library  /home/johann/xmlSockets.py   ${CURDIR}/config.xml  test

Upvotes: 1

Jiri Janous
Jiri Janous

Reputation: 1242

If the library is in the same project as the config.xml you can use ${CURDIR} variable from built-in-variables. the current directory will be the directory of the file where you create the library. I would use this to specify the library path as well. Something like this:

Library       ${CURDIR}${/}path to lib${/}xmlSockets.py   ${CURDIR}${/}path to config${/}config.xml   "test"

Upvotes: 0

Coliban
Coliban

Reputation: 671

The solution ist, that the current directory is NOT the directory with the Library (or python class), it is under this in the test directory. So we must navigate BACK to the place where the python class was imported (or other) weith "../config.xml" or the take absolute path to the file.

Upvotes: 0

Related Questions