selene_with_new_wdm


Nameselene_with_new_wdm JSON
Version 2.2.1 PyPI version JSON
download
home_pagehttps://yashaka.github.io/selene/
SummarySelene 2.0.0rc4 + webdriver-manager-4.0.2
upload_time2024-09-26 21:01:33
maintainerNone
docs_urlNone
authorYevhen Halitsyn
requires_python<4.0,>=3.9
licenseMIT
keywords testing selenium selenide browser pageobject widget wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            <!-- --8<-- [start:githubSection] -->
# Selene - User-oriented Web UI browser tests in Python (Selenide port)

### This build: Selene 2.0.0rc4 + webdriver-manager-4.0.2

![Pre-release Version](https://img.shields.io/github/v/release/yashaka/selene?label=latest)
[![tests](https://github.com/yashaka/selene/actions/workflows/tests.yml/badge.svg)](https://github.com/yashaka/selene/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/yashaka/selene/branch/master/graph/badge.svg)](https://codecov.io/gh/yashaka/selene)
![Free](https://img.shields.io/badge/free-open--source-green.svg)
[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yashaka/selene/blob/master/LICENSE)

[![Downloads](https://pepy.tech/badge/selene)](https://pepy.tech/project/selene)
[![Project Template](https://img.shields.io/badge/project-template-9cf.svg)](https://github.com/yashaka/python-web-test)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

[![Join telegram chat https://t.me/selene_py](https://img.shields.io/badge/chat-telegram-blue)](https://t.me/selene_py)
[![Присоединяйся к чату https://t.me/selene_py_ru](https://img.shields.io/badge/%D1%87%D0%B0%D1%82-telegram-red)](https://t.me/selene_py_ru)

[![Sign up for a course https://autotest.how/sdet-start](https://img.shields.io/badge/course-sign_up-blue)](https://autotest.how/sdet-start)
[![Запишись на курс https://autotest.how/sdet-start-ru](https://img.shields.io/badge/%D0%BD%D0%B0%D0%B1%D0%BE%D1%80-%D0%BD%D0%B0%20%D0%BA%D1%83%D1%80%D1%81-red)](https://autotest.how/sdet-start-ru)
[![Реєструйся на курс https://autotest.how/sdet-start-uk](https://img.shields.io/badge/%D0%BD%D0%B0%D0%B1%D1%96%D1%80-%D0%BD%D0%B0_%D0%BA%D1%83%D1%80%D1%81-yellow)](https://autotest.how/sdet-start-uk)

Main features:

- **User-oriented API for Selenium Webdriver** (code like speak common English)
- **Ajax support** (Smart implicit waiting and retry mechanism)
- **PageObjects support** (all elements are lazy-evaluated objects)
- **Automatic driver management** (no need to install and setup driver for quick local execution)

Selene was inspired by [Selenide][selenide] from Java world.

Tests with Selene can be built either in a simple straightforward "selenide" style or with PageObjects composed from Widgets i.e. reusable element components.

- [Versions](#versions)
    - [Migration Guide](#migration-guide)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
    - [Quick Start](#quick-start)
    - [Core API](#core-api)
    - [Automatic Driver and Browser Management](#automatic-driver-and-browser-management)
    - [Advanced API](#advanced-api)
- [Tutorials](#tutorials)
- [Examples](#more-examples)
- [Contribution](#contribution)
- [Release Workflow](#release-workflow)
- [Changelog](#changelog)

## Versions

- Latest recommended version to use is [2.0.0b17+][latest-recommended-version]
    - it's a completely new version of selene, with improved API and speed
    - supports Python `3.7+`
    - bundled with Selenium `4.1+`
    - it's incompatible with [1.x][brunch-ver-1]
    - current master branch is pointed to 2.x
    - yet in alpha/beta stage, refining API, improving "migratability" and testing
    - most active Selene users already upgraded to 2.0 alpha/beta 
      and have been using it in production during last 2 years
    - the only risk is API changes, 
      some commands are in progress of deprecation and renaming
- Latest version marked as stable is: [1.0.2][selene-stable]
    - its sources and corresponding README version
    can be found at [1.x][brunch-ver-1] branch.
    - supports python `2.7, 3.5, 3.6, 3.7`

THIS README DESCRIBES THE USAGE OF THE PRE-RELEASE version of Selene. For older docs look at [1.x][brunch-ver-1] branch.

### Migration guide

From `1.0.2` to `2.0.0b<LATEST>`:

- upgrade to Python 3.7+
- update selene to `2.0.0b<LATEST>`
    - find&replace the `collection.first()` method from `.first()` to `.first`
    - ensure all conditions like `text('foo')` are used via `be.*` or `have.*` syntax
        - example:
            - find&replace all
                - `(text('foo'))` to `(have.text('foo'))`
                - `(visible)` to `(be.visible)`
            - smarter find&replace (with some manual refactoring)
                - `.should(x, timeout=y)` to `.with_(timeout=y).should(x)`
                - `.should_not(be.*)` to `.should(be.not_.*)` or `.should(be.*.not_)`
                - `.should_not(have.*)` to `.should(have.no.*)` or `.should(have.*.not_)`
                - `.should_each(condition)` to `.should(condition.each)`
            - and add corresponding imports:
            `from selene import be, have`
    - fix another broken imports if available
    - run tests, read deprecation warnings, and refactor to new style recommended in warning messages

## Prerequisites

[Python 3.7+][python-37]

Given [pyenv][pyenv] installed, installing needed version of Python is pretty simple:

```plain
$ pyenv install 3.7.3
$ pyenv global 3.7.3
$ python -V
Python 3.7.3
```

## Installation

### via poetry + pyenv (recommended)

GIVEN [poetry][poetry] and [pyenv][pyenv] installed ...

AND

```plain
poetry new my-tests-with-selene
cd my-tests-with-selene
pyenv local 3.7.3
```

WHEN latest pre-release recommended version:

```plain
poetry add selene --allow-prereleases
```

WHEN latest stable version:

```plain
poetry add selene
```

THEN

```plain
poetry install
```

### via pip

Latest recommended pre-release alpha version:

```plain
pip install selene --pre
```

Latest stable version:

```plain
pip install selene
```

### from sources

GIVEN webdriver and webdriver_manager are already installed

THEN

```plain
git clone https://github.com/yashaka/selene.git
python setup.py install
```

or using pip:

```plain
pip install git+https://github.com/yashaka/selene.git
```

## Usage

### Quick Start

Simply...

```python
from selene import browser, by, be, have

browser.open('https://google.com/ncr')
browser.element(by.name('q')).should(be.blank)\
    .type('selenium').press_enter()
browser.all('#rso>div').should(have.size_greater_than(5))\
    .first.should(have.text('Selenium automates browsers'))
```

OR with custom setup

```python
from selene import browser, by, be, have

browser.config.driver_name = 'firefox'
browser.config.base_url = 'https://google.com'
browser.config.timeout = 2
# browser.config.* = ...

browser.open('/ncr')
browser.element(by.name('q')).should(be.blank) \
    .type('selenium').press_enter()
browser.all('#rso>div').should(have.size_greater_than(5)) \
    .first.should(have.text('Selenium automates browsers'))
```

OR more Selenide from java style:

```python
from selene import browser, by, be, have
from selene.support.shared import config
from selene.support.shared.jquery_style import s, ss


config.browser_name = 'firefox'
config.base_url = 'https://google.com'
config.timeout = 2
# config.* = ...

browser.open('/ncr')
s(by.name('q')).should(be.blank) \
    .type('selenium').press_enter()
ss('#rso>div').should(have.size_greater_than(5)) \
    .first.should(have.text('Selenium automates browsers'))
```

### Core Api


```python

# Given:
from selenium.webdriver import Chrome

# AND chromedriver executable available in $PATH

# WHEN:
from selene import Browser, Config

browser = Browser(
    Config(
        driver=Chrome(),
        base_url='https://google.com',
        timeout=2,
    )
)

# AND:
browser.open('/ncr')

# AND:
# browser.element('//*[@name="q"]')).type('selenium').press_enter()
# OR...
# browser.element('[name=q]')).type('selenium').press_enter()
# OR...
from selene import by
# browser.element(by.name('q')).type('selenium').press_enter()
# OR...for total readability
query = browser.element(by.name('q'))
# actual search doesn't start on calling browser.element above, 
# i.e. the element is "lazy"... or in other words it serves as locator         
# Below, on calling actual first action, 
#     ⬇ the actual webelement is located first time
query.type('selenium').press_enter()       
#                      ⬆
#                  and here it's located again, i.e. the element is "dynamic"

# AND in case we need to filter collection of items 
#     by some condition like visibility:

from selene import be
results = browser.all('#rso>div').by(be.visible)

# THEN we can assert some condition:
from selene import have
# results.should(have.size_greater_than(5))
# results.first.should(have.text('Selenium automates browsers'))
# OR...
results.should(have.size_greater_than(5))\
    .first.should(have.text('Selenium automates browsers'))

# FINALLY the browser can be quit:
browser.quit()
# but it's not mandatory, because by default Selenes kills all drivers on exit
# that can be disabled by:
browser.config.hold_driver_at_exit = True
```

### Automatic Driver and Browser Management

Instead of:

```python
from selenium.webdriver import Chrome
from selene import Browser, Config

browser = Browser(
    Config(
        driver=Chrome(),
        base_url='https://google.com',
        timeout=2
    )
)

browser.open('/ncr')
```

You can simply use the browser instance predefined for you in `selene` module:

```python
from selene import browser

browser.config.base_url = 'https://google.com'
browser.config.timeout = 2

browser.open('/ncr')
```

So you don't need to create you driver instance manually. It will be created for you automatically.

Yet, if you need some special case, like working with remote driver, etc., you can still use shared browser object with additional configuration:

```python
from selenium import webdriver
from selene import browser

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-notifications')
options.add_argument('--disable-extensions')
options.add_argument('--disable-infobars')
options.add_argument('--enable-automation')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-setuid-sandbox')
browser.config.driver_options = options
browser.config.driver_remote_url = 'http://localhost:4444/wd/hub', 
browser.config.base_url = 'https://google.com'
browser.config.timeout = 2

browser.open('/ncr')
...
```

But if you like to create the driver on your own, you can do it too:

```python
from selenium import webdriver
from selene import browser

options = webdriver.ChromeOptions()
options.add_argument('--headless')
# ... other arguments
browser.config.driver = webdriver.Remote(
  'http://localhost:4444/wd/hub', 
  options=options
)
# Once you start to build and set the driver on your own,
# probably you are going to fully manage it life cycle,
# thus, consider disabling the automatic driver reset on browser.open
# if driver was crashed or quit:
browser.config._reset_not_alive_driver_on_get_url = False
# And consider disabling the automatic driver quit on exit:
browser.config.hold_driver_at_exit = True
# Other common options will still be useful:
browser.config.base_url = 'https://google.com'
browser.config.timeout = 2

browser.open('/ncr')
...

# Finally, you can quit the driver manually:
browser.quit()
```

### Advanced API

Sometimes you might need some extra things to reach your specific goals... Here go examples of Selene's `command`, `query`, custom conditions, `.matching(condition)` and `.wait_until(condition)`...

```python
from selene import browser, have

...

###################################################
# Maybe you need some advanced actions on elements,
# e.g. for workaround something through js:

from selene import command

browser.element('#not-in-view').perform(command.js.scroll_into_view)

...

###################################################
# Probably you think that will need something like:

from selene import query

...

def my_int_from(text):
    return int(text.split(' ')[0])

product_text = browser.element('#price-label').get(query.text)
# ... to assert something not standard:
price = my_int_from(product_text)
assert price > 100

# But such version is very unstable in dynamic web world...
# Usually it's...
# either better to implement your custom condition:

from selene.core.condition import Condition
from selene.core.conditions import ElementCondition
from selene.core.entity import Element


def have_in_text_the_int_number_more_than(number) -> Condition[Element]:
    def fn(element: Element) -> None:
        text = element.get(query.text)
        parsed_number = my_int_from(text)
        if not parsed_number > number:
            raise AssertionError(
                f'actual text was: {text}'
                f'with parsed int number: {parsed_number}'
            )
    return ElementCondition(
        f'has in text the int number more than: {number}', 
        fn
    )


browser.element('#price-label').should(
    have_in_text_the_int_number_more_than(100)
)
'''
# You even can create your own project_package/selene_extensions/have.py
# with the following content:

from selene.support.conditioins.have import *

def int_number_more_than(number) -> Condition[Element]:
    def fn(element: Element) -> None:
        text = element.get(query.text)
        parsed_number = my_int_from(text)
        if not parsed_number > number:
            raise AssertionError(
                f'actual text was: {text}'
                f'with parsed int number: {parsed_number}'
            )
    return ElementCondition(
        f'has in text the int number more than: {number}', 
        fn
    )
    
# And then in your test:

from project_package.selene_extensions import have

browser.element('#price-label').should(have.text('Price: ') \
    .should(have.int_number_more_than(100))

# i.e. using it same style as in selene,
# with also access to all original selene conditions
'''

# Such condition-based alternative to the original `assert price > 100` is less fragile,
# because Python's `assert` does not have "implicit waiting",
# while Selene's `should` command does have ;)

# Furthermore, the good test is when you totally control your test data, 
# and the code like below:

product = browser.element('#to-remember-for-future')

product_text_before = product.get(query.text)
price_before = my_int_from(product_text_before)

... # some test steps

product_text_after = product.get(query.text)
price_after = my_int_from(product_text_after)

assert price_after > price_before

# – normally, should be refactored to something like:

product = browser.element('#to-remember-for-future')

product.should(have.text('100$'))

... # some test steps

product.should(have.text('125$'))


###############################################
# You might also think you need something like:

from selene import query

if browser.element('#i-might-say-yes-or-no').get(query.text) == 'yes':
    ...  # do something...

# Or:

from selene import query

if browser.all('.option').get(query.size) >= 2:
    ...  # do something...

# – maybe, one day, you really find a use case:)

# But for above cases, probably easier would be:

if browser.element('#i-might-say-yes-or-no').wait_until(have.text('yes')):
    ...  # do something

...

if browser.all('.i-will-appear').wait_until(have.size_greater_than_or_equal(2)):
    ...  # do something

# Or, by using non-waiting versions, if "you are in a rush:)":

if browser.element('#i-might-say-yes-or-no').matching(have.text('yes')):
    ...  # do something

...

if browser.all('.i-will-appear').matching(have.size_greater_than_or_equal(2)):
    ... # do something
```

## Tutorials

TBD

## More Examples

- [Project template][project-template]

TBD

## Contribution

[see CONTRIBUTING.md][contribution]

## Release Workflow

[see Release workflow][release-workflow]

## Changelog

[see CHANGELOG.md][changelog]

<!-- References -->
[selenide]: http://selenide.org/
[latest-recommended-version]: https://pypi.org/project/selene/2.0.0rc2/
[brunch-ver-1]: https://github.com/yashaka/selene/tree/1.x
[selene-stable]: https://pypi.org/project/selene/1.0.2/
[python-37]: https://www.python.org/downloads/release/python-370/
[pyenv]: https://github.com/pyenv/pyenv
[poetry]: https://python-poetry.org/
[project-template]: https://github.com/yashaka/python-web-test
<!-- --8<-- [end:githubSection] -->

<!-- GitHub only references -->
[contribution]: https://yashaka.github.io/selene/contribution/to-source-code-guide/
[release-workflow]: https://yashaka.github.io/selene/contribution/release-workflow-guide/
[changelog]: https://yashaka.github.io/selene/changelog/

            

Raw data

            {
    "_id": null,
    "home_page": "https://yashaka.github.io/selene/",
    "name": "selene_with_new_wdm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "testing, selenium, selenide, browser, pageobject, widget, wrapper",
    "author": "Yevhen Halitsyn",
    "author_email": "yevhen.halitsyn@nixs.com",
    "download_url": "https://files.pythonhosted.org/packages/df/f4/e3169662cca2a623990d762f42566ebba30d1759f708e38cffe5a732c2de/selene_with_new_wdm-2.2.1.tar.gz",
    "platform": null,
    "description": "<!-- --8<-- [start:githubSection] -->\n# Selene - User-oriented Web UI browser tests in Python (Selenide port)\n\n### This build: Selene 2.0.0rc4 + webdriver-manager-4.0.2\n\n![Pre-release Version](https://img.shields.io/github/v/release/yashaka/selene?label=latest)\n[![tests](https://github.com/yashaka/selene/actions/workflows/tests.yml/badge.svg)](https://github.com/yashaka/selene/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/yashaka/selene/branch/master/graph/badge.svg)](https://codecov.io/gh/yashaka/selene)\n![Free](https://img.shields.io/badge/free-open--source-green.svg)\n[![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yashaka/selene/blob/master/LICENSE)\n\n[![Downloads](https://pepy.tech/badge/selene)](https://pepy.tech/project/selene)\n[![Project Template](https://img.shields.io/badge/project-template-9cf.svg)](https://github.com/yashaka/python-web-test)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n[![Join telegram chat https://t.me/selene_py](https://img.shields.io/badge/chat-telegram-blue)](https://t.me/selene_py)\n[![\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0439\u0441\u044f \u043a \u0447\u0430\u0442\u0443 https://t.me/selene_py_ru](https://img.shields.io/badge/%D1%87%D0%B0%D1%82-telegram-red)](https://t.me/selene_py_ru)\n\n[![Sign up for a course https://autotest.how/sdet-start](https://img.shields.io/badge/course-sign_up-blue)](https://autotest.how/sdet-start)\n[![\u0417\u0430\u043f\u0438\u0448\u0438\u0441\u044c \u043d\u0430 \u043a\u0443\u0440\u0441 https://autotest.how/sdet-start-ru](https://img.shields.io/badge/%D0%BD%D0%B0%D0%B1%D0%BE%D1%80-%D0%BD%D0%B0%20%D0%BA%D1%83%D1%80%D1%81-red)](https://autotest.how/sdet-start-ru)\n[![\u0420\u0435\u0454\u0441\u0442\u0440\u0443\u0439\u0441\u044f \u043d\u0430 \u043a\u0443\u0440\u0441 https://autotest.how/sdet-start-uk](https://img.shields.io/badge/%D0%BD%D0%B0%D0%B1%D1%96%D1%80-%D0%BD%D0%B0_%D0%BA%D1%83%D1%80%D1%81-yellow)](https://autotest.how/sdet-start-uk)\n\nMain features:\n\n- **User-oriented API for Selenium Webdriver** (code like speak common English)\n- **Ajax support** (Smart implicit waiting and retry mechanism)\n- **PageObjects support** (all elements are lazy-evaluated objects)\n- **Automatic driver management** (no need to install and setup driver for quick local execution)\n\nSelene was inspired by [Selenide][selenide] from Java world.\n\nTests with Selene can be built either in a simple straightforward \"selenide\" style or with PageObjects composed from Widgets i.e. reusable element components.\n\n- [Versions](#versions)\n    - [Migration Guide](#migration-guide)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Quick Start](#quick-start)\n    - [Core API](#core-api)\n    - [Automatic Driver and Browser Management](#automatic-driver-and-browser-management)\n    - [Advanced API](#advanced-api)\n- [Tutorials](#tutorials)\n- [Examples](#more-examples)\n- [Contribution](#contribution)\n- [Release Workflow](#release-workflow)\n- [Changelog](#changelog)\n\n## Versions\n\n- Latest recommended version to use is [2.0.0b17+][latest-recommended-version]\n    - it's a completely new version of selene, with improved API and speed\n    - supports Python `3.7+`\n    - bundled with Selenium `4.1+`\n    - it's incompatible with [1.x][brunch-ver-1]\n    - current master branch is pointed to 2.x\n    - yet in alpha/beta stage, refining API, improving \"migratability\" and testing\n    - most active Selene users already upgraded to 2.0 alpha/beta \n      and have been using it in production during last 2 years\n    - the only risk is API changes, \n      some commands are in progress of deprecation and renaming\n- Latest version marked as stable is: [1.0.2][selene-stable]\n    - its sources and corresponding README version\n    can be found at [1.x][brunch-ver-1] branch.\n    - supports python `2.7, 3.5, 3.6, 3.7`\n\nTHIS README DESCRIBES THE USAGE OF THE PRE-RELEASE version of Selene. For older docs look at [1.x][brunch-ver-1] branch.\n\n### Migration guide\n\nFrom `1.0.2` to `2.0.0b<LATEST>`:\n\n- upgrade to Python 3.7+\n- update selene to `2.0.0b<LATEST>`\n    - find&replace the `collection.first()` method from `.first()` to `.first`\n    - ensure all conditions like `text('foo')` are used via `be.*` or `have.*` syntax\n        - example:\n            - find&replace all\n                - `(text('foo'))` to `(have.text('foo'))`\n                - `(visible)` to `(be.visible)`\n            - smarter find&replace (with some manual refactoring)\n                - `.should(x, timeout=y)` to `.with_(timeout=y).should(x)`\n                - `.should_not(be.*)` to `.should(be.not_.*)` or `.should(be.*.not_)`\n                - `.should_not(have.*)` to `.should(have.no.*)` or `.should(have.*.not_)`\n                - `.should_each(condition)` to `.should(condition.each)`\n            - and add corresponding imports:\n            `from selene import be, have`\n    - fix another broken imports if available\n    - run tests, read deprecation warnings, and refactor to new style recommended in warning messages\n\n## Prerequisites\n\n[Python 3.7+][python-37]\n\nGiven [pyenv][pyenv] installed, installing needed version of Python is pretty simple:\n\n```plain\n$ pyenv install 3.7.3\n$ pyenv global 3.7.3\n$ python -V\nPython 3.7.3\n```\n\n## Installation\n\n### via poetry + pyenv (recommended)\n\nGIVEN [poetry][poetry] and [pyenv][pyenv] installed ...\n\nAND\n\n```plain\npoetry new my-tests-with-selene\ncd my-tests-with-selene\npyenv local 3.7.3\n```\n\nWHEN latest pre-release recommended version:\n\n```plain\npoetry add selene --allow-prereleases\n```\n\nWHEN latest stable version:\n\n```plain\npoetry add selene\n```\n\nTHEN\n\n```plain\npoetry install\n```\n\n### via pip\n\nLatest recommended pre-release alpha version:\n\n```plain\npip install selene --pre\n```\n\nLatest stable version:\n\n```plain\npip install selene\n```\n\n### from sources\n\nGIVEN webdriver and webdriver_manager are already installed\n\nTHEN\n\n```plain\ngit clone https://github.com/yashaka/selene.git\npython setup.py install\n```\n\nor using pip:\n\n```plain\npip install git+https://github.com/yashaka/selene.git\n```\n\n## Usage\n\n### Quick Start\n\nSimply...\n\n```python\nfrom selene import browser, by, be, have\n\nbrowser.open('https://google.com/ncr')\nbrowser.element(by.name('q')).should(be.blank)\\\n    .type('selenium').press_enter()\nbrowser.all('#rso>div').should(have.size_greater_than(5))\\\n    .first.should(have.text('Selenium automates browsers'))\n```\n\nOR with custom setup\n\n```python\nfrom selene import browser, by, be, have\n\nbrowser.config.driver_name = 'firefox'\nbrowser.config.base_url = 'https://google.com'\nbrowser.config.timeout = 2\n# browser.config.* = ...\n\nbrowser.open('/ncr')\nbrowser.element(by.name('q')).should(be.blank) \\\n    .type('selenium').press_enter()\nbrowser.all('#rso>div').should(have.size_greater_than(5)) \\\n    .first.should(have.text('Selenium automates browsers'))\n```\n\nOR more Selenide from java style:\n\n```python\nfrom selene import browser, by, be, have\nfrom selene.support.shared import config\nfrom selene.support.shared.jquery_style import s, ss\n\n\nconfig.browser_name = 'firefox'\nconfig.base_url = 'https://google.com'\nconfig.timeout = 2\n# config.* = ...\n\nbrowser.open('/ncr')\ns(by.name('q')).should(be.blank) \\\n    .type('selenium').press_enter()\nss('#rso>div').should(have.size_greater_than(5)) \\\n    .first.should(have.text('Selenium automates browsers'))\n```\n\n### Core Api\n\n\n```python\n\n# Given:\nfrom selenium.webdriver import Chrome\n\n# AND chromedriver executable available in $PATH\n\n# WHEN:\nfrom selene import Browser, Config\n\nbrowser = Browser(\n    Config(\n        driver=Chrome(),\n        base_url='https://google.com',\n        timeout=2,\n    )\n)\n\n# AND:\nbrowser.open('/ncr')\n\n# AND:\n# browser.element('//*[@name=\"q\"]')).type('selenium').press_enter()\n# OR...\n# browser.element('[name=q]')).type('selenium').press_enter()\n# OR...\nfrom selene import by\n# browser.element(by.name('q')).type('selenium').press_enter()\n# OR...for total readability\nquery = browser.element(by.name('q'))\n# actual search doesn't start on calling browser.element above, \n# i.e. the element is \"lazy\"... or in other words it serves as locator         \n# Below, on calling actual first action, \n#     \u2b07 the actual webelement is located first time\nquery.type('selenium').press_enter()       \n#                      \u2b06\n#                  and here it's located again, i.e. the element is \"dynamic\"\n\n# AND in case we need to filter collection of items \n#     by some condition like visibility:\n\nfrom selene import be\nresults = browser.all('#rso>div').by(be.visible)\n\n# THEN we can assert some condition:\nfrom selene import have\n# results.should(have.size_greater_than(5))\n# results.first.should(have.text('Selenium automates browsers'))\n# OR...\nresults.should(have.size_greater_than(5))\\\n    .first.should(have.text('Selenium automates browsers'))\n\n# FINALLY the browser can be quit:\nbrowser.quit()\n# but it's not mandatory, because by default Selenes kills all drivers on exit\n# that can be disabled by:\nbrowser.config.hold_driver_at_exit = True\n```\n\n### Automatic Driver and Browser Management\n\nInstead of:\n\n```python\nfrom selenium.webdriver import Chrome\nfrom selene import Browser, Config\n\nbrowser = Browser(\n    Config(\n        driver=Chrome(),\n        base_url='https://google.com',\n        timeout=2\n    )\n)\n\nbrowser.open('/ncr')\n```\n\nYou can simply use the browser instance predefined for you in `selene` module:\n\n```python\nfrom selene import browser\n\nbrowser.config.base_url = 'https://google.com'\nbrowser.config.timeout = 2\n\nbrowser.open('/ncr')\n```\n\nSo you don't need to create you driver instance manually. It will be created for you automatically.\n\nYet, if you need some special case, like working with remote driver, etc., you can still use shared browser object with additional configuration:\n\n```python\nfrom selenium import webdriver\nfrom selene import browser\n\noptions = webdriver.ChromeOptions()\noptions.add_argument('--headless')\noptions.add_argument('--no-sandbox')\noptions.add_argument('--disable-gpu')\noptions.add_argument('--disable-notifications')\noptions.add_argument('--disable-extensions')\noptions.add_argument('--disable-infobars')\noptions.add_argument('--enable-automation')\noptions.add_argument('--disable-dev-shm-usage')\noptions.add_argument('--disable-setuid-sandbox')\nbrowser.config.driver_options = options\nbrowser.config.driver_remote_url = 'http://localhost:4444/wd/hub', \nbrowser.config.base_url = 'https://google.com'\nbrowser.config.timeout = 2\n\nbrowser.open('/ncr')\n...\n```\n\nBut if you like to create the driver on your own, you can do it too:\n\n```python\nfrom selenium import webdriver\nfrom selene import browser\n\noptions = webdriver.ChromeOptions()\noptions.add_argument('--headless')\n# ... other arguments\nbrowser.config.driver = webdriver.Remote(\n  'http://localhost:4444/wd/hub', \n  options=options\n)\n# Once you start to build and set the driver on your own,\n# probably you are going to fully manage it life cycle,\n# thus, consider disabling the automatic driver reset on browser.open\n# if driver was crashed or quit:\nbrowser.config._reset_not_alive_driver_on_get_url = False\n# And consider disabling the automatic driver quit on exit:\nbrowser.config.hold_driver_at_exit = True\n# Other common options will still be useful:\nbrowser.config.base_url = 'https://google.com'\nbrowser.config.timeout = 2\n\nbrowser.open('/ncr')\n...\n\n# Finally, you can quit the driver manually:\nbrowser.quit()\n```\n\n### Advanced API\n\nSometimes you might need some extra things to reach your specific goals... Here go examples of Selene's `command`, `query`, custom conditions, `.matching(condition)` and `.wait_until(condition)`...\n\n```python\nfrom selene import browser, have\n\n...\n\n###################################################\n# Maybe you need some advanced actions on elements,\n# e.g. for workaround something through js:\n\nfrom selene import command\n\nbrowser.element('#not-in-view').perform(command.js.scroll_into_view)\n\n...\n\n###################################################\n# Probably you think that will need something like:\n\nfrom selene import query\n\n...\n\ndef my_int_from(text):\n    return int(text.split(' ')[0])\n\nproduct_text = browser.element('#price-label').get(query.text)\n# ... to assert something not standard:\nprice = my_int_from(product_text)\nassert price > 100\n\n# But such version is very unstable in dynamic web world...\n# Usually it's...\n# either better to implement your custom condition:\n\nfrom selene.core.condition import Condition\nfrom selene.core.conditions import ElementCondition\nfrom selene.core.entity import Element\n\n\ndef have_in_text_the_int_number_more_than(number) -> Condition[Element]:\n    def fn(element: Element) -> None:\n        text = element.get(query.text)\n        parsed_number = my_int_from(text)\n        if not parsed_number > number:\n            raise AssertionError(\n                f'actual text was: {text}'\n                f'with parsed int number: {parsed_number}'\n            )\n    return ElementCondition(\n        f'has in text the int number more than: {number}', \n        fn\n    )\n\n\nbrowser.element('#price-label').should(\n    have_in_text_the_int_number_more_than(100)\n)\n'''\n# You even can create your own project_package/selene_extensions/have.py\n# with the following content:\n\nfrom selene.support.conditioins.have import *\n\ndef int_number_more_than(number) -> Condition[Element]:\n    def fn(element: Element) -> None:\n        text = element.get(query.text)\n        parsed_number = my_int_from(text)\n        if not parsed_number > number:\n            raise AssertionError(\n                f'actual text was: {text}'\n                f'with parsed int number: {parsed_number}'\n            )\n    return ElementCondition(\n        f'has in text the int number more than: {number}', \n        fn\n    )\n    \n# And then in your test:\n\nfrom project_package.selene_extensions import have\n\nbrowser.element('#price-label').should(have.text('Price: ') \\\n    .should(have.int_number_more_than(100))\n\n# i.e. using it same style as in selene,\n# with also access to all original selene conditions\n'''\n\n# Such condition-based alternative to the original `assert price > 100` is less fragile,\n# because Python's `assert` does not have \"implicit waiting\",\n# while Selene's `should` command does have ;)\n\n# Furthermore, the good test is when you totally control your test data, \n# and the code like below:\n\nproduct = browser.element('#to-remember-for-future')\n\nproduct_text_before = product.get(query.text)\nprice_before = my_int_from(product_text_before)\n\n... # some test steps\n\nproduct_text_after = product.get(query.text)\nprice_after = my_int_from(product_text_after)\n\nassert price_after > price_before\n\n# \u2013 normally, should be refactored to something like:\n\nproduct = browser.element('#to-remember-for-future')\n\nproduct.should(have.text('100$'))\n\n... # some test steps\n\nproduct.should(have.text('125$'))\n\n\n###############################################\n# You might also think you need something like:\n\nfrom selene import query\n\nif browser.element('#i-might-say-yes-or-no').get(query.text) == 'yes':\n    ...  # do something...\n\n# Or:\n\nfrom selene import query\n\nif browser.all('.option').get(query.size) >= 2:\n    ...  # do something...\n\n# \u2013 maybe, one day, you really find a use case:)\n\n# But for above cases, probably easier would be:\n\nif browser.element('#i-might-say-yes-or-no').wait_until(have.text('yes')):\n    ...  # do something\n\n...\n\nif browser.all('.i-will-appear').wait_until(have.size_greater_than_or_equal(2)):\n    ...  # do something\n\n# Or, by using non-waiting versions, if \"you are in a rush:)\":\n\nif browser.element('#i-might-say-yes-or-no').matching(have.text('yes')):\n    ...  # do something\n\n...\n\nif browser.all('.i-will-appear').matching(have.size_greater_than_or_equal(2)):\n    ... # do something\n```\n\n## Tutorials\n\nTBD\n\n## More Examples\n\n- [Project template][project-template]\n\nTBD\n\n## Contribution\n\n[see CONTRIBUTING.md][contribution]\n\n## Release Workflow\n\n[see Release workflow][release-workflow]\n\n## Changelog\n\n[see CHANGELOG.md][changelog]\n\n<!-- References -->\n[selenide]: http://selenide.org/\n[latest-recommended-version]: https://pypi.org/project/selene/2.0.0rc2/\n[brunch-ver-1]: https://github.com/yashaka/selene/tree/1.x\n[selene-stable]: https://pypi.org/project/selene/1.0.2/\n[python-37]: https://www.python.org/downloads/release/python-370/\n[pyenv]: https://github.com/pyenv/pyenv\n[poetry]: https://python-poetry.org/\n[project-template]: https://github.com/yashaka/python-web-test\n<!-- --8<-- [end:githubSection] -->\n\n<!-- GitHub only references -->\n[contribution]: https://yashaka.github.io/selene/contribution/to-source-code-guide/\n[release-workflow]: https://yashaka.github.io/selene/contribution/release-workflow-guide/\n[changelog]: https://yashaka.github.io/selene/changelog/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Selene 2.0.0rc4 + webdriver-manager-4.0.2",
    "version": "2.2.1",
    "project_urls": {
        "Changelog": "https://github.com/yashaka/selene/releases",
        "Documentation": "https://yashaka.github.io/selene/",
        "Homepage": "https://yashaka.github.io/selene/",
        "Repository": "https://github.com/yashaka/selene/"
    },
    "split_keywords": [
        "testing",
        " selenium",
        " selenide",
        " browser",
        " pageobject",
        " widget",
        " wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "591bd207a9a5ba2e4544f3fcb4b2290cebaa5dd4f775a95fec1b8161c3270d01",
                "md5": "740759ba845090ac6c7743db6a061ded",
                "sha256": "1ada99d3b018c01d56f094ff65dab798ddcab340a0601b8e5fd4537cc36f3fd4"
            },
            "downloads": -1,
            "filename": "selene_with_new_wdm-2.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "740759ba845090ac6c7743db6a061ded",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 89129,
            "upload_time": "2024-09-26T21:01:32",
            "upload_time_iso_8601": "2024-09-26T21:01:32.178867Z",
            "url": "https://files.pythonhosted.org/packages/59/1b/d207a9a5ba2e4544f3fcb4b2290cebaa5dd4f775a95fec1b8161c3270d01/selene_with_new_wdm-2.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dff4e3169662cca2a623990d762f42566ebba30d1759f708e38cffe5a732c2de",
                "md5": "97d21b5395afacfd034daf725d8a14c2",
                "sha256": "f3c670b022255d550d1ce3503d9bb2507c429f0f617a2170362cf733840cdfec"
            },
            "downloads": -1,
            "filename": "selene_with_new_wdm-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "97d21b5395afacfd034daf725d8a14c2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 68432,
            "upload_time": "2024-09-26T21:01:33",
            "upload_time_iso_8601": "2024-09-26T21:01:33.659508Z",
            "url": "https://files.pythonhosted.org/packages/df/f4/e3169662cca2a623990d762f42566ebba30d1759f708e38cffe5a732c2de/selene_with_new_wdm-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-26 21:01:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "yashaka",
    "github_project": "selene",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "selene_with_new_wdm"
}
        
Elapsed time: 1.74965s