diff --git a/CHANGELOG.md b/CHANGELOG.md index c450939e..43d104f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -210,8 +210,6 @@ 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: is text + exact_text naming still relevant for match.* case over have.*? - ### Deprecated conditions - `be.present` in favor of `be.present_in_dom` diff --git a/selene/core/match.py b/selene/core/match.py index bd7353fd..8865193c 100644 --- a/selene/core/match.py +++ b/selene/core/match.py @@ -380,7 +380,39 @@ def __x_exact_text(expected: str | int | float, _ignore_case=False, _inverted=Fa ) -def text(expected: str | int | float, _ignore_case=False, _inverted=False): +# todo: is text + exact_text naming still relevant for match.* case over have.*? +# let's compare examples: +# > element.should(have.exact_text('full of partial!')) # ๐Ÿ‘๐Ÿป +# > element.should(have.text('partial')) # ๐Ÿ‘๐Ÿป +# > element.should(match.exact_text('full of partial!')) # ๐Ÿ‘๐Ÿป +# > element.should(match.text('part')) # ๐Ÿคจ +# > element.should(match.text_containing('part')) # ๐Ÿค” +# > element.should(match.partial_text('part')) # ๐Ÿ‘๐Ÿป +# > match.text('part')(element) # ๐Ÿคจ +# > match.text_containing('part')(element) # ?? +# > match.partial_text('part')(element) # ๐Ÿ‘๐Ÿป +# let's see other conditions +# > element.should(have.value('full of partial!')) # ๐Ÿ‘๐Ÿป +# > element.should(have.value_containing('part')) # ๐Ÿ‘๐Ÿป +# > element.should(match.value('full of partial!')) # ๐Ÿ‘๐Ÿป +# > element.should(match.value_containing('part')) # ๐Ÿ‘๐Ÿป +# > element.should(match.partial_value('part')) # ๐Ÿ‘๐Ÿป? +# > browser.should(match.url_containing('part')) # ๐Ÿ‘๐Ÿป +# > browser.should(match.partial_url('part')) # ๐Ÿ‘๐Ÿป? +# > match.url_containing('part')(browser) # ๐Ÿ‘๐Ÿป +# > match.partial_url('part')(browser) # ๐Ÿ‘๐Ÿป? +# Hm... There is something weird in "match.partial_*('part')" ... +# it's conciser but less consistent with have.*_containing +# and maybe it's subjective, but partial_ phrasing sounds +# less natural for me... from human-language perspective +# Hence, let's keep things simple and consistent. +# match.text is really a problem. Not others. +# So let's rename only it and rename only to the most consistent +# with other versions... i.e. to text_containing +# Let's not do anything else. For example, +# we could rename match.exact_text to match.text, but again, +# let's keep consistency with have.* as much as possible +def text_containing(expected: str | int | float, _ignore_case=False, _inverted=False): return _EntityHasSomethingSupportingIgnoreCase( 'has text', # TODO: is it here name or description? probably it's even a "name prefix" expected, @@ -391,17 +423,6 @@ def text(expected: str | int | float, _ignore_case=False, _inverted=False): ) -# TODO: is text + exact_text naming still relevant for match.* case over have.*? -# let's compare examples: -# > element.should(have.exact_text('full of partial!')) # ๐Ÿ‘๐Ÿป -# > element.should(have.text('partial')) # ๐Ÿ‘๐Ÿป -# > element.should(match.exact_text('full of partial!')) # ๐Ÿ‘๐Ÿป -# > element.should(match.text('partial')) # ๐Ÿคจ -# > element.should(match.text_containing('partial')) # ๐Ÿค” -# > element.should(match.partial_text('partial')) # ๐Ÿ‘๐Ÿป -# > match.text('partial')(element) # ๐Ÿคจ -# > match.text_containing('partial')(element) # ?? -# > match.partial_text('partial')(element) # ๐Ÿ‘๐Ÿป def exact_text(expected: str | int | float, _ignore_case=False, _inverted=False): return _EntityHasSomethingSupportingIgnoreCase( 'has exact text', diff --git a/selene/support/conditions/have.py b/selene/support/conditions/have.py index ae293850..614a750b 100644 --- a/selene/support/conditions/have.py +++ b/selene/support/conditions/have.py @@ -37,7 +37,7 @@ def exact_text(value: str | int | float): def text(partial_value: str | int | float): - return match.text(partial_value) + return match.text_containing(partial_value) # todo: why not exact_text_matching o_O? diff --git a/selene/support/conditions/not_.py b/selene/support/conditions/not_.py index e4a1f5b2..2d7f939c 100644 --- a/selene/support/conditions/not_.py +++ b/selene/support/conditions/not_.py @@ -74,7 +74,7 @@ def exact_text(value: str | int | float): def text(partial_value: str | int | float): - return _match.text(partial_value, _inverted=True) + return _match.text_containing(partial_value, _inverted=True) def text_matching(regex_pattern: str): diff --git a/tests/integration/condition__element__have_text_matching__compared_test.py b/tests/integration/condition__element__have_text_matching__compared_test.py index 7045e566..00de0dca 100644 --- a/tests/integration/condition__element__have_text_matching__compared_test.py +++ b/tests/integration/condition__element__have_text_matching__compared_test.py @@ -130,9 +130,13 @@ def test_text_matching__regex_pattern__ignore_case__compared(session_browser): browser.all('li').first.should(match.exact_text('1) one!!!').not_) # TODO: o_O browser.all('li').first.should(have.no.exact_text('1) one!!!')) browser.all('li').first.should(match.exact_text('1) one!!!', _ignore_case=True)) + browser.all('li').first.with_(_ignore_case=True).should( + match.exact_text('1) one!!!') + ) browser.all('li').first.should(have.exact_text('1) one!!!').ignore_case) - browser.all('li').first.should(match.text('one', _ignore_case=True)) + browser.all('li').first.should(match.text_containing('one', _ignore_case=True)) browser.all('li').first.should(have.text('one').ignore_case) + browser.all('li').first.with_(_ignore_case=True).should(have.text('one')) browser.all('li').first.should(match.text_pattern(r'.*one.*', _flags=re.IGNORECASE)) browser.all('li').first.should(match.text_pattern(r'.*one.*').not_) browser.all('li').first.should(