Skip to content

Commit

Permalink
[#530] REFACTOR: match.url*
Browse files Browse the repository at this point in the history
TODOS in changelog:
* should we support ignorecase on asserting urls too?
* should we make ingorecase optionally default for all conditions supporting it?
  • Loading branch information
yashaka committed Jul 11, 2024
1 parent 17ed83d commit da10bdb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ should we even refactor out them from Condition and move to Match only?

### TODO: rename all conditions inside match.py so match can be fully used instead be + have #530

### TODO: should we support ignorecase on asserting urls too?

### TODO: should we make ingorecase optionally default for all conditions supporting it?

### Deprecated conditions

- `be.present` in favor of `be.present_in_dom`
Expand Down
27 changes: 8 additions & 19 deletions selene/core/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,9 @@ def __init__(
_name=lambda entity: (
'have size' if isinstance(entity, Collection) else 'has size'
),
# TODO: should we also tune actual rendering based on
# todo: should we also tune actual rendering based on
# config._match_only_visible_elements_size?
# ... maybe utilizing _describe_actual_result?
_by=predicate.equals,
_inverted=False,
):
Expand Down Expand Up @@ -1252,7 +1253,7 @@ def ignore_case(self) -> Condition[Collection]:
return self.where_flags(re.IGNORECASE)


# TODO: add an alias from texts(*expected).with_regex to text_patterns_like
# todo: add an alias from texts(*expected).with_regex to text_patterns_like
# hm, but then it would be natural
# if we disable implicit ^ and $ for each item text
# and so we make it inconsistent with the behavior of *_like versions
Expand Down Expand Up @@ -1425,25 +1426,13 @@ def process_wildcards(item: str) -> str:
# )


# TODO: consider refactoring the code like below by moving outside fns like url, title, etc...
# TODO: probably we will do that nevertheless when reusing "commands&queries" inside element class definitions
def browser_has_url(
expected: str,
describing_matched_to='has url',
compared_by_predicate_to=predicate.equals,
) -> Condition[Browser]:
def url(browser: Browser) -> str:
return browser.driver.current_url

return BrowserCondition.raise_if_not_actual(
f"{describing_matched_to} '{expected}'",
url,
compared_by_predicate_to(expected),
)
# TODO: should we make it supporting ignorecase?
def url(expected: str, _name='has url', _by=predicate.equals) -> Condition[Browser]:
return Match(f"{_name} '{expected}'", query.url, by=_by(expected))


def browser_has_url_containing(expected: str) -> Condition[Browser]:
return browser_has_url(expected, 'has url containing', predicate.includes)
def url_containing(expected: str) -> Condition[Browser]:
return url(expected, 'has url containing', predicate.includes)


def browser_has_title(
Expand Down
8 changes: 4 additions & 4 deletions selene/support/conditions/have.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ def _texts_like(*contained_texts_or_item_placeholders: str | int | float | Itera
return match._texts_like(*contained_texts_or_item_placeholders)


def url(exact_value: str) -> Condition[Browser]:
return match.browser_has_url(exact_value)
def url(exact_value: str):
return match.url(exact_value)


def url_containing(partial_value: str) -> Condition[Browser]:
return match.browser_has_url_containing(partial_value)
def url_containing(partial_value: str):
return match.url_containing(partial_value)


def title(exact_value: str) -> Condition[Browser]:
Expand Down
4 changes: 2 additions & 2 deletions selene/support/conditions/not_.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ def _texts_like(*contained_texts_or_item_placeholders: str | int | float | Itera


def url(exact_value: str) -> Condition[Browser]:
return _match.browser_has_url(exact_value).not_
return _match.url(exact_value).not_


def url_containing(partial_value: str) -> Condition[Browser]:
return _match.browser_has_url_containing(partial_value).not_
return _match.url_containing(partial_value).not_


def title(exact_value: str) -> Condition[Browser]:
Expand Down
1 change: 0 additions & 1 deletion tests/integration/condition__browser__have_url_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pytest

from selene import have
from selene.core.exceptions import TimeoutException
from tests.integration.helpers.givenpage import GivenPage


Expand Down

0 comments on commit da10bdb

Please sign in to comment.