Returing keyword status and return values to robot frame work

1,311 views
Skip to first unread message

bindal

unread,
Dec 23, 2008, 7:30:20 AM12/23/08
to robotframework-users
Hi,

I am using Java Core library to build my keywords in Java.
There is requiremnet of a key word which returns a value and checks
the status.

For e.g I am making a keyword for checking the row count in a data
base table. The following are the arguments to the Keyword.
1. Table Name
2. Expected row count

If the count of rows in the given table does not match with the
'Expected row count' then the keyword should fail. I am communicating
the keyword failure status to robot framework by throwing an
exception.
The keyword should also return the table row count value, so that it
can be used to make another keywords. A return statement can be used
to return this value to robot framework.
However, it is not possible to perform both these operations(throwing
an exception and returning value) at the same time.
So the keyword can either return a pass/fail status or return a value.
Is there anyway to pass the status and return value to the robot
framework simultaneously?

Regards,
Bindal.

Pekka Klärck

unread,
Dec 23, 2008, 8:01:03 AM12/23/08
to shah....@gmail.com, robotframework-users
2008/12/23 bindal <shah....@gmail.com>:

>
> I am using Java Core library to build my keywords in Java.
> There is requiremnet of a key word which returns a value and checks
> the status.
>
> For e.g I am making a keyword for checking the row count in a data
> base table. The following are the arguments to the Keyword.
> 1. Table Name
> 2. Expected row count
>
> If the count of rows in the given table does not match with the
> 'Expected row count' then the keyword should fail. I am communicating
> the keyword failure status to robot framework by throwing an
> exception.
> The keyword should also return the table row count value, so that it
> can be used to make another keywords. A return statement can be used
> to return this value to robot framework.

Interesting. Are you planning to implement a generic database library
or something that is dependent on your application under test? I know
others would be interested about a generic db library too.

> However, it is not possible to perform both these operations(throwing
> an exception and returning value) at the same time.
> So the keyword can either return a pass/fail status or return a value.
> Is there anyway to pass the status and return value to the robot
> framework simultaneously?

Yes, keyword can either return a value or throw an exception and fail.
If there is no exception the keyword is considered to pass so that
status is communicated implicitly. Since the test execution ends if a
keyword fails (i.e. throws an exception), the return value couldn't be
used for anything even if you could return it.

Sometime there might be a need to first return return something from a
keyword, then do something with the return value and finally decide
the test case status based on the return value. This can be done be
always returning a value from the keyword and never failing it (or
failing it only in unexpected error situations). You can either add
the status to the return value or return multiple values as explained
in the user guide [1]. The latter approach could then be used to
construct something like this:

| ${return_value} | ${status} = | My Keyword |
| Do Something | ${return_value} |
| Should Be Equal | ${status} | PASS |

[1] http://robotframework.googlecode.com/svn/trunk/doc/userguide/RobotFrameworkUserGuide.html#returning-values

Cheers,
.peke

Reply all
Reply to author
Forward
0 new messages