Skip to content

Commit

Permalink
REFACTOR: device platform-processing to be more lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Oct 24, 2024
1 parent a6b1bd4 commit 047376d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2015-2022 Iakiv Kramarenko
Copyright (c) 2015 Iakiv Kramarenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
1 change: 1 addition & 0 deletions examples/run_cross_platform_android_ios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See more complete example with full configuration management and pageobjects at [python-mobile-test-template](https://github.com/automician/python-mobile-test-template)
37 changes: 15 additions & 22 deletions selene/support/_mobile/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,25 +119,21 @@ def element(
return Element(selector_or_by_or_locator, self.config)

# TODO: should not we apply translation in a more lazy way, based on config?
bys_per_platform = {
'android': self.config._selector_or_by_to_by(
selector_or_by_per_platform.get(
'android',
selector_or_by_per_platform.get('drd', selector_or_by_or_locator),
)
),
'ios': self.config._selector_or_by_to_by(
selector_or_by_per_platform.get('ios', selector_or_by_or_locator)
selector_or_by_per_platform = {
'android': selector_or_by_per_platform.get(
'android',
selector_or_by_per_platform.get('drd', selector_or_by_or_locator),
),
'ios': selector_or_by_per_platform.get('ios', selector_or_by_or_locator),
}

# todo: do we need by_to_locator_strategy?
return Element(
PlatformWiseByLocator(
lambda by: f'{self}.element({by})',
bys_per_platform=bys_per_platform,
config=self.config,
search=lambda by: self.driver.find_element(*by),
selector_or_by_platform=selector_or_by_per_platform,
config=self.config,
),
self.config,
)
Expand Down Expand Up @@ -168,24 +164,21 @@ def all(
return AllElements(selector_or_by_or_locator, self.config)

# TODO: should not we apply translation in a more lazy way, based on config?
bys_per_platform = {
'android': self.config._selector_or_by_to_by(
selector_or_by_per_platform.get(
'android',
selector_or_by_per_platform.get('drd', selector_or_by_or_locator),
)
),
'ios': self.config._selector_or_by_to_by(
selector_or_by_per_platform.get('ios', selector_or_by_or_locator)
selector_or_by_per_platform = {
'android': selector_or_by_per_platform.get(
'android',
selector_or_by_per_platform.get('drd', selector_or_by_or_locator),
),
'ios': selector_or_by_per_platform.get('ios', selector_or_by_or_locator),
}

# todo: do we need by_to_locator_strategy?
return AllElements(
PlatformWiseByLocator(
lambda by: f'{self}.all({by})',
bys_per_platform=bys_per_platform,
config=self.config,
search=lambda by: self.driver.find_elements(*by),
selector_or_by_platform=selector_or_by_per_platform,
config=self.config,
),
self.config,
)
Expand Down
14 changes: 10 additions & 4 deletions selene/support/_mobile/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,24 @@ def __init__(
description: Callable[[Tuple[str, str]], str],
*,
search: Callable,
bys_per_platform,
selector_or_by_platform,
config: Config,
):
self._config = config
self._bys_per_platform = bys_per_platform
self._bys_per_platform = selector_or_by_platform

def locate():
by = bys_per_platform.get(self._current_platform_name)
by = config._selector_or_by_to_by(
selector_or_by_platform.get(self._current_platform_name)
)
return search(by) if by is not None else cast(T, _SkippedAppiumElement())

super().__init__(
lambda: description(bys_per_platform.get(self._current_platform_name)),
lambda: description(
config._selector_or_by_to_by(
selector_or_by_platform.get(self._current_platform_name)
)
),
locate,
)

Expand Down

0 comments on commit 047376d

Please sign in to comment.