def click(self, locator, wait_state=WaitState.PRESENT): try: self.get_webelement(locator, wait_state).click() logger.info('Clicked element {}'.format(locator)) except ElementNotInteractableException as e: logger.error("Unable to click element {}. {}".format(locator, e)) raise ElementNotInteractableException( "Unable to click element {}. {}".format(locator, e)) except Exception as e: logger.error("Unable to click element {}. {}".format(locator, e)) raise Exception(e)
def switch_window_by_handles(self, handles): try: self.driver.switch_to.window(handles) logger.info('Switched to window') except NoSuchWindowException as e: logger.error("Unable to switch to window as {}".format(e)) raise NoSuchWindowException( "Unable to switch to window as {}".format(e)) except Exception as e: logger.error("Unable to switch to window as {}".format(e)) raise Exception(e)
def switch_to_child_window(self): try: parent_window = self.driver.current_window_handle handles = self.driver.window_handles self.driver.switch_to.window(handles[len(handles) - 1]) logger.info('Switched to child window') return parent_window except NoSuchWindowException as e: logger.error("Unable to switch to window as {}".format(e)) raise NoSuchWindowException( "Unable to switch to window as {}".format(e)) except Exception as e: logger.error("Unable to switch to window as {}".format(e)) raise Exception(e)
def set_text(self, locator, text, wait_state=WaitState.PRESENT): try: self.get_webelement(locator, wait_state).send_keys(text) logger.info('Entered {} in element {}'.format(text, locator)) except ElementNotInteractableException as e: logger.error("Unable to set text {} to the element {}. {}".format( text, locator, e)) raise ElementNotInteractableException( "Unable to set text {} to the element {}. {}".format( text, locator, e)) except Exception as e: logger.error("Unable to set text {} to the element {}. {}".format( text, locator, e)) raise Exception(e)
def switch_window_by_title(self, window_title): try: handles = self.driver.window_handles for i in handles: self.driver.switch_to.window(i) if self.get_window_title() == window_title: logger.info('Switched to {} window'.format(window_title)) return True except NoSuchWindowException as e: logger.error("Unable to switch to window as {}".format(e)) raise NoSuchWindowException( "Unable to switch to window as {}".format(e)) except Exception as e: logger.error("Unable to switch to window as {}".format(e)) raise Exception(e)
def run_tests(f, sheet_name, driver): try: print(get_project_path() + os.sep + 'data' + os.sep + f + '.xlsx') wb = xlrd.open_workbook(get_project_path() + os.sep + 'data' + os.sep + f + '.xlsx') sheet = wb.sheet_by_name(sheet_name) for r in range(1, sheet.nrows): get_test_data.set_row_data(sheet._cell_values[r]) eval(f + '(driver).' + sheet.cell_value(r, 1) + '()') logger.info('Passed step {}'.format(f)) except ValueError as e: logger.error('Failed {} due to {}'.format(f, e)) raise ValueError("Unable to load {} as {}".format(f, e)) except Exception as e: logger.error('Failed {} due to {}'.format(f, e)) raise Exception(e)
def main(): args = parse_argument() print(args.testsuite) test_list = excel_utils.read_test_suit(args.testsuite) for i in test_list.keys(): launch_app() print(i) try: excel_utils.run_tests(i, test_list.get(i), driver) logger.info('==============') logger.info('Test completed') logger.info('==============') except Exception as e: logger.error('==============') logger.error('Test Failed') logger.error('==============') raise Exception("Execution Failed due to {}".format(e)) finally: driver.quit()