CURDIR built-in variable

1,436 views
Skip to first unread message

Vinicius Kwiecien Ruoso

unread,
May 19, 2016, 6:48:56 AM5/19/16
to robotframework-users
Hi all,

I was trying to use the ${CURDIR} variable from within a Python
library by using the BuiltIn().get_variable_value method. It did not
work, so I read the docs and they say: "Additionally ${CURDIR} is
special because it is replaced already during the test data processing
time.".

We have a few ways of handling this variable to the library (init
argument, keyword argument, a keyword to set it in the library state,
and so on) but in that particular case the test suite itself would
benefit from a "transparent" way of passing a relative path.

Does anyone see a better way of handling that case? Would it be much
effort to add support to that variable in the "Get Variable Value"
keyword?

Greetings,
Vinicius

Pekka Klärck

unread,
May 20, 2016, 11:51:58 AM5/20/16
to Vinicius Kwiecien Ruoso, robotframework-users
2016-05-19 13:48 GMT+03:00 Vinicius Kwiecien Ruoso <viniciu...@gmail.com>:
>
> I was trying to use the ${CURDIR} variable from within a Python
> library by using the BuiltIn().get_variable_value method. It did not
> work, so I read the docs and they say: "Additionally ${CURDIR} is
> special because it is replaced already during the test data processing
> time.".

Yes, ${CURDIR} is not a normal variable. It is replaced already at the
parsing time.

> We have a few ways of handling this variable to the library (init
> argument, keyword argument, a keyword to set it in the library state,
> and so on) but in that particular case the test suite itself would
> benefit from a "transparent" way of passing a relative path.
>
> Does anyone see a better way of handling that case? Would it be much
> effort to add support to that variable in the "Get Variable Value"
> keyword?

If you are interested in a relative path to the test suite itself,
then you could simply use ${SUITE SOURCE} variable. If you would need
a path to resource file calling your library keyword, you can create a
variable with that information in the resource file based on
${CURDIR}:

*** Variables ***
${RESOURCE DIR} ${CURDIR}

Notice that if you would create such a ${RESOURCE DIR} variable both
in a resource file and in a test suite file importing the resource
file, only the value in the suite file would be visible.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Vinicius Kwiecien Ruoso

unread,
May 20, 2016, 12:22:49 PM5/20/16
to Pekka Klärck, robotframework-users
Hi Pekka,

The use of the ${SUITE SOURCE} variable gets confusing if used in the
keyword call because it points to the suite file name. It looks like
the best option is to request an absolute path in the library keyword,
and ask the user to use ${CURDIR} to build it relatively if they need
it. Doing it inside the library with ${SUITE SOURCE} would also work,
but does not look so elegant, and would also not solve the calling the
keyword from a resource file problem. :)

Thanks for your answer.

Greetings,
Vinicius
Reply all
Reply to author
Forward
0 new messages