Beispiel #1
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)