I have a little issue with selenium webdriver (using python 3.x). Question is - application which I am testing is 'too fast', I was trying to use explicit/implicit waits, but non of these are working. As we know it's not the great solution of using sleep() method, so maybe you will help me. Here is few lines of code. We are writing code with bdd (gherkin/behave).
from behave import when, then
from selenium.webdriver.common.keys import Keys
from some_module.ui.bdd_tests import helpers
from some_module.ui.bdd_tests.pages.method_x import method_x_method
from some_module.ui.bdd_tests.pages.also_module import another_page
from some_module.ui.bdd_tests.pages.profile_builder import ProfileBuilderPage
@when('user collapses method_x_step')
def step_impl(context):
method_x = method_x_method(context.browser)
method_x.find_clickable_element(method_x.COLLAPSE_EXPAND_method_x).click()
@then('method_x_step is collapsed')
def step_impl(context):
method_x = method_x_method(context.browser)
assert method_x.find_text_in_element(method_x.COLLAPSE_EXPAND_method_x, 'Expand All')
@then('method_x_step is expanded')
def step_impl(context):
method_x = method_x_method(context.browser)
assert method_x.find_text_in_element(method_x.COLLAPSE_EXPAND_method_x, 'Collapse All')
@when('user collapses attacks')
def step_impl(context):
method_x = method_x_method(context.browser)
method_another_page = another_page(context.browser)
attacks_header = method_x.find_clickable_element(method_another_page.ATTACKS_method_x_HEADER_CONTAINER)
attacks_header.find_element(method_another_page.ICON_CARET_UP.method,
method_another_page.ICON_CARET_UP.location).click()
@then('attacks are collapsed')
def step_impl(context):
method_x = method_x_method(context.browser)
method_another_page = another_page(context.browser)
attacks_header = method_x.find_clickable_element(method_another_page.ATTACKS_method_x_HEADER_CONTAINER)
assert method_x.find_clickable_element(method_another_page.ICON_CARET_DOWN)
assert attacks_header.find_element(method_another_page.ICON_CARET_DOWN.method,
method_another_page.ICON_CARET_DOWN.location).is_displayed()
@when('user expands attacks')
def step_impl(context):
method_x = method_x_method(context.browser)
method_another_page = another_page(context.browser)
attacks_header = method_x.find_clickable_element(method_another_page.ATTACKS_method_x_HEADER_CONTAINER)
attacks_header.find_element(method_another_page.ICON_CARET_DOWN.method,
method_another_page.ICON_CARET_DOWN.location).click()
@then('attacks are expanded')
def step_imp(context):
method_x = method_x_method(context.browser)
method_another_page = another_page(context.browser)
attacks_header = method_x.find_clickable_element(method_another_page.ATTACKS_method_x_HEADER_CONTAINER)
assert method_x.find_clickable_element(method_another_page.ICON_CARET_UP)
assert attacks_header.find_element(method_another_page.ICON_CARET_UP.method,
method_another_page.ICON_CARET_UP.location).is_displayed()
@then('burger menu options are visible')
def step_impl(context):
method_x = method_x_method(context.browser)
assert method_x.find_text_in_element(method_x.EDIT_BUTTON, 'Edit')
assert method_x.find_text_in_element(method_x.RENAME_BUTTON, 'Rename')
assert method_x.find_text_in_element(method_x.DUPLICATE_BUTTON, 'Duplicate')
assert method_x.find_text_in_element(method_x.DELETE_BUTTON, 'Delete')
@when('user clicks out of the panel to hide the menu')
def step_impl(context):
method_x = method_x_method(context.browser)
method_x.find_visible_element(method_x.CLICK_OUT_OF_method_x).click()
@then('edit name input disappears')
def step_impl(context):
method_x = method_x_method(context.browser)
method_x.find_invisible_element(method_x.NAME_EDIT_INPUT)
@then('burger menu options are not visible')
def step_impl(context):
method_x = method_x_method(context.browser)
assert method_x.find_invisible_element(method_x.DELETE_BUTTON)
assert method_x.find_invisible_element(method_x.RENAME_BUTTON)
assert method_x.find_invisible_element(method_x.DUPLICATE_BUTTON)
assert method_x.find_invisible_element(method_x.DELETE_BUTTON)
# 1 parameter steps
@when('user clicks on "{button}" option in method_x_step context menu')
def step_impl(context, button):
method_x = method_x_method(context.browser)
if button == 'Edit':
method_x.find_present_element(method_x.EDIT_BUTTON).click()
elif button == 'Rename':
method_x.find_present_element(method_x.RENAME_BUTTON).click()
elif button == 'Duplicate':
method_x.find_present_element(method_x.DUPLICATE_BUTTON).click()
method_x.find_visible_element(method_x.RENAME_PROFILE_FIELD).send_keys(Keys.ENTER)
elif button == 'Delete':
method_x.find_present_element(method_x.DELETE_BUTTON).click()
else:
raise ValueError(f"{button} is a wrong option")
@when('user clicks "{modal_button}" modal button')
def step_impl(context, modal_button):
pb = ProfileBuilderPage(context.browser)
if modal_button == 'Update':
pb.find_clickable_element(pb.UPDATE_BUTTON).click()
elif modal_button == 'Delete Profile':
pb.find_present_element(pb.DELETE_BUTTON_MODAL).click()
else:
raise ValueError(f"{modal_button} is a wrong option")
@when('user renames method_x_step profile with "{method_x_profile}"')
def step_impl(context, method_x_profile):
method_x = method_x_method(context.browser)
method_x.find_present_element(method_x.RENAME_PROFILE_FIELD).clear()
method_x.find_visible_element(method_x.RENAME_PROFILE_FIELD).send_keys(method_x_profile)
method_x.find_visible_element(method_x.RENAME_PROFILE_FIELD).send_keys(Keys.ENTER)
@then('there is "{method_x_profile}" profile on method_x_step')
def step_impl(context, method_x_profile):
method_x = method_x_method(context.browser)
method_x.find_element_by_child_element(
method_x.method_x_ENTITY.parent, method_x.method_x_ENTITY.child, method_x_profile)
@then('method_x_step profile "{method_x_profile}" has been duplicated and got suffix: "{suffix}"')
def step_impl(context, method_x_profile, suffix):
method_x = method_x_method(context.browser)
method_x.find_element_by_child_element(
method_x.method_x_ENTITY.parent, method_x.method_x_ENTITY.child, method_x_profile + suffix)
@when('user clicks burger icon on "{method_x_profile}" left profile attacks')
def step_impl(context, method_x_profile):
method_x = method_x_method(context.browser)
method_x_profile = helpers.adjust_resource_name(context.preconfigured_resources, "attacks", method_x_profile)
burger_icon = method_x.find_element_by_child_element(
method_x.method_x_ENTITY.parent, method_x.method_x_ENTITY.child, method_x_profile)
hamburger = burger_icon.parent.find_element(
method_x.BURGER_MENU_method_x.method, method_x.BURGER_MENU_method_x.location)
hamburger.click()
Expected results are to just slow down the application with selenium's waits.