class MultipleWindowsPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Opening a new window" self.xpathHeading = "//h3" self.cssLink = "div.example > a" def verify_multiple_windows_page(self): """ This method is to verify Multiple Windows page. return: instance of Multiple Windows page rtype: Multiple Windows Page instance """ logging.info("## Verifying Multiple Windows page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Multiple Windows page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_next_window_txt(self): self.driver.find_element_by_css_selector(self.cssLink).click() handles = self.driver.window_handles for handle in handles: if handle != self.driver.current_window_handle: self.driver.switch_to.window(handle) assert "New Window" == self.driver.title
class FileUpLoadingPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "File Uploader" self.xpathHeading = "//h3" self.xpathChooseFile = "//input[@id='file-upload']" self.xpathUploadBtn = "//input[@id='file-submit']" self.xpathUploadedFiles = "//div[@id='uploaded-files']" def verify_file_uploader_page(self): """ This method is to verify File Uploader page. return: instance of File Uploader page rtype: File UploaderPage instance """ logging.info("## Verifying File Uploader page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on File Uploader page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_uploaded_file(self): self.driver.find_element_by_xpath(self.xpathChooseFile).send_keys( "E:\\eclipse\\selLearning\\download\\menu.pdf") sleep(2) self.services.assert_and_click_by_xpath(self.xpathUploadBtn) self.services.wait_for_element(self.xpathUploadedFiles) assert "menu.pdf" == self.services.get_text_by_xpath( self.xpathUploadedFiles)
class FileDownLoadingPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "File Downloader" self.xpathHeading = "//h3" self.xpathLink = "//a[text()='%s']" def verify_file_downloader_page(self): """ This method is to verify File Downloader page. return: instance of File Downloader page rtype: File DownloaderPage instance """ logging.info("## Verifying File Downloader page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on File Downloader page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_file_downloading(self, link): self.services.assert_and_click_by_xpath(self.xpathLink%link)
class KeyPressesPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Key Presses" self.xpath_heading = "//h3" self.xpath_result = "//*[@id='result']" self.send_keys = {'ENTER': Keys.ENTER, 'A': 'a'} def verify_key_presses_page(self): """ This method is to verify Key Presses page. return: instance of Key Presses page rtype: Key Presses Page instance """ logging.info("## Verifying Key Presses page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Key Presses page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_key_presses(self): """ This method is to verify Key Presses after input. The result should be the same as the input """ for result, key in self.send_keys.items(): ActionChains(self.driver).send_keys(key).perform() self.services.wait_for_element(self.xpath_result) key_result = self.services.get_text_by_xpath(self.xpath_result) assert key_result == "You entered: %s" % result, "The result should be %s after input" % result
class NotificationMessagePage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Notification Message" self.xpath_heading = "//h3" self.xpath_href = "//a[@href = '/notification_message']" self.xpath_notification_message = "//div[@id = 'flash']" def verify_notification_message_page(self): """ This method is to verify Notification Message page. return: instance of Notification Message page rtype: Notification Message Page instance """ logging.info("## Verifying Notification Message page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Notification Message page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_notification_message(self): """ This method is to verify notification message. """ href_button = self.driver.find_element_by_xpath(self.xpath_href) href_button.click() notification_message = self.driver.find_element_by_xpath(self.xpath_notification_message) actual = notification_message.get_attribute('innerHTML') assert "Action successful" or "Action unsuccesful, please try again" in actual, "Notification message appears"
class ContextMenuPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Context Menu" self.xpathHeading = "//h3" self.hot_spot = "//div[@id='hot-spot']" def verify_context_menu_page(self): """ This method is to verify Context Menu page. return: instance of Context Menu page rtype: ContextMenuPage instance """ logging.info('## Verifying context menu page ##') self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Context Menu page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) return self def perform_right_click(self): self.services.wait_for_element(self.hot_spot) logging.info('## Find element on which right click need to perform. ##') hot_spot_ele = self.driver.find_element_by_xpath(self.hot_spot) actions = ActionChains(self.driver) actions.context_click(hot_spot_ele).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ARROW_DOWN).send_keys(Keys.ENTER).perform() sleep(2) alert = Alert(self.driver) alert.accept()
class DisappearingElementsPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Disappearing Elements" self.xpathHeading = "//h3" self.xpathTabs = "//ul//li//a" self.xpathTabByText = self.xpathTabs + "[text()='%s']" def verify_disappearing_elements_page(self): """ This method is to verify Disappearing Elements page. return: instance of Disappearing Elements page rtype: ChallengingDomPage instance """ logging.info("## Verifying Disappearing Elements page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Disappearing Elements page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def get_list_of_all_tabs(self): """ This function is to get the list of all tabs present on page. :return: list of button """ self.services.wait_for_element(self.xpathTabs) tabs_ele = self.driver.find_elements_by_xpath(self.xpathTabs) tab_lst = [] for btn in tabs_ele: tab_lst.append(btn.text) return tab_lst def verify_tab_disappear(self, tab_name): """ This function is to tab disappearance. :param tab_name: string """ xpath = self.xpathTabByText % tab_name print(xpath) while (True): self.driver.refresh() if not self.services.is_element_present(xpath): logging.info("# Tab '%s' is not present." % tab_name) break logging.info("# Tab '%s' is present." % tab_name) assert not self.services.is_element_present( xpath), "Tab '%s' should not present." % tab_name
class DragAndDropPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Mootools Drag and Drop example" self.xpath_heading = "//h1" self.xpath_a_box = "//div[@id='dragger']" self.xpath_b_box = "//div[@class='item'][1]" def verify_drag_and_drop_page(self): """ This method is to verify Drag and Drop page. return: instance of Drag and Drop page rtype: Drag and DropPage instance """ logging.info("## Verifying Drag and Drop page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Drag and Drop page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def drag_a_to_b(self): ele_a = self.driver.find_element_by_xpath(self.xpath_a_box) location = ele_a.location size = ele_a.size print(location) print(size) ele_b = self.driver.find_element_by_xpath(self.xpath_b_box) location = ele_b.location size = ele_b.size print(location) print(size) # {'y': 91.0, 'x': 430.0} # {'width': 116.0, 'height': 16.0} x_coordinate = int(location['x']) + int((size['width'] / 2)) print("x_coordinate: %d" % x_coordinate) y_coordinate = int(location['y']) print("y_coordinate: %d" % y_coordinate) action_chain = ActionChains(self.driver) #action_chain.drag_and_drop(ele_a, ele_b).perform() #action_chain.move_to_element(ele_a).click_and_hold(ele_a).move_to_element(ele_b).perform() #action_chain.drag_and_drop_by_offset(ele_a, x_coordinate, y_coordinate).perform() #action_chain.click_and_hold(ele_a).move_to_element(ele_b).perform() #action_chain.click_and_hold(ele_a).move_by_offset(x_coordinate, y_coordinate).perform() #action_chain.click_and_hold(ele_a).move_to_element_with_offset(ele_b, size['width'], y_coordinate).perform() #action_chain.click_and_hold(ele_a).move_to_element(ele_b).release(ele_b).perform() import time for x in range(500, 700, 10): action_chain = ActionChains(self.driver) action_chain.click_and_hold(ele_a).move_by_offset( x, y_coordinate).perform() time.sleep(1)
class DynamicContentPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Dynamic Content" self.xpath_heading = "//h3" self.xpath_img = "//*[@id='content']/div[%d]/div[1]/img" self.xpath_text = "//*[@id='content']/div[%d]/div[2]" self.image_texts = [] def verify_dynamic_content_page(self): """ This method is to verify Dynamic Content page. return: instance of Dynamic Content page rtype: Dynamic Content Page instance """ logging.info("## Verifying Dynamic Content page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Dynamic Content page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_dynamic_images_texts(self): """ This method is to verify Dynamic Contents after reloading. Not all elements would change after reloading. Thus, only one change is acceptable. """ for index in range(1, 4): xpath_img = self.xpath_img % index xpath_text = self.xpath_text % index self.image_texts.append({ "img": self.services.get_src_by_xpath(xpath_img), "text": self.services.get_text_by_xpath(xpath_text) }) self.services.reload_page() self.services.wait_for_element("//*[@id='content']") b_pass = False for index in range(3): content_img = self.services.get_src_by_xpath( (self.xpath_img % (index + 1))) content_text = self.services.get_text_by_xpath(self.xpath_text % (index + 1)) if content_img != self.image_texts[index][ "img"] or content_text != self.image_texts[index]["text"]: b_pass = True assert b_pass is True, "After reloading, one of the image/text should be different"
class FramesPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Frames" self.xpathHeading = "//h3" self.xpathLink = "//a[text()='%s']" self.xpathBottomFrame = "//frame[@name='frame-bottom']" self.xpathTopFrame = "//frame[@name='frame-top']" self.xpathLeftFrame = "//frame[@name='frame-left']" self.xpathMiddleFrame = "//frame[@name='frame-middle']" self.xpathRightFrame = "//frame[@name='frame-right']" def verify_multiple_windows_page(self): """ This method is to verify Frames page. return: instance of Frames page rtype: Frames Page instance """ logging.info("## Verifying Frames page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Frames page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def click_on_link(self, lnk): self.services.assert_and_click_by_xpath(self.xpathLink % lnk) def verify_next_frame_txt(self): self.services.wait_for_element(self.xpathBottomFrame) top_frame = self.driver.find_element_by_xpath(self.xpathTopFrame) self.driver.switch_to.frame(top_frame) left_frame = self.driver.find_element_by_xpath(self.xpathLeftFrame) self.driver.switch_to.frame(left_frame) print(self.services.get_text_by_xpath("//body")) self.driver.switch_to_default_content() top_frame = self.driver.find_element_by_xpath(self.xpathTopFrame) self.driver.switch_to.frame(top_frame) middle_frame = self.driver.find_element_by_xpath(self.xpathMiddleFrame) self.driver.switch_to.frame(middle_frame) print(self.services.get_text_by_xpath("//body"))
class CheckboxPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Checkboxes" self.xpathHeading = "//h3" self.xpathCheckboxes = "//input[@type='checkbox'][%d]" def verify_checkbox_page(self): """ This method is to verify Checkbox page. return: instance of Checkbox page rtype: CheckboxPage instance """ logging.info("## Verifying checkbox page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on checkbox page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def select_checkbox(self, index, to_select=True): """ This method is to check or uncheck checkbox. If to_select is True, then it will check the checkbox, else it will un-check it param index: Index of the checkbox on which check/un-check action has to perform. type index: number param to_select: If True will check, otherwise will un-check. Default value is True type to_select: bool """ logging.info("# Select or un-select checkbox.") xpath = self.xpathCheckboxes % index self.services.wait_for_element(xpath) checkbox_ele = self.driver.find_element_by_xpath(xpath) if to_select: if not checkbox_ele.is_selected(): logging.info("# Selecting checkbox.") checkbox_ele.click() else: if checkbox_ele.is_selected(): logging.info("# Un-selecting checkbox.") checkbox_ele.click()
class HoversPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Hovers" self.xpath_heading = "//h3" self.xpath_image = "//div[@class='figure']" self.xpath_image_1 = self.xpath_image + "[1]//img" self.xpath_image_2 = self.xpath_image + "[2]//img" self.xpath_image_3 = self.xpath_image + "[3]//img" self.xpath_image_1_caption = self.xpath_image + "[1]//div[@class='figcaption']" self.xpath_image_2_caption = self.xpath_image + "[2]//div[@class='figcaption']" self.xpath_image_3_caption = self.xpath_image + "[3]//div[@class='figcaption']" def verify_hovers_page(self): """ This method is to verify Hovers page. return: instance of Hovers page rtype: HoversPage instance """ logging.info("## Verifying Hovers page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Hovers page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_hovers_functionality(self): image_1 = self.driver.find_element_by_xpath(self.xpath_image_1) image_2 = self.driver.find_element_by_xpath(self.xpath_image_2) self.services.assert_element_visibility(self.xpath_image_2_caption, False) action_chain = ActionChains(self.driver) action_chain.move_to_element(image_1).perform() from time import sleep sleep(1) action_chain.move_to_element(image_2).perform() from time import sleep sleep(1) self.services.is_element_visible(self.xpath_image_2_caption)
class ContextMenuPage: def __init__(self, driver): import win32com.client as comclt self.driver = driver self.services = Services(self.driver) self.header = "Context Menu" self.xpathHeading = "//h3" self.hot_spot = "//div[@id='hot-spot']" def verify_context_menu_page(self): """ This method is to verify Context Menu page. return: instance of Context Menu page rtype: ContextMenuPage instance """ logging.info('## Verifying context menu page ##') self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Context Menu page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) return self def perform_right_click(self): self.services.wait_for_element(self.hot_spot) logging.info( '## Find element on which right click need to perform. ##') hot_spot_ele = self.driver.find_element_by_xpath(self.hot_spot) wsh = comclt.Dispatch("WScript.Shell") actions = ActionChains(self.driver) actions.move_to_element(hot_spot_ele).context_click().perform() wsh.SendKeys("{DOWN}") wsh.SendKeys("{DOWN}") wsh.SendKeys("{DOWN}") wsh.SendKeys("{DOWN}") wsh.SendKeys("{DOWN}") wsh.SendKeys("{ENTER}") sleep(3) alert = Alert(self.driver) alert.accept()
class IndexPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.dropDown = "//a[contains(text(), 'QA_traininguser13(Empirix_QA_Training)')]" self.languageJav = "//a[contains(text(), 'Japanese')]" self.languageJavAl = "//div[contains(text(), 'Japanese')]" self.languageEng = "//a[contains(text(), 'English')]" self.languageEngAl = "//div[contains(text(), 'English')]" self.verifyJav = "//a[contains(text(), 'ダッシュボード')]" self.verifyEng = "//a[contains(text(), 'Dashboard')]" def switch_language(self, language): """ This method is to login into page. return: instance of index page rtype: indexPage instance """ logging.info("## Verifying login page ##") self.services.assert_and_click_by_xpath(self.dropDown) if language == "Japanese": if self.services.is_element_present(self.languageJavAl): logging.info("Already language is Japanese.") else: if self.services.is_element_present(self.languageJav): self.services.assert_and_click_by_xpath(self.languageJav) obj = self.driver.switch_to.alert obj.accept() self.services.wait_for_element(self.verifyJav) else: raise Exception("Element is not present") else: if self.services.is_element_present(self.languageEngAl): logging.info("Already language is English") else: if self.services.is_element_present(self.languageEng): self.services.assert_and_click_by_xpath(self.languageEng) obj = self.driver.switch_to.alert obj.accept() self.services.wait_for_element(self.verifyEng) else: raise Exception("Element is not present")
class JQueryUIMenuPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "JQueryUI - Menu" self.xpath_heading = "//h3" self.xpath_enabled = "//ul[@id='menu']//li/a[text()='Enabled']" self.xpath_downloads = "//li/a[text()='Downloads']" self.xpath_file_option = "//li/a[text()='%s']" # self.xpath_file_option = "//*[@href='/download/jqueryui/menu/menu.%s']" def verify_jquery_menu_page(self): """ This method is to verify JQueryUI - Menu page. return: instance of JQueryUI - Menu page rtype: JQueryUI - MenuPage instance """ logging.info("## Verifying JQueryUI - Menu page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on JQueryUI - Menu page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_jquery_menu(self, file_option="Excel"): enabled = self.driver.find_element_by_xpath(self.xpath_enabled) action_chains = ActionChains(self.driver) action_chains.move_to_element(enabled).perform() self.services.wait_for_element_visible(self.xpath_downloads) download = self.driver.find_element_by_xpath(self.xpath_downloads) action_chains.move_to_element(download).perform() self.services.wait_for_element_visible(self.xpath_file_option % file_option) option = self.driver.find_element_by_xpath(self.xpath_file_option % file_option) action_chains.move_to_element(option).perform() # it might go fail if file_option is not Excel because # another element <div class="large-4 large-centered columns"> obscures it self.services.assert_and_click_by_xpath(self.xpath_file_option % file_option)
class FloatingMenuPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Floating Menu" self.xpath_heading = "//h3" self.xpath_menu = "//*[@id='menu']" self.css_attr = "position" self.css_value = "absolute" def verify_floating_menu_page(self): """ This method is to verify Floating Menu page. return: instance of Floating Menu page rtype: Floating Menu Page instance """ logging.info("## Verifying Floating Menu page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Floating Menu page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_floating_menu(self): """ This method is to verify Floating Menu after scrolling. The menu should always be on the top. """ # the position should be absolute for floating css_floating = self.services.get_css_by_xpath(self.xpath_menu, self.css_attr) assert css_floating == self.css_value, "The attribute of position should be %s" % self.css_value # after scrolling, the y value should be different before_scrolling = self.services.get_position_by_xpath(self.xpath_menu) self.driver.execute_script( "window.scrollTo(0, document.body.scrollHeight);") self.services.wait_for_element(self.xpath_menu) after_scrolling = self.services.get_position_by_xpath(self.xpath_menu) assert before_scrolling.get("y") != after_scrolling.get( "y"), "The position should be different after scrolling"
class LargeDeepDomPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Large & Deep DOM" self.xpath_heading = "//h3" self.js_no_siblings = "$('div.parent')" self.js_no_siblings_length = 52 self.js_table = "$('td')" self.js_table_length = 2500 def verify_large_deep_dom_page(self): """ This method is to verify Large Deep Dom page. return: instance of Large Deep Dom page rtype: Large Deep Dom instance """ logging.info("## Verifying Large Deep Dom page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Large Deep Dom page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_large_deep_dom_no_sibling(self): """ This method is to verify Large Deep Dom with no sibling by executing jquery The result should be the same as the input """ length_no_sibling = self.driver.execute_script("return %s.length" % self.js_no_siblings) assert length_no_sibling == self.js_no_siblings_length, "Actual depth of no siblings should be %d" % self.js_no_siblings_length def verify_large_deep_dom_table(self): """ This method is to verify Large Deep Dom with table by executing jquery The result should be the same as the input """ length_table = self.driver.execute_script("return %s.length" % self.js_table) assert length_table == self.js_table_length, "Actual depth of no siblings should be %d" % self.js_table_length
class JQueryUIMenuPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "JQueryUI - Menu" self.xpath_heading = "//h3" self.xpath_enabled = "//ul[@id='menu']//li/a[text()='Enabled']" self.xpath_downloads = "//li/a[text()='Downloads']" self.xpath_file_option = "//li/a[text()='%s']" def verify_jquery_menu_page(self): """ This method is to verify JQueryUI - Menu page. return: instance of JQueryUI - Menu page rtype: JQueryUI - MenuPage instance """ logging.info("## Verifying JQueryUI - Menu page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on JQueryUI - Menu page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_jquery_menu(self, file_option="PDF"): enabled = self.driver.find_element_by_xpath(self.xpath_enabled) action_chains = ActionChains(self.driver) action_chains.move_to_element(enabled).perform() self.services.wait_for_element_visible(self.xpath_downloads) download = self.driver.find_element_by_xpath(self.xpath_downloads) action_chains.move_to_element(download).perform() self.services.wait_for_element_visible(self.xpath_file_option % file_option) option = self.driver.find_element_by_xpath(self.xpath_file_option % file_option) action_chains.move_to_element(option).perform() self.services.assert_and_click_by_xpath(self.xpath_file_option % file_option)
class RedirectLinkPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Redirection" self.xpath_heading = "//h3" self.xpath_here = "//*[@id='redirect']" self.xpath_status = "//*[@id='content']/div/ul/li/a[text()=%d]" def verify_redirect_link_page(self): """ This method is to verify Redirect Link page. return: instance of Redirect Link page rtype: Redirect Link instance """ logging.info("## Verifying Redirect Link page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Redirect Link page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_redirect_link(self): # click the redirect button self.services.assert_and_click_by_xpath(self.xpath_here) self.services.wait_for_element_visible(self.xpath_status % 200) def verify_redirect_link_status_code(self, status_code): href = self.services.get_href_by_xpath(self.xpath_status % status_code) self.services.assert_and_click_by_xpath(self.xpath_status % status_code) request = get(href) assert request.status_code == status_code, "Actual status code should be %d" % status_code # go back to previous page self.driver.back() self.services.wait_for_element_visible(self.xpath_status % status_code)
class DropdownPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Dropdown List" self.xpath_heading = "//h3" self.xpath_dropdown = "//select[@id='dropdown']" def verify_dropdown_page(self): """ This method is to verify Dropdown page. return: instance of Dropdown page rtype: DropdownPage instance """ logging.info("## Verifying Dropdown page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Dropdown page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def select_dropdown_option(self, opt): """ This method is to select value in dropdown. @param opt: visible text type opt: string """ select = Select(self.driver.find_element_by_xpath(self.xpath_dropdown)) #select.select_by_index(1) #select.select_by_value("2") select.select_by_visible_text(opt) sleep(1) actual = select.first_selected_option.text assert actual == opt, "Selected value {0}, should be same as expected {1}".format( actual, opt)
class FileUpLoadingPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "File Uploader" self.xpathHeading = "//h3" self.xpathChooseFile = "//input[@id='file-upload']" self.xpathUploadBtn = "//input[@id='file-submit']" self.xpathUploadedFiles = "//div[@id='uploaded-files']" def verify_file_uploader_page(self): """ This method is to verify File Uploader page. return: instance of File Uploader page rtype: File UploaderPage instance """ logging.info("## Verifying File Uploader page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on File Uploader page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_uploaded_file(self): """To test this, use a file present in the local system So change the path according to that """ self.driver.find_element_by_xpath( self.xpathChooseFile).send_keys("D:\\Culture.ppt") sleep(2) self.services.assert_and_click_by_xpath(self.xpathUploadBtn) self.services.wait_for_element(self.xpathUploadedFiles) assert "Culture.ppt" == self.services.get_text_by_xpath( self.xpathUploadedFiles)
class InfiniteScrollPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Infinite Scroll" self.xpath_heading = "//h3" def verify_infinite_scroll_page(self): """ This method is to verify infinite scroll page. return: instance of Infinite scroll page rtype: Infinite scroll Page instance """ logging.info("## Verifying Infinite Scroll page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Infinite Scroll page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_infinite_scroll(self, itr): """ This method is to verify infinite scroll. """ scroll_flag = False count = 0 for i in range(0, itr): self.driver.execute_script( "window.scrollTo(0, document.body.scrollHeight);") count += 1 if count == itr: scroll_flag = True assert scroll_flag is True, "Infinite Scroll is happening"
class CasinoPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.title = "Exclusive Casino Games - Best online casino | Optibet" self.casino = "//a[@data-role='Casino']" def verify_casino_page(self): """ This method is to verify Casino page. return: instance of Casino page rtype: CasinoPage instance """ casino = self.casino self.services.wait_for_element(casino) casino_button = self.driver.find_element_by_xpath(casino) logging.info("# Clicking Casino button") casino_button.click() logging.info('## Verifying Casino page ##') actual_title = self.title logging.info('# Actual Title: %s' % actual_title) assert actual_title == self.title, "Actual title %s, should be same as %s" % ( actual_title, self.title) return self
class LoginPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.xpathHeading = "//strong[contains(text(),'Sign in to continue')]" self.userName = "******" self.password = "******" self.signIn = "//input[contains(@value, 'Sign in')]" self.dashboard = "//a[contains(text(), 'Dashboard')]" def login(self, user_name, password): """ This method is to login into page. return: instance of index page rtype: indexPage instance """ logging.info("## Verifying login page ##") self.services.wait_for_element(self.xpathHeading) self.driver.find_element_by_xpath(self.userName).send_keys(user_name) self.driver.find_element_by_xpath(self.password).send_keys(password) self.services.assert_and_click_by_xpath(self.signIn) self.services.wait_for_element(self.dashboard)
class SearchPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.search_field = "//input[@data-role='searchInput']" self.search_button = "search" self.search_data = "Dragon Stone" self.game_thumb = "//div[@data-role='gameThumb']" self.game_title = "Dragon Stone - Play Now! Best Online Casino | Optibet" def click_search_button(self): """ This method to click on search button """ button = self.search_button self.services.wait_for_element_name(button) click_button = self.driver.find_element_by_name(button) logging.info("# Clicking Search button") click_button.click() def enter_search_data(self): """ This method to enter search data and verify """ field = self.search_field data = self.search_data thumb = self.game_thumb self.services.wait_for_element(field) enter_data = self.driver.find_element_by_xpath(field) enter_data.send_keys(data) self.services.wait_for_element(thumb) def validate_game_page(self): """ This method to validate game page after search """ thumb = self.game_thumb self.services.wait_for_element(thumb) click_game = self.driver.find_element_by_xpath(thumb) click_game.click() logging.info('## Verifying game page ##') gametitle = self.game_title logging.info('# Actual Title: %s' % gametitle) assert gametitle == self.driver.title, "Actual title %s, should be same as %s" % ( gametitle, self.driver.title) return self
class JavaScriptAlertsPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "JavaScript Alerts" self.xpath_heading = "//h3" self.xpath_alert = "//button[@onClick = 'jsAlert()']" self.xpath_confirm = "//button[@onClick = 'jsConfirm()']" self.xpath_prompt = "//button[@onClick = 'jsPrompt()']" self.xpath_result = "//p[@id = 'result']" def verify_javascript_alerts_page(self): """ This method is to verify JavaScript Alerts page. return: instance of JavaScript Alerts page rtype: JavaScript Alerts Page instance """ logging.info("## Verifying JavaScript Alerts page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on JavaScript Alerts page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_javascript_alert(self): """ This method is to verify javascript alert. """ alert_button = self.driver.find_element_by_xpath(self.xpath_alert) alert_button.click() wait = WebDriverWait(self.driver, 5) wait.until(EC.alert_is_present()) alert = self.driver.switch_to.alert assert "I am a JS Alert" in alert.text alert.accept() def verify_javascript_confirm(self): """ This method is to verify javascript confirm. """ confirm_button = self.driver.find_element_by_xpath(self.xpath_confirm) confirm_button.click() wait = WebDriverWait(self.driver, 5) wait.until(EC.alert_is_present()) alert = self.driver.switch_to.alert assert "I am a JS Confirm" in alert.text alert.dismiss() def verify_javascript_prompt(self, txt): """ This method is to verify javascript prompt. """ prompt_button = self.driver.find_element_by_xpath(self.xpath_prompt) result_txt = self.driver.find_element_by_xpath(self.xpath_result) prompt_button.click() wait = WebDriverWait(self.driver, 5) wait.until(EC.alert_is_present()) alert = self.driver.switch_to.alert assert "I am a JS prompt" in alert.text self.driver.switch_to.alert.send_keys(txt) assert "You entered: ", txt in result_txt.get_attribute('innerHTML') alert.accept()
class DynamicLoadingPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Dynamically Loaded Page Elements" self.sub_header_1 = "Example 1: Element on page that is hidden" self.sub_header_2 = "Example 2: Element rendered after the fact" self.xpath_heading = "//h3" self.xpath_sub_heading = "//h4" self.xpath_link = "//a[contains(text(),'%s')]" self.xpath_btn = "//button" self.xpath_loading = "//div[@id='loading']" self.xpath_finsh = "//div[@id='finish']" self.txt_finsh = "Hello World!" def verify_dynamic_loading_page(self): """ This method is to verify Dynamically Loaded Page Elements page. return: instance of Dynamically Loaded Page Elements page rtype: Dynamically Loaded Page ElementsPage instance """ logging.info("## Verifying Dynamically Loaded Page Elements page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info( "# Actual heading on Dynamically Loaded Page Elements page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def click_on_link(self, link): self.services.wait_for_element(self.xpath_link % link) self.driver.find_element_by_xpath(self.xpath_link % link).click() self.services.wait_for_element(self.xpath_sub_heading) sub_heading = self.driver.find_element_by_xpath(self.xpath_sub_heading) actual_heading = sub_heading.text if 'Example 1' in link: assert actual_heading == self.sub_header_1, "Actual '%s' should be same as expected '%s'" % ( actual_heading, self.sub_header_1) else: assert actual_heading == self.sub_header_2, "Actual '%s' should be same as expected '%s'" % ( actual_heading, self.sub_header_2) def display_hidden_element(self): self.services.wait_for_element(self.xpath_btn) self.services.assert_element_present(self.xpath_finsh) self.services.assert_element_visibility(self.xpath_finsh, False) self.driver.find_element_by_xpath(self.xpath_btn).click() self.services.wait_for_element_visible(self.xpath_loading) self.services.assert_element_present(self.xpath_loading) self.services.wait_for_element_invisible(self.xpath_loading) self.services.assert_element_visibility(self.xpath_loading, False) self.services.assert_element_visibility(self.xpath_finsh) actual_txt = self.driver.find_element_by_xpath(self.xpath_finsh).text assert actual_txt == self.txt_finsh, "Actual '%s' should be same as expected '%s'" % ( actual_txt, self.txt_finsh) def render_new_element(self): self.services.wait_for_element(self.xpath_btn) self.services.assert_element_is_not_present(self.xpath_finsh) self.driver.find_element_by_xpath(self.xpath_btn).click() self.services.wait_for_element_visible(self.xpath_loading) self.services.assert_element_present(self.xpath_loading) self.services.wait_for_element_invisible(self.xpath_loading) self.services.assert_element_visibility(self.xpath_loading, False) self.services.assert_element_present(self.xpath_finsh) self.services.assert_element_visibility(self.xpath_finsh) actual_txt = self.driver.find_element_by_xpath(self.xpath_finsh).text assert actual_txt == self.txt_finsh, "Actual '%s' should be same as expected '%s'" % ( actual_txt, self.txt_finsh)
class DynamicControlsPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Dynamic Controls" self.xpath_heading = "//h4" self.xpath_btn = "//button[@type='button' and text()='%s']" self.xpath_checkbox = "//input[@type='checkbox']" self.xpath_loading = "//div[@id='loading']" def verify_dynamic_controls_page(self): """ This method is to verify Dynamic Controls page. return: instance of Dynamic Controls page rtype: Dynamic ControlsPage instance """ logging.info("## Verifying Dynamic Controls page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Dynamic Controls page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_removed_element(self): assert self.services.is_element_present( self.xpath_checkbox), "Checkbox element should be present." xpath_remove_btn = self.xpath_btn % "Remove" self.services.assert_element_present(xpath_remove_btn) remove_btn = self.driver.find_element_by_xpath(xpath_remove_btn) remove_btn.click() self.services.wait_for_element_visible(self.xpath_loading) self.services.assert_element_present(self.xpath_loading) self.services.wait_for_element_invisible(self.xpath_loading) self.services.assert_element_visibility(self.xpath_loading, False) self.services.assert_element_is_not_present(self.xpath_checkbox) self.services.assert_element_is_not_present(xpath_remove_btn) def verify_add_element(self): self.verify_removed_element() xpath_add_btn = self.xpath_btn % "Add" self.services.assert_element_present(xpath_add_btn) add_btn = self.driver.find_element_by_xpath(xpath_add_btn) add_btn.click() self.services.wait_for_element_visible(self.xpath_loading) self.services.assert_element_present(self.xpath_loading) self.services.wait_for_element_invisible(self.xpath_loading) self.services.assert_element_visibility(self.xpath_loading, False) self.services.assert_element_present(self.xpath_checkbox) self.services.assert_element_is_not_present(xpath_add_btn)
class ChallengingDomPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Challenging DOM" self.xpathHeading = "//h3" self.xpathButton = "//a[contains(@class,'button') and text()='%s']" self.xpathButtons = "//a[contains(@class,'button')]" self.xpathTableHeader = "//div[@class='large-10 columns']/table/thead/tr/th" self.xpathTableCell = "//div[@class='large-10 columns']/table/tbody/tr[%s]/td[%s]" def verify_challenging_dom_page(self): """ This method is to verify Challenging DOM page. return: instance of Challenging DOM page rtype: ChallengingDomPage instance """ logging.info("## Verifying Challenging DOM page ##") self.services.wait_for_element(self.xpathHeading) actual_heading = self.services.get_text_by_xpath(self.xpathHeading) logging.info("# Actual heading on Challenging DOM page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def get_list_of_all_buttons(self): """ This function is to get the list of all buttons present on page. :return: list of button """ self.services.wait_for_element(self.xpathButtons) buttons_ele = self.driver.find_elements_by_xpath(self.xpathButtons) btn_lst = [] for btn in buttons_ele: btn_lst.append(btn.text) return btn_lst def click_on_button(self, btn_text): """ This function is to click on the desired button by given text present on button. :param btn_text: string """ xpath = self.xpathButton % btn_text print(xpath) self.services.wait_for_element(xpath) self.driver.find_element_by_xpath(xpath).click() def get_column_index(self, col_name): ''' This function is to get the index of the column name present on the table header. :param col_name: col name :return: index ''' self.services.wait_for_element(self.xpathTableHeader) header_eles = self.driver.find_elements_by_xpath(self.xpathTableHeader) index = 0 lst = [] for header in header_eles: index += 1 h_txt = header.text.strip() lst.append(h_txt) if col_name == h_txt: return index assert index == 0, "Given col name '{0}' is not present in {1}.".format( col_name, lst) def get_cell_text(self, row_index=1, col_name=None): """ This function is to get the cell text by row index & cell index :param row_index: row index in number :param col_name: column name in string :return: cell text. """ col_index = self.get_column_index(col_name) xpath = self.xpathTableCell % (str(row_index), str(col_index)) self.services.wait_for_element(xpath) return self.driver.find_element_by_xpath(xpath).text
class ShiftingContentPage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Shifting Content" self.xpath_heading = "//h3" self.xpath_menu = "//a[@href = '/shifting_content/menu']" self.xpath_image = "//a[@href = '/shifting_content/image']" self.xpath_list = "//a[@href = '/shifting_content/list']" def verify_shifting_content_page(self): """ This method is to verify Shifting Content page. return: instance of Shifting Content page rtype: Shifting Content Page instance """ logging.info("## Verifying Shifting Content page ##") self.services.wait_for_element(self.xpath_heading) actual_heading = self.services.get_text_by_xpath(self.xpath_heading) logging.info("# Actual heading on Shifting Content page: %s" % actual_heading) assert actual_heading == self.header, "Actual header (%s), should be same as expected header (%s)." % ( actual_heading, self.header) def verify_menu_random(self): """ This method is to verify Shifting Menu element randomly. """ href_menu = self.driver.find_element_by_xpath(self.xpath_menu) href_menu.click() href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/menu?mode=random']") href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/menu?mode=random" assert current_url == expected_url, "Shifting of Menu elements happens randomly" def verify_menu_pixel_shift(self): """ This method is to verify Shifting Menu element by 100 pixels. """ href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/menu?pixel_shift=100']") href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/menu?pixel_shift=100" assert current_url == expected_url, "Shifting of Menu elements happens by 100 pixels" def verify_menu_pixel_shift_random(self): """ This method is to verify Shifting Menu element by 100 pixels. """ href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/menu?mode=random&pixel_shift=100']" ) href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/menu?mode=random&pixel_shift=100" assert current_url == expected_url, "Shifting of Menu elements happens by 100 pixels and randomly" def verify_image_random(self): """ This method is to verify shifting of image randomly element. """ href_menu = self.driver.find_element_by_xpath(self.xpath_image) href_menu.click() href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/image?mode=random']") href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/image?mode=random" assert current_url == expected_url, "Shifting of image elements happens randomly" def verify_image_pixel_shift(self): """ This method is to verify Shifting image element by 100 pixels. """ href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/image?pixel_shift=100']") href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/image?pixel_shift=100" assert current_url == expected_url, "Shifting of image elements happens by 100 pixels" def verify_image_pixel_shift_random(self): """ This method is to verify Shifting image element by 100 pixels. """ href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/image?mode=random&pixel_shift=100']" ) href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/image?mode=random&pixel_shift=100" assert current_url == expected_url, "Shifting of image elements happens by 100 pixels and randomly" def verify_image_append(self): """ This method is to verify appending image element. """ href_random = self.driver.find_element_by_xpath( "//a[@href = '/shifting_content/image?image_type=simple']") href_random.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/image?image_type=simple" assert current_url == expected_url, "Appending image element works" def verify_list(self): """ This method is to verify list element. """ href_menu = self.driver.find_element_by_xpath(self.xpath_list) href_menu.click() current_url = self.driver.current_url expected_url = "http://the-internet.herokuapp.com/shifting_content/list" assert current_url == expected_url, "List elements keeps on randomly shifting"