2

Here's a basic rundown of what I want to do:

I want to call my scripts using an argument file. But the argument file needs to work on an environment variable for the path. So, for example, the argument file may be:

args.robot

[ROBOT_HOME variable]/test1.robot
[ROBOT_HOME variable]/test2.robot
[ROBOT_HOME variable]/test3.robot

And I would define the ROBOT_HOME variable at the environment level:

$ export ROBOT_HOME=/path/to/tests/
$ pybot -A args.robot

None of the following substitutions for [ROBOT_HOME variable] in the args.robot file have worked:

  • $ROBOT_HOME
  • ${ROBOT_HOME}
  • %{ROBOT_HOME}

And neither of the following pybot commands have worked:

  • pybot -A args.robot
  • pybot -v ROBOT_HOME:$ROBOT_HOME -A args.robot

Is what I'm trying to do possible?

ewok
  • 20,148
  • 51
  • 149
  • 254
  • Not sure if [this](http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#argument-file-syntax) is of help, please see. – Rao Feb 02 '16 at 19:54
  • @Rao Yea I looked there and didn't see anything about this kind of thing. – ewok Feb 02 '16 at 19:55

2 Answers2

0

@Rao gives a good solution for the problem. The last part of the documentation on arguments file demonstrate how to programmatically generate argumentfile and use them with a one-liner.

generate_arguments.sh | robot --argumentfile STDIN
generate_arguments.sh | robot --name Example --argumentfile STDIN tests.robot

The quesion remaining now is what can the generate_arguments.sh be? Il like to use envsub, envsub replace environnement variables in a script (for linux env)

envsubst '$HOME' < "argumentfile.txt" > "argumentfile.txt"
echo "argumentfile.txt"

Another possibility to run that script would be:

generate_arguments.sh && robot --argumentfile "argumentfile.txt"
xNok
  • 98
  • 1
  • 7
0

@xNok Solution would work, but it is not very accurate. You can not rewrite a file with envsubst command. Take a look into this thread.

rewriting a file with "envsubst file" leaves it empty

So, basically if you want to get it working in this way, the argument file would look like this:

export HOME='your/path'
envsubst '${HOME}' < argumentfile.txt > argumentfile_tmp.txt && mv argumentfile_tmp.txt argumentfile.txt

And for instance the "argumentfile.txt" would look like this:

--variable PATH:${HOME}/some/sub/path

Then as suggested by @xNok, you can run the script this way:

generate_arguments.sh && robot --argumentfile "argumentfile.txt"

Please note that this method would overwrite the "argumentfile.txt". So, every time you need to clone the source code or the other option is to use envsubst to write to a temporary file.

MKalio
  • 5
  • 3