def select_check_box_format(cls, element_identifier_name,state,value_to_format): is_selected = False try: __obj_wait_extension = WaitExtensions() by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val2 = by[1] if value_to_format != None : # check if there is an option to format by[1] = __val2.format(value_to_format) if (__obj_wait_extension.Wait_for_element_visible(by, 10)): ele = Env_setup.get_driver().find_element(eval(by[0]), by[1]) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(ele).perform() if (state.upper() == "ON"): if ele.is_selected() : cls.log.info("Check box selection is successful '{}'".format(element_identifier_name)) is_selected = True else: ele.click() # if check box is not selected, then select is_selected = True else: # to un select check box ele.click() cls.log.info("Check box is unselected {}".format(element_identifier_name)) except webdriver_exceptions.NoSuchElementException as e: cls.log.exception("Exception thrown in 'select_check_box_format' method '{}' ".format(e)) raise e except Exception as a: cls.log.exception("Exception thrown in 'select_check_box_format' method '{}' ".format(a)) raise a cls.log.exception("Value of 'is_selected' is '{}' ".format(is_selected)) return is_selected
def is_alert_present(self, time_to_wait): try: wait_ext = WaitExtensions() if wait_ext.Wait_for_alert_present(time_to_wait): EnvironmentSetup.get_driver().switch_to_alert() self.log.info( "Switch to Alert is executed, so returning 'True' value") return True except exception.NoAlertPresentException: self.log.warning( "Given alert is not present, so returning 'False' value") return False
def click_on_element_using_javascript(cls, element_identifier_name): try: # print ("field is present in the application") element = cls.get_web_element(element_identifier_name) Env_setup.get_driver().execute_script("$(arguments[0]).click();", element) cls.log.info("Click on element '{}' is successful ".format(element_identifier_name)) except webdriver_exceptions.NoSuchElementException as a: cls.log.exception("Exception thrown in 'click_on_element' method '{}' ".format(a)) raise a except Exception as e: cls.log.exception("Exception thrown in 'click_on_element' method '{}' ".format(e)) raise e
def get_column_value(self,element_identifier_name,index_value): try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __val1 = by[1].format(index_value) #print (__val1) #element = Env_setup.get_driver().find_element(eval(by[0]), str(__val1)) element = Env_setup.get_driver().find_element_by_xpath(__val1) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(element).perform() return element.text except webdriver_exceptions.NoSuchElementException as e: #traceback.print_exc() raise e
def get_row_count_in_table(self,element_identifier_name): __element_list = [] try: by = Page_elements().get_element_identifier(element_identifier_name) by = eval(by) __element_list = Env_setup.get_driver().find_elements_by_xpath(by[1]) return __element_list.__len__() except webdriver_exceptions.NoSuchElementException as e: raise e
def apptio_setup(): try: print("################## Module Set Up ###################") __local_env_setup = EnvironmentSetup() __local_env_setup.setup() # create driver for working obj_page_elements = PageElements( ) # get page elements required to execute test cases in this module into dictionary # Load page elements based on the module you want to execute obj_page_elements.load_page_elements("Apptio_Pageelements") obj_load_data = LoadTestData( ) # load the test data required to execute test cases in this module into dictionary obj_load_data.load_data("Test_Data", "Apptio_Testdata") EnvironmentSetup.go_to_url() #time.sleep(3) except: traceback.print_exc() yield apptio_setup print("################## Module Tear Down ###################") dict_cleanup() EnvironmentSetup.quit_driver() global obj_load_data obj_load_data = None
def dismiss_alert(self): Alert(EnvironmentSetup.get_driver()).dismiss()
def accept_alert(self): Alert(EnvironmentSetup.get_driver()).accept()
def get_text_in_alert(self): var_text = Alert(EnvironmentSetup.get_driver()).text self.log.info("Text from the Alert is '{}'".format(var_text)) return var_text
def switch_to_give_window_handle(cls,window_handle): Env_setup.get_driver().switch_to.window(window_handle)
def get_current_window_handle(cls,handle_number): return Env_setup.get_driver().window_handles[handle_number]
def refresh_page(self): Env_setup.get_driver().refresh()
def close_browser(cls): Env_setup.get_driver().close()
def scroll_to_element(cls,element_identifier_name): element = cls.get_web_element(element_identifier_name) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(element).perform() cls.log.info("Scroll to element '{}'".format(element_identifier_name))
def click_on_menu(cls,element_identifier_name): element = cls.get_web_element(element_identifier_name) action_chains.ActionChains(Env_setup.get_driver()).move_to_element(element).perform() cls.log.info("Click on menu item '{}'".format(element_identifier_name))