Loading Data files in Test Cases

1,030 views
Skip to first unread message

Ocre

unread,
Feb 9, 2010, 2:42:10 AM2/9/10
to robotframework-users
Hi,

Is it possible to use a data file which contains the data for the test
cases in Robot Framework?
I only read about a resource file and variable file in the user guide.
Can the variable file be a python file only? Can we have a html file
with namespace so that the variables will be referred like
NAMESPACE.VARIABLE ?

Thanks,
Ocre

Pekka Klärck

unread,
Feb 9, 2010, 4:53:07 AM2/9/10
to kavip...@gmail.com, robotframework-users
2010/2/9 Ocre <kavip...@gmail.com>:

One east solution would be implementing a dynamic variable file that
reads the data from some other file. Alternatively you could have a
library with keywords for reading the data. If you just need to pass a
reference of that external file to some other tool, you can create a
path to it simply like `${CURDIR}${/}mydata.txt`.

Cheers,
.peke

Ocre

unread,
Feb 9, 2010, 5:42:38 AM2/9/10
to robotframework-users
Just got an idea that I'll use a resource file as my data file if I'm
able to refer to my variables with ${MyResource.Var} syntax.
MyResource.html is my resource file and ${Var} is my variable.

Is this possible?
Something similar to accessing a keyword explicitly.

Thanks,
Ocre

Carl Dichter

unread,
Feb 9, 2010, 12:06:44 PM2/9/10
to kavip...@gmail.com, robotframework-users

Related to this, I'm not seeing the name-space behavior that the RF user's guide mentions:

Resource files are specified in the full keyword name, similarly as library names. The name of the resource is derived from the basename of the resource file without the file extension. For example, the keyword Example in a resource file myresources.html can be used as myresources.Example. Note that this syntax does not work, if several resource files have the same basename. In such cases, either the files or the keywords must be renamed. The full name of the keyword is case-, space- and underscore-insensitive, similarly as normal keyword names.

I put a variable "bar" in a resouces file called "foo.htm", then I cannot seem to access the variable as ${foo.bar} but I there is no problem accessing ${bar}.

There are no other files names with the same basename: foo

Because of the differences in file name case significance on Windows and Linux (I am on Windows), I also tried putting the filename in all upper and lower case.



--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.


Bryan Oakley

unread,
Feb 9, 2010, 1:11:04 PM2/9/10
to robotframework-users
On Tue, Feb 9, 2010 at 3:53 AM, Pekka Klärck <pekka....@gmail.com> wrote:
>
> One east solution would be implementing a dynamic variable file that
> reads the data from some other file. Alternatively you could have a
> library with keywords for reading the data. If you just need to pass a
> reference of that external file to some other tool, you can create a
> path to it simply like `${CURDIR}${/}mydata.txt`.

My team is having a lot of success with this. We h ave a couple
variations -- one that creates variables out of a spreadsheet (in csv
format), and one that makes variables from JSON data stored in a
javascript file.

Variable files are very cool, and only limited by your imagination and
programming skills.

Carl Dichter

unread,
Feb 9, 2010, 4:02:12 PM2/9/10
to oak...@bardo.clearlight.com, robotframework-users
When I use "Log Variables" the variables are there without the prefix for the file that they came from,

What's wrong?



Pekka Klärck

unread,
Feb 9, 2010, 4:10:13 PM2/9/10
to carl.d...@gmail.com, kavip...@gmail.com, robotframework-users
2010/2/9 Carl Dichter <carl.d...@gmail.com>:

>
> Related to this, I'm not seeing the name-space behavior that the RF user's
> guide mentions:
>
> Resource files are specified in the full keyword name, similarly as library
> names. The name of the resource is derived from the basename of the resource
> file without the file extension. For example, the keyword Example in a
> resource file myresources.html can be used as myresources.Example. Note that
> this syntax does not work, if several resource files have the same basename.
> In such cases, either the files or the keywords must be renamed. The full
> name of the keyword is case-, space- and underscore-insensitive, similarly
> as normal keyword names.
>
> I put a variable "bar" in a resouces file called "foo.htm", then I cannot
> seem to access the variable as ${foo.bar} but I there is no problem
> accessing ${bar}.

The namespace behavior is unfortunately limited only to keywords. I
haven't even though it about ${resource.variable_name} syntax but it
feels pretty nice. The only problem is that it might easily clash with
the extended variable syntax (e.g. ${variable_as_object.attribute}).
Please submit an enhancement request about adding namespaces for
variables to the tracker. We probably need to look at the related code
anyway in RF 2.5.

Cheers,
.peke

Reply all
Reply to author
Forward
0 new messages