Skip to content

Commit

Permalink
[#530] REFACTOR: text and size conditions
Browse files Browse the repository at this point in the history
condition aliases and new conditions:
- collection conditions
  - `have.size(int).or_more` as alias to `have.size_greater_than_or_equal(int)`
  - `have.size(int).or_less` as alias to `have.size_less_than_or_equal(int)`
- element conditions
  - `have.size(dict_of_element_size)`
- browser conditions
  - `have.size(dict_of_browser_size)`

add
- config._match_only_visible_elements_texts
  - `True` by default
  • Loading branch information
yashaka committed Jul 9, 2024
1 parent fd0ad5e commit 8d7fa83
Show file tree
Hide file tree
Showing 20 changed files with 469 additions and 193 deletions.
25 changes: 23 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ Then we have to consider rething condition.__call__ aliases... And corresponding

### TODO: check if there are no type errors on passing be._empty to should

### Consider making configurable the "filtering collection for visibility" like in texts type of conditions
### Consider making configurable the "filtering collection for visibility" in size condition

### Consider changing name type from str | Callable[[], str] to str | Callable[[E], str],

### Ensure type errors on element.should(collection_condition), etc.

### Deprecated conditions

Expand Down Expand Up @@ -496,7 +500,7 @@ See a bit more in documented ["FAQ: How to work with iFrames in Selene?"](https:
in order to copy to clipboard before pasting
via simulating `ctrl+v` or `cmd+v` shortcut pressed.
- `command.long_press(duration=0.1)` alias to `command._long_press(duration=0.1)`
actually the _long_press is now an outdated alias and probably will be duplicated in future releases
actually the _long_press is now an outdated alias and probably will be deprecated in future releases
- `command.press_sequentially(text: str)`

### More collection queries in query.py
Expand All @@ -516,6 +520,23 @@ See a bit more in documented ["FAQ: How to work with iFrames in Selene?"](https:
- query.values
- query.tags

### More conditions & aliases

- collection conditions
- `have.size(int).or_more` as alias to `have.size_greater_than_or_equal(int)`
- `have.size(int).or_less` as alias to `have.size_less_than_or_equal(int)`
- element conditions
- `have.size(dict_of_element_size)`
- browser conditions
- `have.size(dict_of_browser_size)`

#### Additional Config options relating conditions behavior

- config._match_only_visible_elements_texts
- `True` by default
- does not change current behavior – conditions like have.texts will still filter out invisible elements by default, as it was before
- but now you can turn this behavior off by setting the option to `False`

### Document command.py and query.py on module level

Providing a brief overview of the modules and how to define your own custom commands and queries. See official docs to check new articles in Reference.
Expand Down
6 changes: 2 additions & 4 deletions selene/common/predicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ def str_equals_ignoring_case(expected):
return lambda actual: str(expected).lower() == str(actual).lower()


def equals(expected, ignore_case=False): # TODO: remove ignore_case from here
return lambda actual: (
expected == actual if not ignore_case else str_equals_ignoring_case(expected)
)
def equals(expected):
return lambda actual: (expected == actual)


def equals_with(ignore_case=False): # TODO: remove ignore_case from here
Expand Down
1 change: 1 addition & 0 deletions selene/core/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def with_(self, config: Optional[Config] = None, **config_as_kwargs) -> Browser:
def __str__(self):
return 'browser'

# todo: consider not just building driver but also adjust its size according to config
@property
def driver(self) -> WebDriver:
return self.config.driver
Expand Down
1 change: 1 addition & 0 deletions selene/core/_browser.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Browser(WaitingEntity['Browser']):
type_by_js: bool = False,
click_by_js: bool = False,
wait_for_no_overlap_found_by_js: bool = False,
_match_only_visible_elements_texts: bool = True,
# Etc.
_build_wait_strategy: Callable[[Config], Callable[[E], Wait[E]]] = ...,
) -> Browser: ...
Expand Down
Loading

0 comments on commit 8d7fa83

Please sign in to comment.