Selenium page object implementation
Project description
About this
==========
This is page object implementation for selenium library.
Installation
============
```bash
pip install pagium
```
How to use
==========
1. Basic usage
```python
from pagium import Page, PageElement, By, Remote
class GooglePage(Page):
search = PageElement(by=By.NAME, value='q')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search.send_keys(*'python selenium')
```
2. Controls usage
```python
from pagium import Page, PageElement, WebElement, By, Remote, Keys
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class GooglePage(Page):
search = PageElement(SearchInput, by=By.NAME, value='q')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search.fill('python selenium')
```
3. Container usage
```python
from pagium import Page, PageElement, WebElement, By, Remote, Keys
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class SearchForm(WebElement):
input = PageElement(SearchInput, by=By.NAME, value='q')
class GooglePage(Page):
search_form = PageElement(SearchForm)
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search_form.input('python selenium')
```
4. Web driver polling
Pagium has feature polling for web drivers
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
polling_timeout=20,
polling_delay=0.5,
)
```
Polling timeout is retry time for a while command execution raising error and delay is sleep time between retries.
It can be using like
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with wd.enable_polling(20, delay=0.1):
...
```
or like
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
polling_timeout=20,
polling_delay=0.5,
)
with wd.disable_polling():
...
```
5. Assert matchers
```python
from hamcrest import assert_that
from pagium.matchers import has_text, element_exists
from pagium import Page, PageElement, WebElement, By, Keys, Remote
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class SearchForm(WebElement):
input = PageElement(SearchInput, by=By.NAME, value='q')
class GoogleSearchPage(Page):
__path__ = '/'
search_form = PageElement(SearchForm)
result_container = PageElement(by=By.ID, value='center_col')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GoogleSearchPage(wd, 'https://google.com') as page:
page.search_form.input.fill('page object')
assert_that(page.result_container, element_exists(), has_text('page object'))
```
==========
This is page object implementation for selenium library.
Installation
============
```bash
pip install pagium
```
How to use
==========
1. Basic usage
```python
from pagium import Page, PageElement, By, Remote
class GooglePage(Page):
search = PageElement(by=By.NAME, value='q')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search.send_keys(*'python selenium')
```
2. Controls usage
```python
from pagium import Page, PageElement, WebElement, By, Remote, Keys
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class GooglePage(Page):
search = PageElement(SearchInput, by=By.NAME, value='q')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search.fill('python selenium')
```
3. Container usage
```python
from pagium import Page, PageElement, WebElement, By, Remote, Keys
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class SearchForm(WebElement):
input = PageElement(SearchInput, by=By.NAME, value='q')
class GooglePage(Page):
search_form = PageElement(SearchForm)
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GooglePage(wd, 'https://google.com') as page:
page.search_form.input('python selenium')
```
4. Web driver polling
Pagium has feature polling for web drivers
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
polling_timeout=20,
polling_delay=0.5,
)
```
Polling timeout is retry time for a while command execution raising error and delay is sleep time between retries.
It can be using like
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with wd.enable_polling(20, delay=0.1):
...
```
or like
```python
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
polling_timeout=20,
polling_delay=0.5,
)
with wd.disable_polling():
...
```
5. Assert matchers
```python
from hamcrest import assert_that
from pagium.matchers import has_text, element_exists
from pagium import Page, PageElement, WebElement, By, Keys, Remote
class SearchInput(WebElement):
def fill(self, text):
self.send_keys(*text + Keys.ENTER)
class SearchForm(WebElement):
input = PageElement(SearchInput, by=By.NAME, value='q')
class GoogleSearchPage(Page):
__path__ = '/'
search_form = PageElement(SearchForm)
result_container = PageElement(by=By.ID, value='center_col')
wd = Remote(
command_executor='http://localhost:4444/wd/hub',
desired_capabilities={'browserName': 'chrome'},
)
with GoogleSearchPage(wd, 'https://google.com') as page:
page.search_form.input.fill('page object')
assert_that(page.result_container, element_exists(), has_text('page object'))
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pagium-0.0.5.tar.gz
(5.5 kB
view details)
File details
Details for the file pagium-0.0.5.tar.gz
.
File metadata
- Download URL: pagium-0.0.5.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6de924580197186d85f58b6502c07a2ba283c2b509b5d6f697f5c3e48c3f96b0 |
|
MD5 | 1c53e636c7369f7e97dea61313de3cf4 |
|
BLAKE2b-256 | 24b09f134d43d72cf1ad5c37c3c809053b5cd772b62e0c01272799519428c56b |