from marigoso import Test
test = Test()
browser = test.launch_browser("Firefox")
data = {
    'url': "http://pytest.uk",
    'username': "myusername",
    'password': "mysecret"
}

"""
Explanation: How to dynamically add functionalities to the Browser
Suppose you want to add a login function to the Browser.
End of explanation
"""


def login(self, data):
    self.get_url(data['url'])
    if self.is_available('name=credential_0', 1):
        self.kb_type('name=credential_0', data['username'])
        self.kb_type('name=credential_1', data['password'])
        self.submit_btn('Login')
    assert self.is_available("Logout")
    return self.get_element("id=logged_in_user").text

"""
Explanation: You can define such a function at any point in your testbook. Note that you need to use self inside your function definition rather than using the word browser.
End of explanation
"""


test.register_function("browser", [login])

"""
Explanation: Once defined, you can call the register_function method of test object to attach the function to the browser object.
End of explanation
"""


browser.login

"""
Explanation: You can then confirm that the login is now a bound method of browser and can be used right away just like any other methods bound to browser.
End of explanation
"""


