Metadata-Version: 2.1
Name: py-selenium-auto-core
Version: 0.4.3
Summary: Selenium core for Python
Home-page: https://github.com/Polmik/py-selenium-auto-core
Author: Egor Ryaboshapko
Author-email: mrpolmik@hotmail.com
Maintainer: Egor Ryaboshapko
Maintainer-email: mrpolmik@hotmail.com
Keywords: testing,selenium,driver,test automation
Platform: any
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Framework :: Pytest
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: PyHamcrest==1.9.0
Requires-Dist: pytest==7.4.2
Requires-Dist: allure-pytest==2.13.2
Requires-Dist: selenium~=4.11.2
Requires-Dist: webdriver-manager==4.0.0
Requires-Dist: dependency-injector==4.41.0

# Selenium CORE for Python

[![Tests](https://github.com/Polmik/py-selenium-auto-core/actions/workflows/tests.yml/badge.svg)](https://github.com/Polmik/py-selenium-auto-core/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/Polmik/py-selenium-auto-core/branch/main/graph/badge.svg)](https://codecov.io/gh/Polmik/py-selenium-auto-core)

### Introduction

It's a library with core functions simplifying work with Selenium-controlled applications.

This package is based on **Aquality Selenium CORE for .NET** and provides a set of methods related to the most common actions performed with elements. So you shouldn't have a lot of difficulties with this solution if you interacted with **Aquality Selenium CORE**.

To simplify overriding of implementations this solution uses Dependency Injection.

### Supported Python Versions

* Python 3.7-3.9

### Installation 

If you have [pip](https://pip.pypa.io/en/stable/) on your system, you can simply install or upgrade the Python bindings:

```bash
pip install py-selenium-auto-core
```

Alternately, you can download the source distribution from [PyPI](https://pypi.org/project/py-selenium-auto-core/#files), unarchive it, and run:

```bash
python setup.py install
```

### Quick start

1. Setup Dependency Injection container using Startup

The simplest way is to create your own Services class extended from abstract CoreServices with the following simple signature:

```python
class BrowserService(CoreService):

    @staticmethod
    def is_application_started() -> bool:
        return CoreService._is_application_started()

    @staticmethod
    def application() -> YourApplication:
        return CoreService._get_application(lambda service: BrowserService._start_application(service))

    @staticmethod
    def service_provider() -> ServiceProvider:
        return CoreService._get_service_provider(lambda service: BrowserService.application())

    @staticmethod
    def _start_application(service_provider: ServiceProvider):
        ...  # your implementation
```

If you need to register your own services / rewrite the implementation, you need override Startup and implement BrowserServices like in example below:

```python
class BrowserService(CoreService):
    _browser_startup_container: CustomStartup = CustomStartup()

    @staticmethod
    def is_application_started() -> bool:
        return CoreService._is_application_started()

    @staticmethod
    def application() -> Application:
        return CoreService._get_application(lambda service: your_implementation,
                                            lambda: BrowserService._browser_startup_container.configure_services(
                                                lambda service: BrowserService.application()))

    @staticmethod
    def service_provider() -> ServiceProvider:
        return CoreService._get_service_provider(lambda service: BrowserService.application())

    @staticmethod
    def _start_application(service_provider: ServiceProvider):
        ...  # your implementation


class CustomStartup(Startup):

    @staticmethod
    def configure_services(application_provider: Callable, settings: JsonSettingsFile = None) -> ServiceProvider:
        service_provider = Startup.configure_services(application_provider, settings)
        # your implementation service_provider.timeout_configuration.override(Singleton(TimeoutConfiguration, service_provider.settings_file))
        return service_provider
```

2. Work with Application via the implemented BrowserServices or via element services

All the services could be resolved from the Dependency Injection container via ServiceProvider
```python
BrowserServices.application().driver.find_element(ELEMENT).click()
BrowserServices.service_provider().conditional_wait().wait_for_driver(
    lambda driver: len(driver.find_elements(Locator(By.XPATH, "//*"))) > 0
)
```


### License
Library's source code is made available under the [Apache 2.0 license](https://github.com/Polmik/py-selenium-auto-core/blob/main/LICENSE).
