Skip to content

Commit

Permalink
cleanup code (#59)
Browse files Browse the repository at this point in the history
### To be filled by the PR creator:

* A brief description of the changes made - 

* Do we have clean latest run report (Docker or Browserstack) attached
with this PR?
  * [ ] Yes
  * [ ] No (Please explain why)

* Does the PR contain changes to any core file?
  * [ ] Yes (Needs approval from at least 1 people)
  * [ ] No

* Is it
  * [ ] New Testcase
  * [ ] Fix


### To be filled by the PR reviewer:

* [ ] Verify the attached run report passed in GitHub Actions (Docker or
Browserstack run)

* General
    * [ ] Use the best strategy to locate the elements
    * [ ] Comments wherever the code is not readable by itself
    * [ ] Use of the right data structure for the use case
    * [ ] Reuse logic/functionality as much as possible
    * [ ] Cleanup of any test data that is generated by the tests
    * [ ] No static waits
  • Loading branch information
Tauqir Sarwar authored Mar 22, 2024
2 parents 90f8ccc + 3be5e2e commit c479367
Show file tree
Hide file tree
Showing 40 changed files with 164 additions and 764 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/api_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fi
source $HOME/.bp-venv/bin/activate
sh api_run.sh "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}"
sh local_run_api.sh "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}"
- name: Get Allure history
uses: actions/checkout@v4
Expand Down Expand Up @@ -103,7 +103,7 @@ jobs:
fi
source $HOME/.bp-venv/bin/activate
sh api_run.sh "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}"
sh local_run_api.sh "$TAGS" "${{secrets.SLACK_WEBHOOK_URL}}" "${{secrets.TEAMS_WEBHOOK_URL}}"
- name: Get Allure history
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Reference Link - https://pypi.org/project/pytest-xdist/
<p align="right">(<a href="#about-the-project">back to top</a>)</p>
Command for local run on chrome (also ./web_local_run.sh)
Command for local run on chrome (also ./local_run_web.sh)
```shell
-v -s --gherkin-terminal-reporter --driver=Chrome --html="./output/reports/" --self-contained-html --capability headless True --tags="web_tests" --reruns 1 --reruns-delay 2 -n=2
```
Expand Down
4 changes: 0 additions & 4 deletions bp_core/backend/common/step_definitions/__init__.py

This file was deleted.

12 changes: 5 additions & 7 deletions bp_core/frontend/common/step_definitions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from .api_bdd import *
from .browser_navigation_window_tabs_and_screenshots import *
from .browser_navigation import *
from .click_touch_and_keyboard_actions import *
from .date_time_and_pause import *
from .date_time import *
from .dropdowns import *
from .element_existence_visibility_and_attribute_assertion import *
from .attribute_assertion import *
from .environment_variables import *
from .excel_and_csv import *
from .html_tables import *
from .ionic_hybrid_mobile_apps_steps import *
from .mobile_device_actions import *
from .swipe_scroll_move_hover_drag_and_drop import *
from .text_assertion_editing_and_generation import *
from .swipe_drag_and_drop import *
from .text_assertion_editing import *
from .visual_comparison import *
43 changes: 0 additions & 43 deletions bp_core/frontend/common/step_definitions/api_bdd.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
"""
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
"""
import polling
import structlog

Expand All @@ -23,7 +15,6 @@


# WEB context Predefined Step
# ID 501
@given(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
Expand All @@ -47,7 +38,6 @@ def check_property_is(selenium_generics: SeleniumGenerics, locators: Locators, s


# WEB context Predefined Step
# ID 502
@given(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is not the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is not the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
Expand All @@ -71,7 +61,6 @@ def check_property_is_not(selenium_generics: SeleniumGenerics, locators: Locator


# WEB context Predefined Step
# ID 503
@given(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The css attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The css attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
Expand All @@ -94,7 +83,6 @@ def check_css_property_is(attribute, selenium_generics: SeleniumGenerics, locato


# WEB context Predefined Step
# ID 504
@given(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The css attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is not the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re(r"(With soft assertion '(?P<soft_assert>.*)' )?The css attribute '(?P<attribute>.*)' of element '(?P<locator_path>.*)' is not the value '(?P<value>.*)'(\s+)?((?:within)\s+(?:')(?P<wait_for>\w+)(?:') seconds)?$"),
Expand All @@ -117,7 +105,6 @@ def check_css_property_is_not(attribute, selenium_generics: SeleniumGenerics, lo


# WEB & MOBILE contexts Predefined Step
# ID 505 & 506 & 507
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?There is an element '(?P<locator_path>.*)' on the page"))
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is displayed"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?There is an element '(?P<locator_path>.*)' on the page"))
Expand All @@ -144,7 +131,6 @@ def element_displayed(selenium_generics: SeleniumGenerics, locators: Locators, s


# WEB & MOBILE contexts Predefined Step
# ID 508 & 509 & 510
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?There is no element '(?P<locator_path>.*)' on the page"))
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not displayed"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?There is no element '(?P<locator_path>.*)' on the page"))
Expand All @@ -171,7 +157,6 @@ def element_not_displayed(selenium_generics: SeleniumGenerics, locators: Locator


# WEB & MOBILE contexts Predefined Step
# ID 511
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' appears exactly '(?P<occurrence_count>.*)' times"),
converters=dict(occurrence_count=data_manager.text_formatted), )
def check_element_exists(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert: str, locator_path, occurrence_count: int, ):
Expand All @@ -193,7 +178,6 @@ def check_element_exists(selenium_generics: SeleniumGenerics, locators: Locators


# WEB & MOBILE contexts Predefined Step
# ID 512
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' does not appear exactly '(?P<occurrence_count>.*)' times"),
converters=dict(occurrence_count=data_manager.text_formatted), )
def check_element_not_exists(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert: str, locator_path, occurrence_count: int, ):
Expand All @@ -215,7 +199,6 @@ def check_element_not_exists(selenium_generics: SeleniumGenerics, locators: Loca


# WEB & MOBILE contexts Predefined Step
# ID 513
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' becomes visible within '(?P<wait_for>.*)' seconds"),
converters=dict(wait_for=data_manager.text_formatted), )
def wait_for_displayed(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert: str, locator_path: str, wait_for: int, ):
Expand All @@ -234,8 +217,6 @@ def wait_for_displayed(selenium_generics: SeleniumGenerics, locators: Locators,
assert selenium_generics.is_element_visible(locators.parse_and_get(locator_path, selenium_generics), int(wait_for))


# WEB & MOBILE contexts Predefined Step
# ID 514
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' becomes invisible within '(?P<wait_for>.*)' seconds"),
converters=dict(wait_for=data_manager.text_formatted), )
def wait_for_not_displayed(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert: str, locator_path: str, wait_for: int):
Expand All @@ -257,7 +238,7 @@ def wait_for_not_displayed(selenium_generics: SeleniumGenerics, locators: Locato


# WEB context Predefined Step
# ID 515

@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' is within the viewport"))
def check_within_viewport(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert:str, locator_path: str):
if soft_assert is not None and soft_assert.lower() == 'true':
Expand All @@ -268,7 +249,6 @@ def check_within_viewport(selenium_generics: SeleniumGenerics, locators: Locator


# WEB context Predefined Step
# ID 516
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?I expect that element '(?P<locator_path>.*)' is not within the viewport"))
def check_within_viewport(selenium_generics: SeleniumGenerics, locators: Locators, soft_assert: str, locator_path):
if soft_assert is not None and soft_assert.lower() == 'true':
Expand All @@ -278,8 +258,6 @@ def check_within_viewport(selenium_generics: SeleniumGenerics, locators: Locator
assert not selenium_generics._is_in_viewport(locators.parse_and_get(locator_path, selenium_generics))


# WEB & MOBILE contexts Predefined Step
# ID 517
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is enabled"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is enabled"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is enabled"))
Expand All @@ -301,7 +279,6 @@ def element_enabled(selenium_generics: SeleniumGenerics, locators: Locators, sof


# WEB & MOBILE contexts Predefined Step
# ID 518
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not enabled"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not enabled"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not enabled"))
Expand All @@ -318,7 +295,6 @@ def element_not_enabled(selenium_generics: SeleniumGenerics, locators: Locators,


# WEB context Predefined Step
# ID 519
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is selected"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is selected"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is selected"))
Expand All @@ -332,7 +308,6 @@ def element_selected(selenium_generics: SeleniumGenerics, locators: Locators, so


# WEB context Predefined Step
# ID 520
@given(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not selected"))
@when(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not selected"))
@then(parsers.re("(With soft assertion '(?P<soft_assert>.*)' )?The element '(?P<locator_path>.*)' is not selected"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
"""
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------
"""
import structlog
from pytest_bdd import parsers, given, when, then
from bp_core.frontend.common.helpers.app import context_manager
Expand All @@ -18,7 +12,6 @@


# WEB & MOBILE contexts Predefined Step
# ID 201, 208
@given(parsers.re("I click on (checkbox|button|dropdown|item|element) '(?P<locator_path>.*)'"))
@given(parsers.re("I tap on '(?P<locator_path>.*)'"))
@when(parsers.re("I click on (checkbox|button|dropdown|item|element) '(?P<locator_path>.*)'"))
Expand All @@ -32,7 +25,6 @@ def click_on_locator(selenium_generics: SeleniumGenerics, locators: Locators, lo


# WEB context Predefined Step - Chrome Only
# ID 202
@given(parsers.re(
"(I wait for maximum '(?P<wait_seconds>\\d+)' seconds, and )?I click on '(?P<locator_path>.+)'"))
@when(parsers.re(
Expand All @@ -43,23 +35,20 @@ def click_element(selenium_generics: SeleniumGenerics, locators: Locators, locat


# WEB context Predefined Step
# ID 203
@given(parsers.re("I (double click|doubleclick) on '(?P<locator_path>.*)'"))
@when(parsers.re("I (double click|doubleclick) on '(?P<locator_path>.*)'"))
def dbl_click_element(selenium_generics: SeleniumGenerics, locators: Locators, locator_path: str):
selenium_generics.double_click(locators.parse_and_get(locator_path, selenium_generics))


# WEB context Predefined Step
# ID 204
@given(parsers.re("I click on SVG element '(?P<locator_path>.*)'"))
@when(parsers.re("I click on SVG element '(?P<locator_path>.*)'"))
def click_svg_element(selenium_generics: SeleniumGenerics, locators: Locators, locator_path):
selenium_generics.click_by_action(locators.parse_and_get(locator_path, selenium_generics))


# WEB context Predefined Step
# ID 205
@given(parsers.re("I click on type:'(?P<element_type>.*)' element with text equal to '(?P<value>.*)'"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re("I click on type:'(?P<element_type>.*)' element with text equal to '(?P<value>.*)'"),
Expand All @@ -69,7 +58,6 @@ def click_on_text(selenium_generics: SeleniumGenerics, element_type, value: str)


# WEB context Predefined Step
# ID 206
@given(parsers.re("I click on type:'(?P<element_type>.*)' that contains the text:'(?P<value>.*)'"),
converters=dict(value=data_manager.text_formatted), )
@when(parsers.re("I click on type:'(?P<element_type>.*)' that contains the text:'(?P<value>.*)'"),
Expand All @@ -79,7 +67,6 @@ def click_on_partial_text(selenium_generics: SeleniumGenerics, element_type, val


# WEB contexts Predefined Step
# ID 207
@given(parsers.re(
"I click on element with visible text '(?P<visibility_option>EQUALS|CONTAINS|STARTS_WITH|ENDS_WITH)' '(?P<value>.*)'"),
converters=dict(value=data_manager.text_formatted), )
Expand All @@ -96,7 +83,6 @@ def click_on_element_by_visible_text(selenium_generics: SeleniumGenerics, locato


# MOBILE context Predefined Step
# ID 209
@given(parsers.re("I long tap on element '(?P<locator>.*)'"))
@when(parsers.re("I long tap on element '(?P<locator>.*)'"))
def long_tap(selenium_generics: SeleniumGenerics, locators: Locators, locator: str):
Expand All @@ -105,7 +91,6 @@ def long_tap(selenium_generics: SeleniumGenerics, locators: Locators, locator: s


# MOBILE contexts Predefined Step
# ID 210
@given(parsers.re(
"I tap '(?P<corner>BOTTOM_LEFT|BOTTOM_RIGHT|TOP_LEFT|TOP_RIGHT)' corner of element '(?P<locator_path>.*)'")) # noqa
@when(parsers.re(
Expand All @@ -123,7 +108,6 @@ def click_element_corner(selenium_generics: SeleniumGenerics, locators: Locators


# MOBILE context Predefined Step
# ID 211
@given(parsers.re(
"On '(?P<platform>Android|iOS)' I tap on the x='(?P<x_value>.*)' % and y='(?P<y_value>.*)' % of element '(?P<locator_path>.*)'"))
@when(parsers.re(
Expand All @@ -138,7 +122,6 @@ def tap_with_percentage(selenium_generics: SeleniumGenerics, locators, platform:


# ANDROID MOBILE context Predefined Step
# ID 212
@given("On android, I tap on back navigation")
@when("On android, I tap on back navigation")
def tap_back_nav(selenium_generics: SeleniumGenerics):
Expand All @@ -148,7 +131,6 @@ def tap_back_nav(selenium_generics: SeleniumGenerics):


# iOS MOBILE context Predefined Step
# ID 213
@given(parsers.re("On iOS, I navigate back to app after clicking on '(?P<locator>.*)'"))
@when(parsers.re("On iOS, I navigate back to app after clicking on '(?P<locator>.*)'"))
def navigate_back_to_app(selenium_generics: SeleniumGenerics, locators: Locators, locator: str):
Expand All @@ -158,7 +140,6 @@ def navigate_back_to_app(selenium_generics: SeleniumGenerics, locators: Locators


# WEB context Predefined Step
# ID 214
@given(parsers.re("I press '(?P<key>.*)'"))
@when(parsers.re("I press '(?P<key>.*)'"))
def press_key_not_focused_on_element(selenium_generics: SeleniumGenerics, key: str):
Expand All @@ -167,7 +148,6 @@ def press_key_not_focused_on_element(selenium_generics: SeleniumGenerics, key: s


# WEB context Predefined Step
# ID 215
@given(parsers.re("I focus over '(?P<locator_path>.*)' then I press '(?P<key>.*)'"))
@when(parsers.re("I focus over '(?P<locator_path>.*)' then I press '(?P<key>.*)'"))
def press_key_on_element(selenium_generics: SeleniumGenerics, locator_path: str, key: str, locators: Locators):
Expand All @@ -177,7 +157,6 @@ def press_key_on_element(selenium_generics: SeleniumGenerics, locator_path: str,


# WEB context Predefined Step
# ID 216
@when(parsers.re("I click item '(?P<inner_text>.*)' for element '(?P<locator_path>.*)'"),
converters=dict(inner_text=data_manager.text_formatted), )
def add_item_for_element(selenium_generics: SeleniumGenerics, locators: Locators, inner_text: str, locator_path: str):
Expand Down
Loading

0 comments on commit c479367

Please sign in to comment.