-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from ScreenPyHQ/add-is-present
Add `IsPresent` Resolution.
- Loading branch information
Showing
10 changed files
with
425 additions
and
286 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
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
Large diffs are not rendered by default.
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,11 +1,17 @@ | ||
"""Resolutions provide answers to the Actor's Questions.""" | ||
|
||
from .is_present import IsPresent | ||
from .is_visible import IsVisible | ||
|
||
# Natural-language-enabling aliases | ||
Visible = IsVisible | ||
Exists = Exist = Present = IsPresent | ||
|
||
__all__ = [ | ||
"Exists", | ||
"Exist", | ||
"IsPresent", | ||
"IsVisible", | ||
"Present", | ||
"Visible", | ||
] |
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,5 +1,9 @@ | ||
"""Custom matchers for ScreenPy: Playwright Resolutions.""" | ||
|
||
from .is_present_element import is_present_element | ||
from .is_visible_element import is_visible_element | ||
|
||
__all__ = ["is_visible_element"] | ||
__all__ = [ | ||
"is_present_element", | ||
"is_visible_element", | ||
] |
45 changes: 45 additions & 0 deletions
45
screenpy_playwright/resolutions/custom_matchers/is_present_element.py
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,45 @@ | ||
""" | ||
A matcher that matches a present element. | ||
For example: | ||
assert_that(driver.find_element_by_id("search"), is_present_element()) | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Optional | ||
|
||
from hamcrest.core.base_matcher import BaseMatcher | ||
from playwright.sync_api import Locator | ||
|
||
if TYPE_CHECKING: | ||
from hamcrest.core.description import Description | ||
|
||
|
||
class IsPresentElement(BaseMatcher[Optional[Locator]]): | ||
"""Match a locator which finds at least 1 element.""" | ||
|
||
def _matches(self, item: Locator | None) -> bool: | ||
if item is None: | ||
return False | ||
return item.count() > 0 | ||
|
||
def describe_to(self, description: Description) -> None: | ||
"""Describe what is needed to pass this test.""" | ||
description.append_text("an element which is present") | ||
|
||
def describe_match(self, _: Locator | None, match_description: Description) -> None: | ||
"""Describe the matching case.""" | ||
match_description.append_text("it was present") | ||
|
||
def describe_mismatch( | ||
self, _: Locator | None, mismatch_description: Description | ||
) -> None: | ||
"""Describe the failing case.""" | ||
mismatch_description.append_text("was not present") | ||
|
||
|
||
def is_present_element() -> IsPresentElement: | ||
"""Match a locator which finds at least 1 element present on the page.""" | ||
return IsPresentElement() |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Matches against a present WebElement.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from screenpy import beat | ||
|
||
from .custom_matchers import is_present_element | ||
|
||
if TYPE_CHECKING: | ||
from .custom_matchers.is_present_element import IsPresentElement | ||
|
||
|
||
class IsPresent: | ||
"""Match on a present element. | ||
The element does not need to be visible, only that it exists. | ||
Examples:: | ||
the_actor.should(See.the(Element(WELCOME_BANNER), IsPresent())) | ||
""" | ||
|
||
def describe(self) -> str: | ||
"""Describe the Resolution's expectation.""" | ||
return "present" | ||
|
||
@beat("... hoping it's present.") | ||
def resolve(self) -> IsPresentElement: | ||
"""Produce the Matcher to make the assertion.""" | ||
return is_present_element() |
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