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]"
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()
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'}
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 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
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 __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.header = "Drag and Drop" self.xpath_heading = "//h3" self.xpath_a_box = "//div[@id='column-a']/header" self.xpath_b_box = "//div[@id='column-b']/header"
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"
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 __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 __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 __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 __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 __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 __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 __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 __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 __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 __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 __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 __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 __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]"
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)
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 __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 __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 __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 __init__(self, driver): self.driver = driver self.services = Services(self.driver) self.xpathLoginButton = "//button[@data-role='loginHeaderButton']" self.submit = "//button[@data-id='login-button']" self.username = "******" self.password = "******" self.profile = "//a[@data-role='accountProfileLink']" self.logout = "//button[@data-role='logoutHeaderButton']" self.email_validation = "//div[@data-role='validationError'][contains(text(),'Please enter a valid email')]" self.password_validation = "//div[@data-role='validationError'][contains(text(),'Password is required')]" self.forgot = "//a[@data-role='loginForgotPasswordButton']" self.close = "//div[@data-role='closeIcon']" self.signup = "Become a member now"
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 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()