diff --git a/docs/source/contrib.rst b/docs/source/contrib.rst index d68f61c..0d93afe 100644 --- a/docs/source/contrib.rst +++ b/docs/source/contrib.rst @@ -9,6 +9,31 @@ If you want to install this package with support for all CONTRIB packages, you c >>> pip install balderhub-html[all] +Contrib for ``balderhub-auth`` +============================== + +For activating this module, you need to install the package like shown below + +.. code-block:: none + + >>> pip install balderhub-html[auth] + +Once installed you can use it. + +Pages +----- + +.. autoclass:: balderhub.html.contrib.auth.pages.LoginPage + :members: + + +Setup Features +-------------- + +.. autoclass:: balderhub.html.contrib.auth.setup_features.UserLoginFeature + :members: + + Contrib for ``balderhub-crud`` ============================== diff --git a/requirements.txt b/requirements.txt index 82b63c1..582b6f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ balderhub-gui balderhub-webdriver balderhub-selenium balderhub-url -balderhub-crud \ No newline at end of file +balderhub-crud +balderhub-auth~=0.0.1b1 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index dbd6ff7..b4ccc71 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,9 @@ project_urls = packages = balderhub.html balderhub.html.contrib + balderhub.html.contrib.auth + balderhub.html.contrib.auth.pages + balderhub.html.contrib.auth.setup_features balderhub.html.contrib.crud balderhub.html.contrib.crud.utils balderhub.html.contrib.crud.utils.field_callbacks @@ -55,7 +58,9 @@ setup_requires = zip_safe = no [options.extras_require] +auth = + balderhub-auth>=0.0.1b1 crud = balderhub-crud>=0.0.1b8 all = - balderhub-html[crud] \ No newline at end of file + balderhub-html[auth,crud] \ No newline at end of file diff --git a/src/balderhub/html/contrib/auth/__init__.py b/src/balderhub/html/contrib/auth/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/balderhub/html/contrib/auth/pages/__init__.py b/src/balderhub/html/contrib/auth/pages/__init__.py new file mode 100644 index 0000000..2820f14 --- /dev/null +++ b/src/balderhub/html/contrib/auth/pages/__init__.py @@ -0,0 +1,5 @@ +from .login_page import LoginPage + +__all__ = [ + 'LoginPage', +] diff --git a/src/balderhub/html/contrib/auth/pages/login_page.py b/src/balderhub/html/contrib/auth/pages/login_page.py new file mode 100644 index 0000000..64d3c4a --- /dev/null +++ b/src/balderhub/html/contrib/auth/pages/login_page.py @@ -0,0 +1,51 @@ +from typing import Union, List + +import balderhub.html.lib.scenario_features + +import balderhub.html.lib.utils.components as html +from balderhub.url.lib.utils import Url + + +class LoginPage(balderhub.html.lib.scenario_features.HtmlPage): + """ + HTML Page for normal login pages as abstract base class - all abstract methods/properties needs to be defined in + subclass + """ + + @property + def url(self) -> Url: + """ + :return: non-schema url the login page is located at + """ + raise NotImplementedError + + @property + def applicable_on_url_schema(self) -> Union[Url, List[Url]]: + return self.url + + def open(self) -> None: + """ + This method opens the login page. + """ + self.driver.navigate_to(self.url) + + @property + def input_username(self) -> html.inputs.HtmlTextInput: + """ + :return: Html input field where the username needs to be filled + """ + raise NotImplementedError + + @property + def input_password(self) -> html.inputs.HtmlPasswordInput: + """ + :return: Html input field where the password needs to be filled + """ + raise NotImplementedError + + @property + def btn_login(self) -> html.HtmlButtonElement: + """ + :return: HTML button to submit the login form + """ + raise NotImplementedError diff --git a/src/balderhub/html/contrib/auth/setup_features/__init__.py b/src/balderhub/html/contrib/auth/setup_features/__init__.py new file mode 100644 index 0000000..87fbd52 --- /dev/null +++ b/src/balderhub/html/contrib/auth/setup_features/__init__.py @@ -0,0 +1,5 @@ +from .user_login_feature import UserLoginFeature + +__all__ = [ + "UserLoginFeature" +] diff --git a/src/balderhub/html/contrib/auth/setup_features/user_login_feature.py b/src/balderhub/html/contrib/auth/setup_features/user_login_feature.py new file mode 100644 index 0000000..433a93d --- /dev/null +++ b/src/balderhub/html/contrib/auth/setup_features/user_login_feature.py @@ -0,0 +1,25 @@ +import balderhub.auth.lib.scenario_features.client.user_login_feature + +from ..pages.login_page import LoginPage + + +class UserLoginFeature(balderhub.auth.lib.scenario_features.client.user_login_feature.UserLoginFeature): + """ + Implementation of the user login feature for using the :class:`balderhub.contrib.html.pages.LoginPage` HTML pages + """ + + page = LoginPage() + + def insert_username(self, username: str) -> None: + self.page.input_username.wait_to_be_clickable_for(1).type_text(username, clean_before=True) + + def insert_password(self, password: str) -> None: + self.page.input_password.wait_to_be_clickable_for(1).type_text(password, clean_before=True) + + def submit_login(self) -> None: + self.page.btn_login.wait_to_be_clickable_for(1).click() + + def is_already_logged_in(self): + # TODO improve + self.page.open() + return not self.page.is_applicable()