def type_email_into_username_of_registration_form(context, user_number): #import pdb; pdb.set_trace() converted_user_number = int(user_number) wc = WebCommon() email = context.users_list[converted_user_number][7] password = context.users_list[converted_user_number][8] email_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_name']['type'] email_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_name']['locator'] wc.type_into_element(context, email, email_locator_type, email_locator_string) password_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_password']['type'] password_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_password']['locator'] wc.type_into_element(context, password, password_locator_type, password_locator_string) register_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirm']['type'] register_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirm']['locator'] wc.click(context, register_locator_type, register_locator_string) registered_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirmed']['type'] registered_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirmed']['locator'] wc.assert_element_visible(context, registered_locator_type, registered_locator_string) wc.click(context, registered_locator_type, registered_locator_string)
def i_select_free_shipping_option(context): wc = WebCommon() logger.info("11111") logger.info("about to select free shipping option") free_ship = CART_PAGE_LOCATORS['free_shipping_radio'] wc.click(context, free_ship['type'], free_ship['locator']) wc.assert_radio_is_selected(context, free_ship['type'], free_ship['locator'])
def i_apply_coupon_to_the_cart(context): coupon_field_locator = CART_PAGE_LOCATORS['coupon_code_field'] apply_coupon_locator = CART_PAGE_LOCATORS['apply_coupon_button'] wc = WebCommon() wc.type_into_element(context, context.coupon_code, coupon_field_locator['type'], coupon_field_locator['locator']) wc.click(context, apply_coupon_locator['type'], apply_coupon_locator['locator'])
def click_on_button_name(context, btn_name): wc = WebCommon() if btn_name.lower() in ('login', 'log in'): login_btn_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'login_button']['type'] login_btn_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'login_button']['locator'] else: raise Exception("Not implemented") wc.click(context, login_btn_locator_type, login_btn_locator_string)
def i_click_on_cart_in_the_top_nav_bar_and_verify_cart_page_opens(context): wc = WebCommon() max_tries = 5 try_count = 0 cart_info_locator = HOME_PAGE_LOCATORS['cart_info_box'] while try_count < max_tries: try: wc.click(context, cart_info_locator['type'], cart_info_locator['locator']) wc.assert_url_contains(context, '/cart/') break except Exception as e: try_count += 1 print(f"failed to click on proceed to cart. Retry number: {try_count}") else: raise Exception(f"failed to click on proceed to cart button after 5 retries")
def users_can_log_in(context): number_of_users = len(context.users_list) wc = WebCommon() for i in range(0, number_of_users): type_email_into_username_of_login_form(context, context.users_list[i][7]) type_password_into_password_of_login_form(context, context.users_list[i][8]) click_on_button_name(context, 'login') registered_locator_type = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirmed']['type'] registered_locator_string = locatorsconfig.MY_ACCOUNT_LOCATORS[ 'register_user_confirmed']['locator'] wc.assert_element_visible(context, registered_locator_type, registered_locator_string) wc.click(context, registered_locator_type, registered_locator_string)
def i_add_random_item_to_cart_from_the_homepage(context, qty): wc = WebCommon() logger.info("11111") logger.info(f"Adding {qty} items to cart") logger.info(f"Adding {qty} items to cart") cart_btns = HOME_PAGE_LOCATORS['all_add_cart_btns'] cart_btns_type = cart_btns['type'] cart_btns_text = cart_btns['locator'] cart_btns = wc.find_elements(context, cart_btns_type, cart_btns_text) random_btns = random.sample(cart_btns, int(qty)) for i in random_btns: wc.click(i) time.sleep(1)
def and_i_click_on_proceed_to_checkout_button(context): proceed_button = CART_PAGE_LOCATORS['proceed_to_checkout_btn'] wc = WebCommon() max_tries = 3 try_count = 0 while try_count < max_tries: try: wc.click(context, proceed_button['type'], proceed_button['locator']) break except Exception as e: try_count += 1 print( f"failed to click on proceed to checkout. Retry number: {try_count}" ) else: raise Exception( f"failed to click on proceed to checkout button after 3 retries")