コード例 #1
0
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)
コード例 #2
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)
コード例 #3
0
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)