Use User keywords within a library

157 views
Skip to first unread message

Mikhail

unread,
Feb 9, 2010, 1:13:51 PM2/9/10
to robotframework-users
Hello,
I am new to robot framework and not sure whether it is possible to use
user defined keywords inside the library keywords within python. This
would allow me to write much more powerful test cases, while
preserving the readability and maintainability of high-level user
keywords.

Pekka Klärck

unread,
Feb 9, 2010, 4:28:15 PM2/9/10
to mzak...@gmail.com, robotframework-users
2010/2/9 Mikhail <mzak...@gmail.com>:

> Hello,
> I am new to robot framework

Welcome!

> and not sure whether it is possible to use
> user defined keywords inside the library keywords within python. This
> would allow me to write much more powerful test cases, while
> preserving the readability and maintainability of high-level user
> keywords.

You can use `run_keyword` method of the BuiltIn library to accomplish
this. The User Guide [1] has some information on how to use BuiltIn
keywords from your own libraries but doesn't have any example
demonstrating exactly this usage. If the provided information isn't
adequate, please send more detailed questions to this list.

[1] http://robotframework.googlecode.com/svn/tags/robotframework-2.1.2/doc/userguide/RobotFrameworkUserGuide.html#using-robot-framework-s-internal-modules

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

Mikhail Zakharov

unread,
Feb 9, 2010, 4:41:25 PM2/9/10
to Pekka Klärck, robotframework-users
Hello, Thanks for your reply.
I have already found the solution by reading through the sources - textfile builtin.py has a really good example on how this is accomplished:

    from robot.libraries.BuiltIn import BuiltIn, register_run_keyword

    def my_run_keyword(name, *args):
        # do something
        return BuiltIn().run_keyword(name, *args)

    # Either one of these works
    register_run_keyword(__name__, my_run_keyword)
    register_run_keyword(__name__, 'My Run Keyword', 1)


Thanks again, and great work!
Reply all
Reply to author
Forward
0 new messages