class AutomaticReplySmsPage(Page): def __init__(self, driver): Page.__init__(self, driver) self.driver.wait_for_element( UI_TEST_TIMEOUT, AVAILABLE_LANGUAGES_DROPDOWN_ID, ) self.language_drop_down = DropDown( self.driver.find(AVAILABLE_LANGUAGES_DROPDOWN_ID)) def choose_automatic_reply_language(self, language): if language == 'new': self.driver.find(NEW_LANGUAGE_CREATE_SELECTOR).click() self.driver.wait_for_page_with_title(UI_TEST_TIMEOUT, 'Languages') return CustomizedLanguagePage(self.driver) self.language_drop_down.set_selected_by_text(language) def save_changes(self): self.driver.find(PROJECT_LANGUAGE_PAGE_SAVE_BUTTON).click() self.driver.wait_for_element(UI_TEST_TIMEOUT, by_css('.success-message-box'), True) def get_success_message(self): return self.driver.find(PROJECT_LANGUAGE_PAGE_SUCCESS_MESSAGE_BOX).text def turn_off_reply_messages(self): try: on_off_switch = self.driver.find_visible_element( by_css('.onoffswitch-checked')) on_off_switch.click() except Exception: pass self.save_changes() time.sleep(2) self.driver.wait_for_page_load() def turn_on_reply_messages(self): try: self.driver.find_visible_element(by_css('.onoffswitch-checked')) except Exception: self.driver.find_visible_element(by_css('.onoffswitch')).click() self.save_changes() def is_language_selection_enabled(self): return self.driver.find(AVAILABLE_LANGUAGES_DROPDOWN_ID).is_enabled() def get_reply_messages_switch_status(self): try: self.driver.find_visible_element(by_css('.onoffswitch-checked')) return True except Exception: return False def open_sms_tester_light_box(self): self.driver.wait_for_element(UI_TEST_TIMEOUT, TEST_QUESTIONNAIRE_LINK, True) self.driver.find(TEST_QUESTIONNAIRE_LINK).click() self.driver.wait_for_element(UI_TEST_TIMEOUT, by_css('.mobile'), True) return SMSTesterLightBoxPage(self.driver)
def __init__(self, driver): Page.__init__(self, driver) self.driver.wait_for_element( UI_TEST_TIMEOUT, AVAILABLE_LANGUAGES_DROPDOWN_ID, ) self.language_drop_down = DropDown( self.driver.find(AVAILABLE_LANGUAGES_DROPDOWN_ID))
def find_drop_down(self, locator_dict): """ Create DropDown class object with the given web element Args: locator_dict is the dictionary of the locator which contains key values like {"locator":"input[name='email']","by":"By.CSS_SELECTOR"} Return DropDown """ return DropDown(self.find(locator_dict))
def __init__(self, driver): Page.__init__(self, driver) self.language_drop_down = DropDown( self.driver.find(LANGUAGE_DROP_DOWN_LOCATOR))
class CustomizedLanguagePage(Page): def __init__(self, driver): Page.__init__(self, driver) self.language_drop_down = DropDown( self.driver.find(LANGUAGE_DROP_DOWN_LOCATOR)) def get_selected_language(self): return self.language_drop_down.get_selected_option_text() def update_message_for_selector(self, msg_locator, message): custom_message_text_box = self.driver.find(msg_locator) self.update_custom_message(message, custom_message_text_box) def remove_appended_message_for_selector(self, locator, message): custom_message_text_box = self.driver.find(locator) self.driver.execute_script( "$(arguments[0]).html(_.str.rtrim($(arguments[0]).html(), arguments[1])); $(arguments[0]).trigger( 'blur' );", custom_message_text_box, message) self.save_changes() def update_custom_message(self, message, message_box): self.driver.execute_script( "$(arguments[0]).html($(arguments[0]).html() + arguments[1]);", message_box, message) # hack to update ko viewmodel self.driver.execute_script("$(arguments[0]).trigger( 'blur' );", message_box) def click_revert_changes_button(self): dont_save_button = self.driver.find_visible_element( by_css(".no_button")) dont_save_button.click() self.driver.wait_until_web_element_is_not_present( UI_TEST_TIMEOUT, dont_save_button) def click_save_changes_button(self): self.driver.find_visible_element(by_css(".yes_button")).click() self.driver.wait_until_element_is_not_present( UI_TEST_TIMEOUT, by_css(".ui-dialog-titlebar")) self.driver.wait_until_element_is_not_present(UI_TEST_TIMEOUT, by_css(".blockPage")) def clear_custom_message(self, message_box_locator): message_box = self.driver.find(message_box_locator) message_box.clear() # hack to update ko viewmodel self.driver.execute_script("$(arguments[0]).trigger( 'blur' );", message_box) def append_custom_message_for(self, msg_locator, message): message_box = self.driver.wait_for_element(UI_TEST_TIMEOUT, msg_locator, want_visible=True) self.update_custom_message(message, message_box) def save_changes(self): self.driver.find(LANGUAGE_SAVE_BUTTON_LOCATOR).click() self.driver.wait_for_element(UI_TEST_TIMEOUT, by_css(".success-message-box"), True) def get_success_message(self): success_message = self.driver.wait_for_element( UI_TEST_TIMEOUT, by_css(".success-message-box"), want_visible=True) return self.driver.execute_script("return arguments[0].innerHTML", success_message) def wait_till_success_message_box_disappears(self): self.driver.wait_until_element_is_not_present( UI_TEST_TIMEOUT, by_css(".success-message-box")) def select_language(self, language_text, wait_for_load=False): self.language_drop_down.set_selected_by_text(language_text) if wait_for_load: self.driver.wait_until_element_is_not_present( UI_TEST_TIMEOUT, by_css(".blockPage")) self.wait_for_reply_messages_to_load() def wait_for_reply_messages_to_load(self): #waiting for the last custom message to be populated WebDriverWait( self.driver, UI_TEST_TIMEOUT).until(lambda driver: driver.execute_script( "return $('#custom_message4').text().length > 0")) def get_custom_message_for(self, msg_locator): msg_box = self.driver.find(msg_locator) return self.driver.execute_script("return $(arguments[0]).html()", msg_box) def get_all_customized_reply_messages(self): return [ self.driver.execute_script( "return $(arguments[0]).TextNTags('getText')", r) for r in self.driver.find_elements_(CUSTOMIZED_MESSAGE_TEXTBOXES_LOCATOR) ] def set_message_boxes(self, default_en_messages, locator=CUSTOMIZED_MESSAGE_TEXTBOXES_LOCATOR): for (index, e) in enumerate(self.driver.find_elements_(locator)): e.clear() e.send_keys(default_en_messages[index]) def revert_customized_messages_to_default(self): return [ self.driver.execute_script( "$(arguments[0]).html(_.str.rtrim($(arguments[0]).html(),'new message')); $(arguments[0]).trigger( 'blur' );", r) for r in self.driver.find_elements_( CUSTOMIZED_MESSAGE_TEXTBOXES_LOCATOR) ] def save_new_language(self, language_name): self.driver.find_text_box(NEW_LANGUAGE_INPUT_BOX).enter_text( language_name) self.driver.find(ADD_NEW_LANG_CONFIRM_BUTTON).click() def add_new_language(self, language_name): self.select_add_new_language_option() self.driver.wait_for_element(UI_TEST_TIMEOUT, by_css('.ui-dialog')) self.save_new_language(language_name) def select_add_new_language_option(self): self.language_drop_down.set_selected_by_text( self.language_drop_down.get_options()[-1])
def __init__(self, driver): Page.__init__(self, driver) self.language_drop_down = DropDown( self.driver.find(AVAILABLE_LANGUAGES_DROPDOWN_ID))