Kaan San
Kaan San

Reputation: 103

Robot Framework , inheriting multiple mixins

I work on a project with robot framework , pageobject library ,selenium2library.
I couldn't find a way to use multiple mixins on a page object.
I want to use two mixins with LoginPage.
MainNavigation works but HeaderMixin doesn't work.
My suite setup is login on every tests so I need to use mixins on that LoginPage
How to use more than one mixin on a page object ?

this is my LoginPage object :

class LoginPage(MainNavigation, HeaderMixin, PageObject):
    """LoginPage baseclass"""

    PAGE_URL = "/user/login"
    PAGE_TITLE = "Title"

    _locators = {
            "username": 'id=login_email',
            "password": 'id=login_password',
            "button": "id=login"
    }

Upvotes: 0

Views: 269

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386210

There's nothing special you need to do to use multiple mixins -- just create a python class with any new keywords that you want, and include the mixins when defining the class.

For example, consider the following two mixin classes:

class MainNavigation():
    def main_nav_keyword(self):
        pass

class HeaderMixin():
    def header_keyword(self):
        pass

You can use these mixins in your LoginPage class:

class LoginPage(MainNavigation, HeaderMixin, PageObject):
    ...

Within a class that uses the LoginPage, you can now access the navigation keywords and header keywords as if they were part of the page:

*** Test Cases ***
Example
    go to page  LoginPage
    the current page should be  LoginPage
    main nav keyword
    header keyword

Upvotes: 0

Related Questions