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 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 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 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 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 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 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 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 WelcomePage: def __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.title = "The Internet" self.xpath_link = "//a[text()='%s']" def verify_welcome_page(self): """ This method is to verify Welcome page. return: instance of welcome page rtype: WelcomePage instance """ logging.info('## Verifying home page ##') actual_title = self.driver.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 def click_on_link(self, link_txt): """ This method is to click on the links present on the welcome page. param link_txt: link text present on the Welcome page type link_txt: string return: returns the instance of the next navigating page. rtype: instance """ logging.info("# Click on link '%s'" % link_txt) self.services.assert_and_click_by_xpath(self.xpath_link % link_txt) # Link Text: Checkboxes if link_txt == "Checkboxes": checkbox_page = CheckboxPage(self.driver) checkbox_page.verify_checkbox_page() return checkbox_page # Link Text: Dropdown if link_txt == "Dropdown": dropdown_page = DropdownPage(self.driver) dropdown_page.verify_dropdown_page() return dropdown_page # Link Text: Dropdown if link_txt == "Context Menu": context_menu_page = ContextMenuPage(self.driver) context_menu_page.verify_context_menu_page() return context_menu_page # Link Text: Challenging DOM if link_txt == "Challenging DOM": challenging_dom_page = ChallengingDomPage(self.driver) challenging_dom_page.verify_challenging_dom_page() return challenging_dom_page # Link Text: Disappearing Elements if link_txt == "Disappearing Elements": disappearing_elements_page = DisappearingElementsPage(self.driver) disappearing_elements_page.verify_disappearing_elements_page() return disappearing_elements_page # Link Text: Dynamic Controls if link_txt == "Dynamic Controls": dynamic_controls_page = DynamicControlsPage(self.driver) dynamic_controls_page.verify_dynamic_controls_page() return dynamic_controls_page # Link Text: Dynamic Loading if link_txt == "Dynamic Loading": dynamic_loading_page = DynamicLoadingPage(self.driver) dynamic_loading_page.verify_dynamic_loading_page() return dynamic_loading_page # Link Text: Dynamic Loading if link_txt == "Drag and Drop": drag_and_drop_page = DragAndDropPage(self.driver) drag_and_drop_page.verify_drag_and_drop_page() return drag_and_drop_page # Link Text: JQuery UI Menus if link_txt == "JQuery UI Menus": jquery_menu_page = JQueryUIMenuPage(self.driver) jquery_menu_page.verify_jquery_menu_page() return jquery_menu_page return self