Using Templates with Named Arguments

2,431 views
Skip to first unread message

Elisabeth Hendrickson

unread,
Jun 1, 2012, 4:48:08 PM6/1/12
to robotframe...@googlegroups.com
Howdy!

I've searched for an answer to this and can't find it. Please forgive me if it's documented and I missed it.

I have a keyword that supports named arguments, with default values specified in the keyword. I am using it as a test template. And I'm having trouble figuring out how to use it in the case where I want all default values.

This is a relatively academic question in that I don't actually have a use case requiring this case at this time. So far all my actual tests require at least one overridden argument.

But for the sake of argument, let's say I have the following keyword:

Greet Team
    [arguments]   ${scrum_master}=pebbles
    ...           ${product_owner}=bambam
    Log           hi SM ${scrum_master} & PO ${product_owner}   

Now, if I use it as a test template, I can specify a test like so:

*** settings ***
Test Template    Greet Team

*** test cases *** 
Passing scrum master var   scrum_master=wilma

This works dandy. I see "wilma" is the Scrum Master, and the default, "bambam" is the product owner. Similarly I can override just the product_owner, or both variables:

Passing product owner vars  product_owner=shazam
Passing both vars           product_owner=joebob   scrum_master=sallymae

However, let's imagine I want a test where I use both defaults. I tried:

Using all defaults                             

This does not work; the error message says that no keywords were specified.

Using all defaults   ${EMPTY}                          

This does not work. The result is that the Scrum Master is set to nothing (it logs: hi SM & PO bambam)

Using all defaults   ${NULL}                          

This does not work. The result is that the Scrum Master is set to "None" (it logs: hi SM None & PO bambam)

So what's the magic incantation I can use to create a test case that calls the keyword but does not override the defaults for the ${scrum_master} or ${product_owner} variables?

If the answer is "You can't," that's OK. I just want to know the limitations.

Thanks!

Elisabeth
….
Elisabeth Hendrickson
Twitter: @testobsessed


Pekka Klärck

unread,
Jun 4, 2012, 6:28:34 PM6/4/12
to elisabeth....@gmail.com, robotframe...@googlegroups.com
2012/6/1 Elisabeth Hendrickson <elisabeth....@gmail.com>:
>
> I have a keyword that supports named arguments, with default values
> specified in the keyword. I am using it as a test template. And I'm having
> trouble figuring out how to use it in the case where I want all default
> values.
>
> This is a relatively academic question in that I don't actually have a use
> case requiring this case at this time. So far all my actual tests require at
> least one overridden argument.

This is a pretty interesting corner case that at least I hadn't though
about before. I was just about to write that you can't do this, but
then I realized that you can use an empty list variable. To continue
with your example, you can add first

*** Variables ***
@{EMPTY}

and then

*** Test Cases ***
Using all defaults @{EMPTY}

will work. The reason it works is that now the test isn't empty
anymore but the empty list variable will be replaces with absolutely
nothing later.

What do you think, should we add a new built-in @{EMPTY} variable to
Robot? That would be trivial and there is, at least, this one
demonstrated use case.

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

Pekka Klärck

unread,
Jun 25, 2012, 12:21:49 PM6/25/12
to Elisabeth Hendrickson, robotframework-users
012/6/25 Elisabeth Hendrickson <e...@qualitytree.com>:
> I like the idea of the @{EMPTY} variable, although I confess that I don't
> actually need it at this time. But there are some other use cases I'm
> running into where I can imagine it would be useful. So if it's trivial, I'd
> say go for it.

I submitted an issue about this [1]. It's targeted for 2.7.4, but I
actually hope we wouldn't need such a release before 2.8.

[1] http://code.google.com/p/robotframework/issues/detail?id=1166
Reply all
Reply to author
Forward
0 new messages