-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NEW: predefine _wait_decorator impl in support.*
+ bump version to 2.0.0b8
- Loading branch information
Showing
12 changed files
with
305 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "selene" | ||
version = "2.0.0b7" | ||
version = "2.0.0b8" | ||
description = "User-oriented browser tests in Python (Selenide port)" | ||
authors = ["Iakiv Kramarenko <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -44,6 +44,7 @@ python = "^3.7" | |
selenium = "==4.2.0" | ||
future = "*" | ||
webdriver-manager = "==3.7.0" | ||
typing-extensions = "==4.3.0" | ||
|
||
[tool.poetry.dev-dependencies] | ||
black = "^22.3.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# todo: consider renaming support to experimental ... | ||
# todo: consider renaming support to _support to emphasize its experimental nature | ||
|
||
from . import _logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from functools import reduce | ||
from typing import Tuple, ContextManager, Dict, Any, Iterable | ||
from typing_extensions import Protocol | ||
|
||
from selenium.webdriver import Keys | ||
|
||
|
||
class _ContextManagerFactory(Protocol): | ||
def __call__( | ||
self, *, title: str, params: Dict[str, Any], **kwargs | ||
) -> ContextManager: | ||
... | ||
|
||
|
||
class _default_translations: | ||
remove_verbosity = ( | ||
('browser.element', 'element'), | ||
('browser.all', 'all'), | ||
("'css selector', ", ""), | ||
('((', '('), | ||
('))', ')'), | ||
) | ||
identify_assertions = ( | ||
(': has ', ': have '), | ||
(': have ', ': should have '), | ||
(': is ', ': should be '), | ||
(' and is ', ' and be '), | ||
(' and has ', ' and have '), | ||
) | ||
key_codes_to_names = [ | ||
(f"({repr(value)},)", key) | ||
for key, value in Keys.__dict__.items() | ||
if not key.startswith('__') | ||
] | ||
|
||
|
||
def wait_with( | ||
*, | ||
context: _ContextManagerFactory, | ||
translations: Iterable[Tuple[str, str]] = ( | ||
*_default_translations.remove_verbosity, | ||
*_default_translations.identify_assertions, | ||
*_default_translations.key_codes_to_names, | ||
), | ||
): | ||
""" | ||
:return: | ||
Decorator factory to pass to Selene's config._wait_decorator | ||
for logging commands with waiting built in | ||
:param context: | ||
Allure-like ContextManager factory | ||
(i.e. a type/class or function to return python context manager), | ||
that builds a context manager based on title string and params dict | ||
:param translations: | ||
Iterable of translations as (from, to) substitution pairs | ||
to apply to final title string to log | ||
""" | ||
|
||
def decorator_factory(wait): | ||
def decorator(for_): | ||
def decorated(fn): | ||
|
||
title = f'{wait.entity}: {fn}' | ||
|
||
def translate(initial: str, item: Tuple[str, str]): | ||
old, new = item | ||
return initial.replace(old, new) | ||
|
||
translated_title = reduce( | ||
translate, | ||
translations, | ||
title, | ||
) | ||
|
||
with context(title=translated_title, params={}): | ||
return for_(fn) | ||
|
||
return decorated | ||
|
||
return decorator | ||
|
||
return decorator_factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import pytest | ||
|
||
from selene.support import shared | ||
|
||
|
||
def pytest_addoption(parser): | ||
|
||
parser.addoption( | ||
'--headless', | ||
help='headless mode', | ||
default=False, | ||
) | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def quit_shared_browser_afterwards(): | ||
yield | ||
|
||
shared.browser.quit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.