robotframework-tools

HomePage: http://bitbucket.org/userzimmermann/robotframework-tools

Author: Stefan Zimmermann

Download: https://pypi.python.org/packages/source/r/robotframework-tools/robotframework-tools-0.1a109.tar.gz

        Robot Framework Tools
=====================

[Python](http://python.org) Tools for [Robot Framework](
  http://robotframework.org) and Test Libraries.

* A [`testlibrary`][1] framework for creating Dynamic Test Libraries.

* A [`ContextHandler`][1.1] framework for `testlibrary`
  to create switchable sets of different Keyword implementations.

* A [`SessionHandler`][1.2] framework for `testlibrary`
  to auto-generate Keywords for session management.

* A [`TestLibraryInspector`][2].

* An interactive [`TestRobot`][3].

* A [`RemoteRobot`][4], combining `TestRobot`
  with external [`RobotRemoteServer`](
    https://pypi.python.org/pypi/robotremoteserver)

* A [`ToolsLibrary`][5],
  accompanying Robot Framework's standard Test Libraries.

* A [`robotshell`][6] extension for [IPython](http://ipython.org).


0. Setup
--------

Supported __Python__ versions: __2.7.x__, __3.3.x__ and later

Package name: __robotframework-tools__

Package extra features:

* __[remote]__: `RemoteRobot`
* __[robotshell]__

### Requirements

* [`path.py`](https://pypi.python.org/pypi/path.py)
* [`moretools >= 0.1a34`](https://pypi.python.org/pypi/moretools)
* [`robotframework >= 2.8`](https://pypi.python.org/pypi/robotframework)
  * __Python 3.x__: [`robotframework-python3 >= 2.8.3`](
      https://pypi.python.org/pypi/robotframework-python3)

Extra requirements for __[remote]__:

* [`robotremoteserver`](https://pypi.python.org/pypi/robotremoteserver)

Extra requirements for __[robotshell]__:

* [`ipython`](https://pypi.python.org/pypi/ipython)

### Installation

    python setup.py install

Or with [pip](http://www.pip-installer.org):

    pip install .

Or from [PyPI](https://pypi.python.org/pypi/robotframework-tools):

    pip install robotframework-tools

* With all extra features:

        pip install robotframework-tools[remote,robotshell]


1. Creating Dynamic Test Libraries
----------------------------------
[1]: #markdown-header-1-creating-dynamic-test-libraries

    from robottools import testlibrary

    TestLibrary = testlibrary()

Defined in a module also called `TestLibrary`,
this generated Dynamic `TestLibrary` type
could now directly be imported in Robot Framework.
It features all the required methods:

* `get_keyword_names`
* `get_keyword_arguments`
* `get_keyword_documentation`
* `run_keyword`

### Keywords

The `TestLibrary` has no Keywords so far...
To add some just use the `TestLibrary.keyword` decorator:

    @TestLibrary.keyword
    def some_keyword(self, arg, *rest):
        ...

A keyword function can be defined anywhere in any scope.
The `TestLibrary.keyword` decorator
always links it to the `TestLibrary`
(but always returns the original function object).
And when called as a Keyword from Robot Framework
the `self` parameter will always get the `TestLibrary` instance.

You may want to define your keyword methods
at your Test Library class scope.
Just derive your actual Dynamic Test Library class from `TestLibrary`:

    # SomeLibrary.py

    class SomeLibrary(TestLibrary):
        def no_keyword(self, ...):
            ...

        @TestLibrary.keyword
        def some_other_keyword(self, arg, *rest):
            ...

To get a simple interactive `SomeLibrary` overview just instantiate it:

    In : lib = SomeLibrary()

You can inspect all Keywords in Robot CamelCase style
(and call them for testing):

    In : lib.SomeKeyword
    Out: SomeLibrary.Some Keyword [ arg | *rest ]

By default the Keyword names and argument lists are auto-generated
from the function definition.
You can override that:

    @TestLibrary.keyword(name='KEYword N@me', args=['f|r$t', 'se[ond', ...])
    def function(self, *args):
        ...

### Keyword Options

When you apply custom decorators to your Keyword functions
which don't return the original function objects,
you would have to take care of preserving the original argspec for Robot.
`testlibrary` can handle this for you:

    def some_decorator(func):
        def wrapper(...):
            return func(...)

        # You still have to take care of the function(-->Keyword) name:
        wrappe