class NavigationPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators my_courses = "My Courses" all_courses = "All Courses" practice = "Practice" user_settings_icon = "//span[@class='navbar-current-user']" def navigate_to_all_courses(self): self.element_click(self.all_courses, locator_type="link") def navigate_to_my_courses(self): self.element_click(self.my_courses, locator_type="link") def navigate_to_practice(self): self.element_click(self.practice, locator_type="link") def navigate_to_user_icon(self): self.element_click(self.user_settings_icon, locator_type="xpath")
class Util(object): log = custom_logger(logging.INFO) def sleep(self, seconds, message=''): #puts the program to wait for the specified period of time if message is not None: self.log.info(sleep_message(seconds, message)) try: time.sleep(seconds) except InterruptedError: traceback.print_stack() def verify_text_contains(self, actual_text, expected_text): self.log.info(actual_text_message(actual_text)) self.log.info(expected_text_message(expected_text)) if expected_text.lower() in actual_text.lower(): self.log.info(verification_successful_message(self.verify_text_contains.__name__)) return True else: self.log.info(verification_failed_message(self.verify_text_contains.__name__)) return False def verify_text_match(self, actual_text, expected_text): self.log.info(actual_text_message(actual_text)) self.log.info(expected_text_message(expected_text)) if expected_text.lower() == actual_text.lower(): self.log.info(verification_successful_message(self.verify_text_contains.__name__)) return True else: self.log.info(verification_failed_message(self.verify_text_contains.__name__)) return False
class NavigationPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators _my_courses = "All Courses" _all_courses = "My Courses" _practice = "Practice" _user_settings_icon = "//div[@id='navbar']//li[@class='dropdown']" def navigate_to_all_courses(self): self.element_click(locator=self._all_courses, locator_type='link') def navigate_to_my_courses(self): self.element_click(locator=self._my_courses, locator_type="link") def navigate_to_practice(self): self.element_click(locator=self._practice, locator_type="link") def navigate_to_user_settings(self): user_settings_element = self.wait_for_element(locator=self._user_settings_icon, locator_type="xpath", poll_frequency=1) # self.elementClick(element=user_settings_element) self.element_click(locator=self._user_settings_icon, locator_type="xpath")
class Util(object): log = cl.custom_logger(logging.INFO) def sleep(self, sec, info=""): """ Put the program to wait for the specified amount of time :param sec: :param info: """ if info is not None: self.log.info("Wait :: " + str(sec) + " seconds for " + info) try: time.sleep(sec) except InterruptedError: traceback.print_stack() def get_alpha_numeric(self, length, char_type="letters"): """ Get random string of characters Provide lower/upper/digits for different types :param length: Length of string, number of characters string should have :param char_type: Type of characters string should have. Default is letters :returns: a generated character string of the requested character type(s) """ alpha_num = "" if char_type == "lower": case = string.ascii_lowercase elif char_type == "upper": case = string.ascii_uppercase
class Util(object): log = cl.custom_logger(logging.INFO) def sleep(self, sec, info=""): """ Put the program to wait for the specified amount of time """ if info is not None: self.log.info("Wait :: '" + str(sec) + "' seconds for " + info) try: time.sleep(sec) except InterruptedError: traceback.print_stack() def get_alpha_numeric(self, length, typee='letters'): """ Get random string of characters Parameters: length: Length of string, number of characters string should have typee: Type of characters string should have. Default is letters Provide lower/upper/digits for different types """ alpha_num = '' if typee == 'lower': case = string.ascii_lowercase elif typee == 'upper': case = string.ascii_uppercase
class NavigationBar(BasePage): # we override log locally to get the LoginPage name in logfile log = custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver #locators _main_logo = "//a[contains(@href, 'http://letskodeit.teachable.com')]" _my_courses = "//a[@href='/courses/enrolled']" _all_courses = "//a[@href='/courses']" _practice = "//a[@href='/pages/practice']" _user_icon = "//div[@id='navbar']//li[@class='dropdown']" #actions on the elements def navigate_to_main_logo(self): self.element_click(locator=self._main_logo, locator_type="XPATH") def navigate_to_my_courses(self): self.element_click(locator=self._my_courses, locator_type="XPATH") def navigate_to_all_courses(self): self.element_click(locator=self._all_courses, locator_type="XPATH") def navigate_to_practice(self): self.element_click(locator=self._practice, locator_type="XPATH") def navigate_to_user_icon(self): user_icon_element = self.wait_for_element\ (locator=self._user_icon, locator_type="XPATH", timeout=10, poll_frequency=1) self.element_click(locator=self._user_icon, locator_type='XPATH')
class NavigationPage(BasePage): """ Page class containing methods used by other page classes for navigation Contains methods that interact with web elements common to every page Arguments: None Attributes: log(obj): Logger instance """ log = custom_logger(logging.INFO) # locators _login_link = "a.login" _store_menu = ".submenu-container a" def click_login_link(self): self.click_element(self._login_link, "css") def click_clothes_menu_link(self, clothes_type): self.click_category_type_element(self._store_menu, clothes_type)
class Util(object): log = cl.custom_logger(logging.INFO) def sleep(self, sec, info=""): """ Put the program to wait for the specified amount of time """ if info is not None: self.log.info("Wait :: '%s' seconds for %s" % (str(sec), info)) try: time.sleep(sec) except InterruptedError: traceback.print_stack() def get_alpha_numeric(self, length, type="letters"): """ Get random string of characters :param length: Number of characters string should have :param type: Type of characters string should have. Default is letters Provide lower/upper/digits for different types :return: a random string """ alpha_num = "" if type == "lower": case = string.ascii_lowercase if type == "upper": case = string.ascii_uppercase
class NavigationPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators _my_courses = "My Courses" _all_courses = "All Courses" _practice = "Practice" _user_settings_icon = "//div[@id='navbar']//li[@class='dropdown']" _header_logo = "header-logo" def navigate_to_my_courses(self): self.element_click(locator=self._my_courses, locator_type="link") def navigate_to_all_courses(self): self.element_click(locator=self._all_courses, locator_type="link") def navigate_to_practice(self): self.element_click(locator=self._practice, locator_type="link") def navigate_to_users_settings(self): self.element_click(locator=self._user_settings_icon, locator_type="xpath") def click_header_logo(self): self.element_click(locator=self._header_logo, locator_type="class")
class LoginPage(SeleniumDriver): Log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.Driver = driver # locators email_field = "login-username" password_field = "login-password" submit_btn = "login-button" login_link = "/html/body/div[3]/div/div[2]/div[1]/header/div[4]/button[2]" def click_login_link(self): self.element_click(self.login_link, "xpath") def send_email_login(self, email): self.send_keys(email, self.email_field, "id") def send_pass_login(self, password): self.send_keys(password, self.password_field, "id") def click_login_btn(self): self.element_click(self.submit_btn, "id") def login_fn(self, email, password): self.click_login_link() time.sleep(2) self.send_email_login(email) self.send_pass_login(password) self.click_login_btn()
class NavigationPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators _logo = "//a[@class='navbar-brand header-logo']" _my_courses = "My Courses" _all_courses = "All Courses" _practice = "Practice" _user_settings_icon = "//a[contains(@class,'open-my-profile-dropdown')]" def go_to_main(self): self.click_element(self._logo, "xpath") def go_to_all_courses(self): self.click_element(self._all_courses, "link") def go_to_my_courses(self): self.click_element(self._my_courses, "link") def go_to_practice(self): self.click_element(self._practice, "link") def go_to_user_settings(self): self.click_element(self._user_settings_icon, "xpath")
class PlayPausePage(SeleniumDriver): Log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.Driver = driver # locators first_song_playlist = "/html/body/div[4]/div/div[2]/div[4]/div[1]/div/div[2]/section[1]/div[4]/section/ol/div[" \ "1]/div/li " play_top = "/html/body/div[4]/div/div[2]/div[4]/div[1]/div/div[2]/section[1]/div[3]/div/button" play_pause_lower = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[2]/div/div[1]/div[3]/button" next = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[2]/div/div[1]/div[4]/button" previous = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[2]/div/div[1]/div[2]/button" play_queue = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[3]/div/div/div[1]/div/button" queued_song = "/html/body/div[4]/div/div[2]/div[4]/div[1]/div/div[2]/section[1]/div[4]/section/ol/div[4]/div/li" options = "/html/body/div[4]/div/div[2]/div[4]/div[1]/div/div[2]/section[1]/div[4]/section/ol/div[4]/div/li/div[" \ "3]/div/div/button " add_to_queue = "/html/body/div[4]/div/nav[1]/div[3]" sound_play = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[3]/div/div/div[3]/div" sound_switch = "/html/body/div[4]/div/div[2]/div[3]/footer/div/div[3]/div/div/div[3]/button" def play_first_song(self): result = self.Driver.find_element_by_xpath(self.first_song_playlist) actions = ActionChains(self.Driver) actions.move_to_element(result).click.perform() def play_playlist(self): self.element_click(self.play_top, "xpath") time.sleep(5) def click_play_pause(self): self.element_click(self.play_pause_lower, "xpath") time.sleep(2) self.element_click(self.play_pause_lower, "xpath") time.sleep(2) def click_next(self): self.element_click(self.next, "xpath") time.sleep(5) def click_previous(self): self.element_click(self.previous, "xpath") time.sleep(5) def slider_sound(self): self.element_click(self.sound_play, "xpath") time.sleep(2) def queue_play(self): self.element_click(self.queued_song, "xpath") time.sleep(2) self.element_click(self.options, "xpath") self.element_click(self.add_to_queue, "xpath") self.element_click(self.play_queue, "xpath") def sound_btn(self): self.element_click(self.sound_switch, "xpath")
class NavigationPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators _trang_moi_nhat = ('//*[@id="cat9999"]/a', 'xpath') _all_courses = "My Courses" _practice = "Practice" _user_settings_icon = "//div[@id='navbar']//li[@class='dropdown']" _tin_noi_bat = ('//*[@id="LoadHLHome"]/div[1]/h2/a', 'xpath') _video_noi_bat = ('//*[@id="TotalBox9"]/div[1]/div[2]/div[1]/div/a/img', 'xpath') def navigate_to_trang_moi_nhat(self): self.element_click(locator=self._trang_moi_nhat[0], locator_type=self._trang_moi_nhat[1]) def navigate_to_trang_video(self): self.driver.get('http://giadinh.net.vn/video-page.htm') def navagate_to_trang_xa_hoi(self): self.driver.get('http://giadinh.net.vn/xa-hoi.htm') def navigate_to_trang_gia_dinh(self): self.driver.get('http://giadinh.net.vn/gia-dinh.htm') def navigate_to_trang_song_khoe(self): self.driver.get('http://giadinh.net.vn/song-khoe.htm') def navigate_to_trang_giai_tri(self): self.driver.get('http://giadinh.net.vn/giai-tri.htm') def navigate_to_trang_phap_luat(self): self.driver.get('http://giadinh.net.vn/phap-luat.htm') def navigate_to_trang_vong_tay_nhan_ai(self): self.driver.get('http://giadinh.net.vn/vong-tay-nhan-ai.htm') def navigate_to_trang_thi_truong(self): self.driver.get('http://giadinh.net.vn/thi-truong.htm') def navigate_to_trang_bon_phuong(self): self.driver.get('http://giadinh.net.vn/bon-phuong.htm') def navigato_to_trang_detail_tin(self): tin_noi_bat = self.get_element(self._tin_noi_bat[0], self._tin_noi_bat[1]) self.element_click(element=tin_noi_bat) # self.driver.get('http://giadinh.net.vn/gia-dinh/biet-chong-trot-say-nang-vo-ra-ke-hoach-yeu-lai-tu-dau-khien-ke-thu-ba-ngam-dang-nuot-cay-20190226225052786.htm') def navigate_to_trang_video_detail(self): video_noi_bat = self.get_element(self._video_noi_bat[0], self._video_noi_bat[1]) self.element_click(element=video_noi_bat)
class ProcurementOptionsWindow(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # LOCATORS _additional_proc_options_arrow = "VNDR_LOC_WRK1_PROC_OPT_PB" _payment_terms_id_field = "VENDOR_LOC_PYMNT_TERMS_CD" _ok_btn = "#ICSave" """ DO SOMETHING WITH ELEMENT """ def expand_additional_procurement_options(self): self.element_click(self._additional_proc_options_arrow) def enter_payment_terms_id(self, pmnt_terms): self.sendkeys((pmnt_terms, Keys.TAB), self._payment_terms_id_field) def click_ok_button(self): self.element_click(self._ok_btn) """ THIS IS THE MODULE THAT IS CALLED BY THE TEST """ def select_payment_terms_id(self, pmnt_terms): self.expand_additional_procurement_options() self.enter_payment_terms_id(pmnt_terms) self.click_ok_button() time.sleep(2) try: self.driver.switch_to.frame("ptifrmtgtframe") except Exception as e: print(e) time.sleep(2) def select_random_payment_terms_id(self): number_of_accounts = 1 random_account = random.choices(population=PROCUREMENT_OPTIONS, k=number_of_accounts) self.expand_additional_procurement_options() self.sendkeys(random_account, self._payment_terms_id_field) self.sendkeys(Keys.TAB, self._payment_terms_id_field) time.sleep(1) self.click_ok_button() time.sleep(1) try: self.driver.switch_to.frame("ptifrmtgtframe") except Exception as e: print(e) time.sleep(2)
class TestStatus(SeleniumDriver): log = cl.custom_logger(logging.INFO) def __init__(self, driver): """ Inits CheckPoint class """ super(TestStatus, self).__init__(driver) self.resultList = [] def set_result(self, result, result_message): try: if result is not None: if result: self.resultList.append("PASS") self.log.info("### VERIFICATION SUCCESSFUL :: + " + result_message) else: # send_message(result_message) self.resultList.append("FAIL") self.log.error("### VERIFICATION FAILED :: + " + result_message) # self.screen_shot(result_message) else: self.resultList.append("FAIL") self.log.error("### VERIFICATION FAILED :: + " + result_message) # self.screen_shot(result_message) except: self.resultList.append("FAIL") self.log.error("### Exception Occurred !!!") # self.screen_shot(result_message) def mark(self, result, result_message): """ Mark the result of the verification point in a test case """ self.set_result(result, result_message) def mark_final(self, test_name, result, result_message): """ Mark the final result of the verification point in a test case This needs to be called at least once in a test case This should be final test status of the test case """ self.set_result(result, result_message) if "FAIL" in self.resultList: self.log.error(test_name + " ### TEST FAILED") self.resultList.clear() assert True == False else: self.log.info(test_name + " ### TEST SUCCESSFUL") self.resultList.clear() assert True == True
class FindExistingValuePage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.util = Util() self.wait = SeleniumDriver(self.driver) """ Unless otherwise noted, locator_type is 'ID' """ # LOCATORS _new_window_link = "New Window" # LINK_TEXT _help_link = "Help" # LINK_TEXT _keyword_search_tab = "ICTAB_1" _add_new_value_tab = "ICTAB_2" _supplier_id_txt = "VENDOR_AP_VW_VENDOR_ID" _persistence_select = "VENDOR_AP_VW_VENDOR_PERSISTENCE" _short_supplier_name_txt = "VENDOR_AP_VW_VENDOR_NAME_SHORT" _our_customer_number_txt = "VENDOR_AP_VW_AR_NUM" _supplier_name = "VENDOR_AP_VW_NAME1" _search_btn = "#ICSearch" _return_to_search_btn = "#ICList" _clear_btn = "#ICClear" _basic_search_link = "Basic Search" # LINK_TEXT _save_search_criteria_link = "Save Search Criteria" # LINK_TEXT _find_existing_value_link = "Find an Existing Value" # LINK_TEXT _keyword_search_link = "Keyword Search" # LINK_TEXT _add_new_value_link = "Add a New Value" # LINK_TEXT def click_add_new_value_tab(self): self.element_click(self._add_new_value_tab) def enter_supplier_id(self, supplier_id): self.sendkeys(supplier_id, self._supplier_id_txt) def click_search_btn(self): self.element_click(self._search_btn) wait = WebDriverWait(self.driver, 30, poll_frequency=1) wait.until( ec.visibility_of_element_located( (By.XPATH, "//span[contains(text(), 'Last Modified By')]"))) """ MODULES CALLED BY TEST SCRIPTS """ def add_a_new_value(self): self.driver.switch_to.frame("ptifrmtgtframe") wait = WebDriverWait(self.driver, 10, poll_frequency=1) wait.until( ec.visibility_of_element_located((By.ID, self._add_new_value_tab))) self.click_add_new_value_tab() def search_for_supplier(self, master_vendor_id): self.enter_supplier_id(master_vendor_id) print("Supplier ID: {}".format(master_vendor_id)) self.click_search_btn()
class LoginPage(BasePage): logger = custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # locator _login_link = 'Login' _email_field = 'user_email' _password_field = 'user_password' _login_button = 'commit' # def get_login_link(self): # return self.driver.find_element(By.LINK_TEXT, self._login_link) # # def get_email_field(self): # return self.driver.find_element(By.ID, self._email_field) # # def get_password_field(self): # return self.driver.find_element(By.ID, self._password_field) # # def get_login_button(self): # return self.driver.find_element(By.NAME, self._login_link) def click_login_link(self): self.element_click(self._login_link, locator_type='link') def enter_email(self, email): self.send_keys(email, self._email_field) def enter_password(self, password): self.send_keys(password, self._password_field) def click_login_button(self): self.element_click(self._login_button, locator_type='name') def login(self, email='', password=''): self.click_login_link() self.enter_email(email) self.enter_password(password) self.click_login_button() def verify_login_successful(self): result = self.is_element_present('//*[@id="navbar"]/div/div/div/ul/li[4]/a/span', locator_type='xpath') return result def verify_login_fail(self): return self.is_element_present('/html/body/div/div/div/div/div/div/div[1]/div/div', locator_type='xpath') def verify_login_title(self): return self.verify_page_title('Google')
class LoginPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.nav = NavigationPage(driver) # Locators _login_link = "Login" _email_field = "user_email" _password_field = "user_password" _login_button = "commit" _logout_button = "Log Out" def click_login_link(self): self.click_element(self._login_link, "link") def enter_email(self, email): self.send_keys(email, self._email_field) def enter_password(self, password): self.send_keys(password, self._password_field) def click_login_button(self): self.click_element(self._login_button, "name") def login(self, email="", password="", click_login=True): if click_login: self.click_login_link() self.clear_fields() self.enter_email(email) self.enter_password(password) self.click_login_button() def verify_login_successful(self): result = self.is_element_present( "//*[@id='navbar']//img[@class='gravatar']", "xpath") return result def verify_login_failed(self): result = self.is_element_present( "//div[contains(text(),'Invalid email or password')]", "xpath") return result def clear_fields(self): self.get_element(self._email_field).clear() self.get_element(self._password_field).clear() def verify_login_title(self): return self.verify_page_title("Let's Kode It") def logout(self): self.nav.go_to_user_settings() self.click_element(self._logout_button, "link")
class testStatus(SeleniumDriver): log = custom_logger(logging.INFO) def __init__(self, driver): super(testStatus, self).__init__(driver) self.result_list = [] def set_result(self, test_name, result): try: if result is not None: if result: self.result_list.append('PASS') self.log.info(verification_successful_message(test_name)) else: self.result_list.append('FAIL') self.log.error(verification_failed_message(test_name)) self.screenshot(test_name) else: self.result_list.append('FAIL') self.log.error(verification_failed_message(test_name)) self.screenshot(test_name) except: self.result_list.append('FAIL') self.log.error(exception_occurred_message(test_name)) self.screenshot(test_name) print_stack() #call on every assertion in the test_case except final assertion def mark(self, test_name, result): self.set_result(test_name, result) # call on final assertion in the test_case def mark_final(self, test_funk_name, test_name, result): self.set_result(test_name, result) print("Result_list:", self.result_list) if "FAIL" in self.result_list: self.log.error(test_failed_message(test_funk_name)) self.result_list.clear() assert False elif 'PASS' in self.result_list: self.log.info(test_successful_message(test_funk_name)) self.result_list.clear() assert True else: self.log.error(test_cannot_collect_message(test_funk_name)) self.result_list.clear() assert False
class ForgottenPasswordPage(BasePage): """ Page class representing the forgotten password page Contains methods that interact with web elements located on the forgotten password page Arguments: None Attributes: log: Logger instance """ log = custom_logger(logging.INFO) # locators _email_input = "email" _retrieve_password_button = "button.btn.btn-default.button.button-medium" _retrieve_password_success_message = "p.alert.alert-success" _retrieve_password_error_message = "div.alert.alert-danger" _back_to_login_button = "[title='Back to Login']" def verify_forgotten_password_page_title(self): return self.verify_page_title("Forgot your password - My Store") def enter_retrieve_password_email_input(self, username): self.sending_keys(username, self._email_input) def click_retrieve_password_button(self): self.click_element(self._retrieve_password_button, "css") def retrieve_password(self, username): self.enter_retrieve_password_email_input(username) self.click_retrieve_password_button() def click_back_to_login_button(self): self.click_element(self._back_to_login_button, "css") def verify_valid_password_retrieval(self, *args): return self.is_text_present( self._retrieve_password_success_message, "css", "A confirmation email has been sent " "to your address: [email protected]") def verify_invalid_password_retrieval(self, *args): return self.is_text_present(self._retrieve_password_error_message, "css", *args, selector="li")
class TestStatus(SeleniumDriver): log = cl.custom_logger(logging.INFO) def __init__(self, driver): """ Inits CheckPoint class """ super(TestStatus, self).__init__(driver) self.result_list = [] def set_result(self, result, result_message): try: if result is not None: if result: self.result_list.append("PASS") self.log.info("Verification Successful :: ", result_message) else: self.result_list.append("FAILED") self.log.info("Verification Failed :: ", result_message) else: self.result_list.append("FAILED") self.log.error("Verification Failed :: ", result_message) except: self.result_list.append("FAILED") self.log.error("Exception Occurred !!!") def mark(self, result, result_message): """ Mark the result of the verification point in a test case """ self.set_result(result, result_message) def mark_final(self, test_name, result, result_message): """ Mark the final result of the verification point in a test case Needs to be called at least once in a test case Should be final test status of the test case """ self.set_result(result, result_message) if "FAIL" in self.result_list: self.log.error(test_name, " Test FAILED!!!") self.result_list.clear() assert True == False else: self.log.info(test_name, " Test SUCCESSFUL") self.result_list.clear() assert True == True
class ResultStatus(SeleniumWrapper): log = cl.custom_logger(logging.INFO) def __init__(self, driver): super(ResultStatus, self).__init__(driver) self.result_list = [] def set_result(self, result, result_message): try: if result is not None: if result: self.result_list.append("PASS") self.log.info("### Verification Successful :: " + result_message) else: self.result_list.append("FAIL") self.log.error("### Verification Failed :: " + result_message) self.screenshot(result_message) else: self.result_list.append("FAIL") self.log.error("### Verification Failed :: " + result_message) self.screenshot(result_message) except ValueError: self.result_list.append("FAILED") self.log.error("### Exception Occurred") self.screenshot(result_message) def mark(self, result, result_message): """ Mark the result of the verification point in a test case """ self.set_result(result, result_message) def mark_final(self, test_name, result, result_message): """ Mark the final result of the verification point in a test case This needs to be called at least once in a test case This is final test status of the test case """ self.set_result(result, result_message) if "FAIL" in self.result_list: self.log.error(test_name + " ### TEST FAILED") self.result_list.clear() assert False else: self.log.info(test_name + " ### TEST SUCCESSFUL") self.result_list.clear() assert True
class Status(SeleniumDriver): log = cl.custom_logger(logging.INFO) def __init__(self, driver): super(Status, self).__init__(driver) self.result_list = [] def set_result(self, result, message): try: if result is not None: if result: self.result_list.append("PASS") self.log.info("### VERIFICATION PASSED :: + " + message) else: self.result_list.append("FAIL") self.log.error("### VERIFICATION FAILED :: + " + message) self.take_screenshot(message) else: self.result_list.append("FAIL") self.log.error("### VERIFICATION FAILED :: + " + message) self.take_screenshot(message) except: self.result_list.append("FAIL") self.log.error("### EXCEPTION !!!") self.take_screenshot(message) def mark(self, result, message): """ Mark the result of the verification point in a test case """ self.set_result(result, message) def mark_final(self, test_name, result, message): """ Mark the final result of the verification point in a test case This needs to be called at least once in a test case This should be final test status of test case """ self.set_result(result, message) if "FAIL" in self.result_list: self.log.error(test_name + "### TEST FAILURE ### ") self.result_list.clear() assert False else: self.log.info(test_name + "### TEST PASSED") self.result_list.clear() assert True
class CheckPoint(SeleniumDriver): log = cl.custom_logger(logging.INFO) def __init__(self, driver): """ Inits TestStatus class """ super().__init__(driver) self.result_list = [] def set_result(self, result, result_message): try: if result is not None: if result: self.result_list.append("PASS") self.log.info("# VERIFICATION SUCCESSFUL: " + result_message) else: self.result_list.append("FAIL") self.log.error("# VERIFICATION FAILED : " + result_message) self.take_screenshot(result_message) else: self.result_list.append("FAIL") self.log.error("# VERIFICATION FAILED : " + result_message) self.take_screenshot(result_message) print_stack() except: self.result_list.append("FAIL") self.log.error("# EXCEPTION OCCURRED !!!") self.take_screenshot(result_message) def mark(self, result, result_message): """ Mark the result of the verification point in a test case """ self.set_result(result, result_message) def mark_final(self, test_name, result, result_message): """ Mark the final result of the verification point in a test case This needs to be called at least once in a test case This should be final test status of the test case """ self.set_result(result, result_message) if "FAIL" in self.result_list: self.log.error("### %s : TEST FAILED" % test_name) self.result_list.clear() assert False else: self.log.info("### %s : TEST SUCCESSFUL" % test_name) self.result_list.clear() assert True
class FindExistingValuePage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.util = Util() """ Unless otherwise noted, locator_type is 'ID' """ # LOCATORS _new_window_link = "New Window" # LINK_TEXT _help_link = "Help" # LINK_TEXT _keyword_search_tab = "ICTAB_1" _add_new_value_tab = "ICTAB_2" _supplier_id_txt = "VENDOR_AP_VW_VENDOR_ID" _persistence_select = "VENDOR_AP_VW_VENDOR_PERSISTENCE" _short_supplier_name_txt = "VENDOR_AP_VW_VENDOR_NAME_SHORT" _our_customer_number_txt = "VENDOR_AP_VW_AR_NUM" _supplier_name = "VENDOR_AP_VW_NAME1" _search_btn = "#ICSearch" _clear_btn = "#ICClear" _basic_search_link = "Basic Search" # LINK_TEXT _save_search_criteria_link = "Save Search Criteria" # LINK_TEXT _find_existing_value_link = "Find an Existing Value" # LINK_TEXT _keyword_search_link = "Keyword Search" # LINK_TEXT _add_new_value_link = "Add a New Value" # LINK_TEXT def click_add_new_value_tab(self): self.element_click(self._add_new_value_tab) def add_a_new_value(self): self.driver.switch_to.frame("ptifrmtgtframe") self.util.sleep(1, "the active window to be recognized by the app.") self.click_add_new_value_tab() def search_for_supplier(self): self.driver.switch_to_frame("ptifrmtgtframe") self.util.sleep(1, "the active window to be recognized by the app.") def enter_supplier_id(self, supplier): self.driver.switch_to_frame("ptifrmtgtframe") self.util.sleep(1, "the active window to be recognized by the app.") self.sendkeys(supplier, self._supplier_id_txt) def click_search_btn(self): self.element_click(self._search_btn) self.util.sleep(2, "the Summary page to open.")
class LoginPage(SeleniumDriver): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators _login_link = "Login" _email_input = "user_email" _pwd_input = "user_password" _login_btn = "commit" def click_login_link(self): # self.get_login_link().click() self.element_click(self._login_link, locator_type="linktext") def enter_email(self, email): # self.get_email_input().send_keys(email) self.element_send_keys(email, self._email_input) def enter_pwd(self, pwd): # self.get_pwd_input().send_keys(pwd) self.element_send_keys(pwd, self._pwd_input) def click_login_btn(self): # self.get_login_btn().click() self.element_click(self._login_btn, locator_type="name") def login(self, username='', pwd=''): self.click_login_link() self.enter_email(username) self.enter_pwd(pwd) self.click_login_btn() def verify_login_success(self): result = self.is_element_present( ".//div[@id='navbar']//span[text()='Test User']", by_type="xpath") return result def verify_login_failed(self): result = self.is_element_present( "//div[contains(text(),'Invalid email or password')]", by_type="xpath") return result
class VATRegistrationDetailsWindows(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver self.util = Util() # LOCATORS _help_link = "Help" # LINK_TEXT _personalize_link = "Personalize" # LINK_TEXT _find_link = "Find" # LINK_TEXT _country = "VNDR_VAT_RGSTRN_COUNTRY$0" _vat_registration_id = "VNDR_VAT_RGSTRN_VAT_RGSTRN_ID$0" _ok_button = "#ICSave" _cancel_button = "#ICCancel" def enter_country(self): self.sendkeys(("LUX", Keys.TAB), self._country) self.util.sleep(2, "the Country to be recognized by the app.") def enter_vat_registration_id(self): random_number = randint(100000000000000, 999999999999999) self.sendkeys(random_number, self._vat_registration_id) self.util.sleep( 2, "the VAT Registration ID, {}, to be recognized by the application." .format(random_number)) def click_save_button(self): self.element_click(self._ok_button) wait = WebDriverWait(self.driver, 10, poll_frequency=1) wait.until(ec.visibility_of_element_located((By.ID, "ptifrmtgtframe"))) try: self.driver.switch_to.frame("ptifrmtgtframe") except Exception as e: print(e) """ METHOD CALLED FROM IDENTIFYING INFO PAGE """ def enter_vat_registration_details(self): self.enter_country() self.enter_vat_registration_id() self.click_save_button()
class LoginPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators login_link = "//li[@class='d--ib']//button[@class='btn-reset text--15 text--normal text--upper js-pre-login-modal-button']" email_field = "username" password_field = "password" login_button = "//button[@id='_submit']" error_message = "//p[contains(text(),'Your email or password are incorrect. Please try again.')]" user_icon = "//div[@class='pull-right']//button[@type='button']" def click_login_link(self): self.element_click(self.login_link, locator_type="xpath") def enter_email(self, email): self.send_keys(email, self.email_field) def enter_password(self, password): self.send_keys(password, self.password_field) def click_login_button(self): self.element_click(self.login_button, locator_type="xpath") def login(self, email="", password=""): time.sleep(3) self.enter_email(email) self.enter_password(password) self.click_login_button() def verify_login_successful(self): result = self.is_element_present(self.user_icon, locator_type="xpath") return result def verify_login_failed(self): result = self.is_element_present(self.error_message, locator_type="xpath") return result def verify_login_title(self): return self.verify_page_title("Kindergifts")
class PersonalInformationPage(BasePage): """ Page class representing the personal information page Contains methods that interact with web elements located on the personal information page Arguments: None Attributes: log: Logger instance """ log = custom_logger(logging.INFO) # locators _old_password_input = "old_passwd" _new_password_input = "passwd" _confirm_new_password_input = "confirmation" _save_button = "submitIdentity" _changed_password_successful = "p.alert.alert-success" def enter_old_password_input(self, old_password): self.sending_keys(old_password, self._old_password_input) def enter_new_password_input(self, new_password): self.sending_keys(new_password, self._new_password_input) def confirm_new_password_input(self, confirmed_password): self.sending_keys(confirmed_password, self._confirm_new_password_input) def click_save_button(self): self.click_element(self._save_button, "name") def change_password(self, old_password, new_password, confirmed_password): self.enter_old_password_input(old_password) self.enter_new_password_input(new_password) self.confirm_new_password_input(confirmed_password) self.click_save_button() def Verify_valid_password_change(self): return self.is_text_present(self._changed_password_successful, "css", "Your personal information has " "been successfully updated.")
class LoginPage(BasePage): log = cl.custom_logger(logging.DEBUG) def __init__(self, driver): super().__init__(driver) self.driver = driver # Locators login_link = "Login" email_field = "user_email" password_field = "user_password" login_button = "//input[@type='submit']" user_icon = "//span[@class='navbar-current-user']" error_message = "// div[contains(text(),'Invalid email or password')]" def click_login_link(self): self.element_click(self.login_link, locator_type="link") def enter_email(self, email): self.send_keys(email, self.email_field) def enter_password(self, password): self.send_keys(password, self.password_field) def click_login_button(self): self.element_click(self.login_button, locator_type="xpath") def login(self, email="", password=""): self.click_login_link() self.enter_email(email) self.enter_password(password) self.click_login_button() def verify_login_successful(self): result = self.is_element_present(self.user_icon, locator_type="xpath") return result def verify_login_failed(self): result = self.is_element_present(self.error_message, locator_type="xpath") return result def verify_login_title(self): return self.verify_page_title("Let's Kode It")