diff --git a/screenpy_selenium/resolutions/is_visible.py b/screenpy_selenium/resolutions/is_visible.py index 274d0bd..7a5283e 100644 --- a/screenpy_selenium/resolutions/is_visible.py +++ b/screenpy_selenium/resolutions/is_visible.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING -from screenpy.resolutions.base_resolution import BaseResolution +from screenpy import beat from .custom_matchers import is_visible_element @@ -12,7 +12,7 @@ from .custom_matchers.is_visible_element import IsVisibleElement -class IsVisible(BaseResolution): +class IsVisible: """Match on a visible element. Examples:: @@ -20,9 +20,11 @@ class IsVisible(BaseResolution): the_actor.should(See.the(Element(WELCOME_BANNER), IsVisible())) """ - matcher: IsVisibleElement - line = "visible" - matcher_function = is_visible_element + def describe(self) -> str: + """Describe the Resolution's expectation.""" + return "visible" - def __init__(self) -> None: # pylint: disable=useless-super-delegation - super().__init__() + @beat("... hoping it's visible") + def resolve(self) -> IsVisibleElement: + """Produce the Matcher to make the assertion.""" + return is_visible_element() diff --git a/tests/test_resolutions.py b/tests/test_resolutions.py index c369aa9..3694c6e 100644 --- a/tests/test_resolutions.py +++ b/tests/test_resolutions.py @@ -67,7 +67,7 @@ def test_matches_a_clickable_element(self) -> None: element.is_displayed.return_value = True ic = IsClickable().resolve() - assert ic.matches(element) + assert ic._matches(element) def test_does_not_match_unclickable_element(self) -> None: invisible_element = get_mocked_element() @@ -121,14 +121,14 @@ def test_can_be_instantiated(self) -> None: def test_matches_a_visible_element(self) -> None: element = get_mocked_element() element.is_displayed.return_value = True - iv = IsVisible() + iv: IsVisibleElement = IsVisible().resolve() assert iv._matches(element) def test_does_not_match_invisible_element(self) -> None: element = get_mocked_element() element.is_displayed.return_value = False - iv = IsVisible() + iv = IsVisible().resolve() assert not iv._matches(None) # element was not found by Element() assert not iv._matches(element) @@ -141,14 +141,16 @@ def test_descriptions(self) -> None: describe_mismatch="was not visible", describe_none="was not even present", ) + iv = IsVisible() - _assert_descriptions(IsVisible(), element, expected) + assert iv.describe() == "visible" + _assert_descriptions(iv.resolve(), element, expected) def test_type_hint(self) -> None: iv = IsVisible() - annotation = iv.__annotations__["matcher"] + annotation = iv.resolve.__annotations__["return"] assert annotation == "IsVisibleElement" - assert type(iv.matcher) == IsVisibleElement + assert type(iv.resolve()) == IsVisibleElement class TestIsInvisible: @@ -197,6 +199,10 @@ def test_descriptions(self) -> None: assert describe_mismatch.out == expected.describe_mismatch assert describe_none.out == expected.describe_none + ii = IsInvisible() + + assert ii.describe() == "invisible" + def test_type_hint(self) -> None: ii = IsInvisible() annotation = ii.resolve.__annotations__["return"]