2013/1/16 Laurent Bristiel <
lau...@bristiel.com>:
>
> The best way I found so far is to have initialization file (__init__.txt) in
> every folder with a line :
> Force Tags folder_name
>
> My question is : is there a way to automatically retrieve the name of the
> folder ?
> I saw in the doc that there are automatic variables, but none is
> "folder_name"
> (
http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.7.5#automatic-variables)
> I can not use ${SUITE_NAME} because I get the name of the tc file, not the
> one of the folder.
>
> Only thing I could think of is to use ${SUITE SOURCE} and extract the tc's
> parents folder name but I don't see how I could do this in the "force tags"
> keyword.
Probably the easiest solution is setting these tags using variables
and creating the variables in a variable file. If you have the
variable file in the same directory as your test suite, you shouldn't
need more than
import os.path
FOLDER_NAME = os.path.basename(os.path.dirname(__file__))
in your variable file and then you could use ${FOLDER NAME} variable
in files taking the variable file into use.
Things are a bit more difficult if you want to have only one variable
file and use that from various test suites in different directories.
In that case you could pass ${CURDIR} as an argument to the variable
file like
*** Settings ***
Variables path/to/foldername.py ${CURDIR}
Force Tags ${FOLDER NAME}
and then in your variable file have
import os.path
def get_variables(directory):
return {'FOLDER_NAME': os.path.basename(directory)}
A different solution is setting tags dynamically using `Set Tags`
keyword. If you use it in suite setup, all tests in that suite will
get those tags. A benefit of this solution is that you don't need
extra files. Having something like this ought to work:
*** Settings ****
Suite Setup Set Folder Name Tags
Library OperatingSystem
*** Keywords ***
Set Folder Name Tags
${path} ${folder name} = Split Path ${CURDIR}
Set Tags ${folder name}
Cheers,
.peke
--
Agile Tester/Developer/Consultant ::
http://eliga.fi
Lead Developer of Robot Framework ::
http://robotframework.org