Skip to content

Commit

Permalink
Tests & elements info fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirPodolian committed Jan 25, 2025
1 parent 54b3f6b commit 6df6557
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
15 changes: 6 additions & 9 deletions mops/mixins/internal_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@
available_kwarg_keys = ('desktop', 'mobile', 'ios', 'android')


def get_element_info(element: Any, is_for_container: bool = False) -> str:
def get_element_info(element: Any, _is_initial_call: bool = True) -> str:
"""
Get element selector information with parent object selector if it exists
:param element: element to collect log data
:param is_for_container: element to collect log data
:param _is_initial_call: element to collect log data
:return: log string
"""
label = '' if is_for_container else 'Selector: '

selector = f"{label}'{element.log_locator}'"

selector = element.log_locator
parent = element.parent

if parent:
container_data = get_element_info(parent, is_for_container=True)
selector = f"{selector} <= {container_data}"
selector = f"{get_element_info(parent, _is_initial_call=False)} >> {selector}"

return selector
return f"Selector='{selector}'" if _is_initial_call else selector

@lru_cache(maxsize=16)
def get_static(cls: Any):
Expand Down
20 changes: 10 additions & 10 deletions tests/static_tests/integration/test_element_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,46 @@ def __init__(self, parent):

def test_get_element_info_selenium(mocked_selenium_driver):
el = Element('element')
assert "Selector: 'id=element'" in get_element_info(el)
assert "Selector='id=element'" in get_element_info(el)


def test_get_element_info_with_parent_selenium(mocked_selenium_driver):
el = SomeGroup().another_group.el
assert "Selector: 'id=another_element' <= 'id=another_group' <= 'id=group'" in get_element_info(el)
assert "Selector='id=group >> id=another_group >> id=another_element'" in get_element_info(el)

def test_get_element_info_playwright(mocked_play_driver):
el = Element('element')
assert "Selector: 'id=element'" in get_element_info(el)
assert "Selector='id=element'" in get_element_info(el)


def test_get_element_info_with_parent_playwright(mocked_play_driver):
el = SomeGroup().another_group.el
assert "Selector: 'id=another_element' <= 'id=another_group' <= 'id=group'" in get_element_info(el)
assert "Selector='id=group >> id=another_group >> id=another_element'" in get_element_info(el)


def test_get_element_info_with_ios(mocked_ios_driver):
el = SomeGroup().mel
assert "Selector: 'id=ielement' <= 'id=gielement'" in get_element_info(el)
assert "Selector='id=gielement >> id=ielement'" in get_element_info(el)


def test_get_element_info_with_android(mocked_android_driver):
el = SomeGroup().mel
assert "Selector: 'id=aelement' <= 'id=gaelement" in get_element_info(el)
assert "Selector='id=gaelement >> id=aelement'" in get_element_info(el)


def test_get_element_info_with_parent_ios(mocked_ios_driver):
el = SomeGroup().another_group.el
assert "Selector: 'css=.another_i_element' <= 'id=another_group' <= 'id=gielement'" in get_element_info(el)
assert "Selector='id=gielement >> id=another_group >> css=.another_i_element" in get_element_info(el)


def test_get_element_info_with_parent_android(mocked_android_driver):
el = SomeGroup().another_group.el
assert "Selector: 'css=.another_a_element' <= 'id=another_group' <= 'id=gaelement'" in get_element_info(el)
assert "Selector='id=gaelement >> id=another_group >> css=.another_a_element" in get_element_info(el)


def test_get_element_info_with_mobile_and_desktop(mocked_android_driver, mocked_selenium_driver):
mobile_element = SomeGroup(driver_wrapper=mocked_android_driver).mel
assert "Selector: 'id=aelement' <= 'id=gaelement'" in get_element_info(mobile_element)
assert "Selector='id=gaelement >> id=aelement'" in get_element_info(mobile_element)

desktop_element = SomeGroup(driver_wrapper=mocked_selenium_driver).mel
assert "Selector: 'id=delement' <= 'id=group'" in get_element_info(desktop_element)
assert "Selector='id=group >> id=delement'" in get_element_info(desktop_element)
16 changes: 6 additions & 10 deletions tests/web_tests/test_error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mops.exceptions import *
from mops.mixins.objects.size import Size

timeout = 0.5
timeout = 0.1


@pytest.mark.medium
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_wait_element_disabled_error_msg(forms_page):
forms_page.validation_form.wait_disabled(timeout=timeout)
except TimeoutException as exc:
assert f'"Validation form" is not disabled after {timeout} seconds.' in exc.msg
assert 'Selector:' in exc.msg
assert """Selector='xpath=//*[contains(@class, "card") and .//.="Form with Validations"]""" in exc.msg
else:
raise Exception('Unexpected behaviour')

Expand All @@ -48,8 +48,7 @@ def test_wait_element_enabled_error_msg(forms_page):
forms_page.controls_form.salary_input.wait_enabled(timeout=timeout)
except TimeoutException as exc:
assert f'"salary input" is not enabled after {timeout} seconds. ' in exc.msg
assert 'Selector:' in exc.msg
assert 'Parent selector:' in exc.msg
assert """Selector='xpath=//*[contains(@class, "card") and .//.="Basic Form Controls"] >> id=salary'""" in exc.msg
else:
raise Exception('Unexpected behaviour')

Expand Down Expand Up @@ -102,8 +101,7 @@ def test_wait_element_visible_error_msg(forms_page):
forms_page.controls_form.broken_input.wait_visibility(timeout=timeout)
except TimeoutException as exc:
assert f'"invalid element" not visible after {timeout} seconds.' in exc.msg
assert 'Selector:' in exc.msg
assert 'Parent selector:' in exc.msg
assert """Selector='xpath=//*[contains(@class, "card") and .//.="Basic Form Controls"] >> id=data'""" in exc.msg
else:
raise Exception('Unexpected behaviour')

Expand All @@ -114,8 +112,7 @@ def test_wait_element_hidden_error_msg(forms_page):
forms_page.controls_form.salary_input.wait_hidden(timeout=timeout)
except TimeoutException as exc:
assert f'"salary input" still visible after {timeout} seconds.' in exc.msg
assert 'Selector:' in exc.msg
assert 'Parent selector:' in exc.msg
assert """Selector='xpath=//*[contains(@class, "card") and .//.="Basic Form Controls"] >> id=salary""" in exc.msg
else:
raise Exception('Unexpected behaviour')

Expand All @@ -126,7 +123,6 @@ def test_wait_element_available_error_msg(forms_page):
forms_page.controls_form.broken_input.wait_availability(timeout=timeout)
except TimeoutException as exc:
assert f'"invalid element" not available in DOM after {timeout} seconds.' in exc.msg
assert 'Selector:' in exc.msg
assert 'Parent selector:' in exc.msg
assert """Selector='xpath=//*[contains(@class, "card") and .//.="Basic Form Controls"] >> id=data""" in exc.msg
else:
raise Exception('Unexpected behaviour')

0 comments on commit 6df6557

Please sign in to comment.