Skip to content

Using rfhub with page objects

Bryan Oakley edited this page Jun 26, 2015 · 1 revision

Starting with version 0.8.2, the hub supports page objects from the robotframework-pageobjects project.

Identifying where to find page object classes

The command line option --pageobjects takes as a value the name of a module that provides access to one or more page object classes. This module must be able to be imported, meaning it needs to be in your PYTHONPATH. The hub will import the given module, examine every member of the module, and expose the documentation for every class that ultimately inherits from robotpageobjects.Page.

If the path to the module is not in PYTHONPATH, you can use the --pythonpath option to add one or more paths to PYTHONPATH when the hub starts up, similar to how the same option works with pybot.

Note: the hub will not recursively examine all submodules. It will only include documentation for page object classes in the given module. You can use the --pageobjects option more than once to include page objects from multiple directories.

Example

Consider the following file structure:

ProjectA
|-- lib
|   |-- __init__.py
|   `-- pages
|       |-- __init__.py
|       |-- Product1
|       |   |-- DashboardPage.py
|       |   |-- LoginPage.py
|       |   |-- __init__.py
|       |-- Product2
|       |   |-- __init__.py
|       |   |-- DashboardPage.py
|       |   |-- LoginPage.py

In order for robot and robotframework-hub to be able to find the module pages, the lib folder needs to be in PYTHONPATH, or added at runtime with the --P/--pythonpath option. You can then start rfhub and tell it to look in the pages module to find page objects:

$ cd ProjectA
$ python -m rfhub --pythonpath ./lib --pageobjects pages.Product1 --pageobjects pages.Product2

With that, you should see in rfhub the documentation for pages.Product1.DashboardPage and pages.Product1.LoginPage, which is how you would reference these pages from within a robot framework test suite.

Excluding pages

If you have pages that act as an abstract base class for other page classes, and which should not appear in the list of pages in the hub, you can exclude that page by setting a class attribute named __show_in_rfhub to False. For example:

class AppPage(Page):
    __show_in_rfhub=False
class DashboardPage(AppPage):
    ...
class ProfilePage(AppPage):
    ...

Since this attribute is name-mangled, it won't be inherited from subclasses.