From 6c1bb5f10847c6fc9f0794af05a0d238f2ed7f2f Mon Sep 17 00:00:00 2001 From: yashaka Date: Fri, 24 Jun 2022 13:57:26 +0300 Subject: [PATCH] NEW: added command.js.remove & similar: - set_style_display_to_none - set_style_display_to_block - set_style_visibility_to_hidden - set_style_visibility_to_visible TODO: - cover with tests - consider approving element._execut_script, making it public --- CHANGELOG.md | 17 +++++++++-- README.md | 2 +- pyproject.toml | 2 +- selene/__init__.py | 2 +- selene/core/command.py | 69 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f119bd05..63654796 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,11 +78,24 @@ - should we make original config (not shared) mutable? - TODO: support python 3.10 [#393](https://github.com/yashaka/selene/issues/393) -## 2.0.0b5 (to be released on xx.06.2022) +## 2.0.0b6 (to be released on xx.06.2022) - TODO: trim text in have.exact_text -## 2.0.0b4 (to be released on 15.06.2022) +## 2.0.0b5 (to be released on 24.06.2022) +- NEW: added command.js.*: + - remove + - set_style_display_to_none + - set_style_display_to_block + - set_style_visibility_to_hidden + - set_style_visibility_to_visible + Example: + ``` + browser.all('[id^=google_ads]').perform(command.js.remove) + ``` + + +## 2.0.0b4 (released on 15.06.2022) - NEW: upgrade selenium to 4.2.0 & webdriver-manager to 3.7.0 - FIX: set_window_size in shared.browser.open - FIX: provide correct chrome type for wdm diff --git a/README.md b/README.md index 5a111672..b39e0e7d 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Tests with Selene can be built either in a simple straightforward "selenide' sty ## Versions -* Latest recommended version to use is >= [2.0.0b4](https://pypi.org/project/selene/2.0.0b4/) +* Latest recommended version to use is >= [2.0.0b5](https://pypi.org/project/selene/2.0.0b5/) * it's a completely new version of selene, with improved API and speed * supports 3.7 <= python <= 3.9, * bundled with Selenium = 4.1 diff --git a/pyproject.toml b/pyproject.toml index ba641c78..1f58aac1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "selene" -version = "2.0.0b4" +version = "2.0.0b5" description = "User-oriented browser tests in Python (Selenide port)" authors = ["Iakiv Kramarenko "] license = "MIT" diff --git a/selene/__init__.py b/selene/__init__.py index 7c2bc648..dd037910 100644 --- a/selene/__init__.py +++ b/selene/__init__.py @@ -220,7 +220,7 @@ # """ # todo: add here some type imports like Element, Collection, etc. -__version__ = '2.0.0b4' +__version__ = '2.0.0b5' # --- DEPRECATED, and will be removed soon --- # diff --git a/selene/core/command.py b/selene/core/command.py index 2c3d430a..6db811b3 100644 --- a/selene/core/command.py +++ b/selene/core/command.py @@ -86,3 +86,72 @@ def fn(element: Element): })(arguments[0]);""" ), ) + + # remove = Command( + # 'remove', + # lambda element: element.execute_script( + # """return (function(element) { + # element.remove(); + # })(arguments[0]);""" + # ), + # ) + + remove = Command( + 'remove', + lambda entity: ( + entity._execute_script('element.remove()') + if not hasattr(entity, '__iter__') + else [ + element._execute_script('element.remove()') + for element in entity + ] + ), + ) + + set_style_display_to_none = Command( + 'set element.style.display="none"', + lambda entity: ( + entity._execute_script('element.style.display="none"') + if not hasattr(entity, '__iter__') + else [ + element._execute_script('element.style.display="none"') + for element in entity + ] + ), + ) + + set_style_display_to_block = Command( + 'set element.style.display="block"', + lambda entity: ( + entity._execute_script('element.style.display="block"') + if not hasattr(entity, '__iter__') + else [ + element._execute_script('element.style.display="block"') + for element in entity + ] + ), + ) + + set_style_visibility_to_hidden = Command( + 'set element.style.visibility="hidden"', + lambda entity: ( + entity._execute_script('element.style.visibility="hidden"') + if not hasattr(entity, '__iter__') + else [ + element._execute_script('element.style.visibility="hidden"') + for element in entity + ] + ), + ) + + set_style_visibility_to_visible = Command( + 'set element.style.visibility="visible"', + lambda entity: ( + entity._execute_script('element.style.visibility="visible"') + if not hasattr(entity, '__iter__') + else [ + element._execute_script('element.style.visibility="visible"') + for element in entity + ] + ), + )