コード例 #1
0
    def test_complex_widget_with_multiple_iframes(self):
        widget = testingwebpages.MyComplexWidget(self.driver,
                                                 Locator.by_xpath("//widget"))
        visible_widget = testingwebpages.MyComplexWidget(
            self.driver, Locator.by_xpath("//widget"))
        visible_widget.visible_iframe = testingwebpages.MyComplexIframe(
            self.driver, Locator.by_xpath("//iframe1"))
        widget.visible_widget = visible_widget
        widget.visible_iframe = testingwebpages.MyComplexIframe(
            self.driver, Locator.by_xpath("//iframe2"))

        # Widgets currently do not have a check if there are multiple iframes defined
        widget.get_element_attr()
コード例 #2
0
 def test_get_element_attr_dict_with_iframe(self):
     widget = testingwebpages.MyComplexWidget(self.driver,
                                              Locator.by_xpath("//widget"))
     visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe"))
     widget.visible_iframe = visible_iframe
     elements = widget.get_element_attr(result_type=dict)
     assert len(elements) == 5, 'Expecting 5 elements'
     assert 'widget' in elements
     assert 'regular_element_on_widget' in elements
     assert 'invisible_element_on_widget' in elements
     assert 'not_checked_element_on_widget' in elements
     assert 'visible_iframe' in elements
コード例 #3
0
    def test_access_element_not_definedy_on_webpage(self):
        page = testingwebpages.MyComplexPage(self.driver)
        visible_iframe = testingwebpages.MyComplexIframe(
            self.driver, Locator.by_xpath("//iframe"))
        visible_widget = testingwebpages.MyComplexWidget(
            self.driver, Locator.by_xpath("//widget"))
        page.visible_iframe = visible_iframe
        page.visible_widget = visible_widget

        try:
            page.foobar
            assert False, "Expecting page.foobar to throw an AttributeError!"
        except AttributeError:
            pass
コード例 #4
0
 def test_complex_page_with_multiple_iframes(self):
     page = testingwebpages.MyComplexPage(self.driver)
     visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     visible_widget.visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe1"))
     page.visible_widget = visible_widget
     page.visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe2"))
     try:
         page.get_element_attr()
         assert False, "Expecting to throw an AttributeError because 2 iframes were defined on a page"
     except AttributeError:
         pass
コード例 #5
0
    def test_access_element_not_defined_directly_on_webpage(self):
        widget = testingwebpages.MyComplexWidget(self.driver,
                                                 Locator.by_xpath("//widget"))
        visible_widget = testingwebpages.MyComplexWidget(
            self.driver, Locator.by_xpath("//widget"))
        widget.visible_widget = visible_widget

        # None of these should throw an AttributeError
        widget.regular_element_on_widget
        widget.invisible_element_on_widget
        widget.not_checked_element_on_widget
        widget.visible_widget
        widget.visible_widget_regular_element_on_widget
        widget.visible_widget_invisible_element_on_widget
        widget.visible_widget_not_checked_element_on_widget
コード例 #6
0
 def test_get_element_attr_dict_with_expanded_widget(self):
     widget = testingwebpages.MyComplexWidget(self.driver,
                                              Locator.by_xpath("//widget"))
     visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     widget.visible_widget = visible_widget
     elements = widget.get_element_attr(result_type=dict)
     assert len(elements) == 8, 'Expecting 8 elements'
     assert 'widget' in elements
     assert 'regular_element_on_widget' in elements
     assert 'invisible_element_on_widget' in elements
     assert 'not_checked_element_on_widget' in elements
     assert 'visible_widget' in elements
     assert 'visible_widget_regular_element_on_widget' in elements
     assert 'visible_widget_invisible_element_on_widget' in elements
     assert 'visible_widget_not_checked_element_on_widget' in elements
コード例 #7
0
 def test_take_multiple_element_screenshots_with_same_name(self):
     """
     The expectation is that they overwrite each other
     """
     page = GooglePage(driver=self.driver, url="http://www.google.com")
     page.open().wait_for_page_load()
     page.element = Element(self.driver, Locator.by_xpath("//foo"))
     num_files_before = self.count_files(seleniumconfig.screenshot_dir)
     time.sleep(1)
     file1 = page.element.take_screenshot()
     time.sleep(2)
     file2 = page.element.take_screenshot(screenshot_name=file1)
     file3 = page.element.take_screenshot(screenshot_name=file1)
     filepath = "{}/{}.png".format(seleniumconfig.screenshot_dir, file1)
     time.sleep(3)
     num_files_after = self.count_files(seleniumconfig.screenshot_dir)
     assert file1 == file2 and file2 == file3, "I'm expecting the files to the same if taken really fast - file1: {} - file2: {} - file3: {}".format(
         file1, file2, file3)
     assert os.path.exists(
         filepath
     ), "Expecting that a screenshot was taken and saved here: {}".format(
         filepath)
     assert num_files_after == (
         num_files_before +
         1), "Expecting there to be 1-more screenshot taken"
コード例 #8
0
    def get_html(self):
        """
        Retrieves the html of the entire webpage

        :return: a str of the entire page html
        """
        return Element(self.driver, Locator.by_xpath("//html")).get_html()
コード例 #9
0
 def test_complex_widget_with_widget(self):
     widget = testingwebpages.MyComplexWidget(self.driver,
                                              Locator.by_xpath("//widget"))
     widget.visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     elements = widget.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 8, "Expecting there to be 8 elements in this test complex widget"
     assert meta_data['types'][
         'element'] == 6, "Expecting there to be 6 Element types"
     assert meta_data['types'][
         'widget'] == 2, "Expecting there to be 2 Widget types"
     assert meta_data['visible'] == 4, "Expecting there to be 4 visible"
     assert meta_data['invisible'] == 2, "Expecting there to be 2 invisible"
     assert meta_data[
         'do-not-check'] == 2, "Expecting there to be 2 do-not-check"
コード例 #10
0
 def __init__(self, driver, url):
     super(Wikipedia, self).__init__(driver, url)
     self.path = self.url.path
     self.headingText = TextElement(driver, Locator.by_id("firstHeading"))
     self.bodyText = TextElement(driver, Locator.by_id("bodyContent"))
     self.bodyTexts = TextElement(
         driver, Locator.by_css_selector("div#mw-content-text > div > p"))
     self.bogus_element = Element(
         driver, Locator.by_xpath("//foo")).mark_do_not_check()
コード例 #11
0
 def test_take_explicit_element_screenshot(self):
     page = GooglePage(driver=self.driver, url="http://www.google.com")
     page.open().wait_for_page_load()
     page.element = Element(self.driver, Locator.by_xpath("//foo"))
     file = page.element.take_screenshot()
     filepath = "{}/{}.png".format(seleniumconfig.screenshot_dir, file)
     assert os.path.exists(
         filepath
     ), "Expecting that a screenshot was taken and saved here: {}".format(
         filepath)
コード例 #12
0
 def test_element_change_defaults_and_then_reset(self):
     seleniumconfig.reset_timeouts()
     seleniumconfig.page_timeout_in_sec = 5
     seleniumconfig.element_timeout_in_sec = 25
     element = Element(self.driver, Locator.by_xpath("//foo"))
     assert element.page_timeout == 5, "Expecting page_timeout=5"
     assert element.element_timeout == 25, "Expecting element_timeout=25"
     seleniumconfig.reset_timeouts()
     assert element.page_timeout == 30, "Expecting page_timeout=30"
     assert element.element_timeout == 10, "Expecting element_timeout=10"
コード例 #13
0
 def test_get_element_attr_with_a_property_decorator_iframe(self):
     iframe = testingwebpages.MyComplexIframeWithErrorProperty(
         self.driver, Locator.by_xpath("//iframe"))
     elements = iframe.get_element_attr(result_type=dict,
                                        expand_iframe_elements=True)
     assert len(elements) == 4, 'Expecting 4 elements'
     assert 'widget' in elements
     assert 'regular_element' in elements
     assert 'invisible_element' in elements
     assert 'not_checked_element' in elements
コード例 #14
0
 def test_locator_by_xpath(self):
     """
     Tests that can create Locator.by_xpath(path)
     :return:
     """
     path = "//div/foobar"
     locator = Locator.by_xpath(path)
     assert locator != None
     assert locator.by == By.XPATH
     assert locator.value == path
コード例 #15
0
 def test_get_element_attr_dict_with_iframe(self):
     page = testingwebpages.MyComplexPage(self.driver)
     visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe"))
     page.visible_iframe = visible_iframe
     elements = page.get_element_attr(result_type=dict)
     assert len(elements) == 4, 'Expecting 4 elements'
     assert 'regular_element' in elements
     assert 'invisible_element' in elements
     assert 'not_checked_element' in elements
     assert 'visible_iframe' in elements
コード例 #16
0
 def test_complex_widget_with_iframe(self):
     widget = testingwebpages.MyComplexWidget(self.driver,
                                              Locator.by_xpath("//widget"))
     widget.visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe"))
     elements = widget.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 5, "Expecting there to be 5 elements in this test complex widget"
     assert meta_data['types'][
         'element'] == 3, "Expecting there to be 3 Element types"
     assert meta_data['types'][
         'widget'] == 1, "Expecting there to be 1 Widget types"
     assert meta_data['types'][
         'iframe'] == 1, "Expecting there to be 1 IFrame types"
     assert meta_data['visible'] == 3, "Expecting there to be 3 visible"
     assert meta_data['invisible'] == 1, "Expecting there to be 1 invisible"
     assert meta_data[
         'do-not-check'] == 1, "Expecting there to be 1 do-not-check"
コード例 #17
0
 def test_take_implicit_webpage_screenshot_enabled_wait_for_page_load(self):
     page = GooglePage(driver=self.driver, url="http://www.google.com")
     page.open().wait_for_page_load()
     page.invalid_element = Element(self.driver, Locator.by_xpath("//foo"))
     num_files_before = self.count_files(seleniumconfig.screenshot_dir)
     try:
         page.wait_for_page_load(timeout=5)
     except TimeoutException:
         num_files_after = self.count_files(seleniumconfig.screenshot_dir)
         assert num_files_after == (
             num_files_before +
             1), "Expecting there to be 1-more screenshot taken"
コード例 #18
0
 def test_complex_page_with_widget_iframe(self):
     page = testingwebpages.MyComplexPage(self.driver)
     visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     visible_widget.visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe"))
     page.visible_widget = visible_widget
     elements = page.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 8, "Expecting there to be 8 elements in this test complex page"
     assert meta_data['types'][
         'element'] == 6, "Expecting there to be 6 Element types"
     assert meta_data['types'][
         'widget'] == 1, "Expecting there to be 1 Widget types"
     assert meta_data['types'][
         'iframe'] == 1, "Expecting there to be 1 IFrame types"
     assert meta_data['visible'] == 4, "Expecting there to be 4 visible"
     assert meta_data['invisible'] == 2, "Expecting there to be 2 invisible"
     assert meta_data[
         'do-not-check'] == 2, "Expecting there to be 2 do-not-check"
コード例 #19
0
    def test_access_element_not_defined_directly_on_webpage_with_duplicates(
            self):
        page = testingwebpages.MyComplexPage(self.driver)
        visible_iframe = testingwebpages.MyComplexIframe(
            self.driver, Locator.by_xpath("//iframe"))
        visible_widget = testingwebpages.MyComplexWidget(
            self.driver, Locator.by_xpath("//widget"))
        page.visible_iframe = visible_iframe
        page.visible_widget = visible_widget

        # None of these should throw an AttributeError
        page.regular_element
        page.invisible_element
        page.not_checked_element
        page.visible_iframe
        page.visible_iframe_regular_element
        page.visible_iframe_invisible_element
        page.visible_iframe_not_checked_element
        page.visible_widget
        page.regular_element_on_widget
        page.invisible_element_on_widget
        page.not_checked_element_on_widget
コード例 #20
0
 def test_complex_page_with_widget_do_not_check_panel(self):
     page = testingwebpages.MyComplexPage(self.driver)
     visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     visible_widget.do_not_check_panel = testingwebpages.MyComplexPanel(
         self.driver, Locator.by_xpath("//panel")).mark_do_not_check()
     page.visible_widget = visible_widget
     elements = page.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 8, "Expecting there to be 8 elements in this test complex page"
     assert meta_data['types'][
         'element'] == 6, "Expecting there to be 6 Element types"
     assert meta_data['types'][
         'widget'] == 1, "Expecting there to be 1 Widget types"
     assert meta_data['types'][
         'panel'] == 1, "Expecting there to be 1 Panel types"
     assert meta_data['visible'] == 3, "Expecting there to be 3 visible"
     assert meta_data['invisible'] == 2, "Expecting there to be 2 invisible"
     assert meta_data[
         'do-not-check'] == 3, "Expecting there to be 3 do-not-check"
コード例 #21
0
    def get_html(self, switch_in=True):
        """
        Retrieves the html of the entire page

        :param switch_in: (Default: True) This is used for automatically switching into and out of an iFrame context
        :return: a str of the entire page html
        """
        try:
            if switch_in:
                self.switch_in()
            return Element(self.driver, Locator.by_xpath("//html")).get_html()
        finally:
            if switch_in:
                self.switch_out()
コード例 #22
0
 def test_complex_widget_with_widget_hidden_panel(self):
     widget = testingwebpages.MyComplexWidget(self.driver,
                                              Locator.by_xpath("//widget"))
     visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget"))
     visible_widget.invisible_panel = testingwebpages.MyComplexPanel(
         self.driver, Locator.by_xpath("//panel")).mark_invisible()
     widget.visible_widget = visible_widget
     elements = widget.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 9, "Expecting there to be 9 elements in this test complex widget"
     assert meta_data['types'][
         'element'] == 6, "Expecting there to be 6 Element types"
     assert meta_data['types'][
         'widget'] == 2, "Expecting there to be 2 Widget types"
     assert meta_data['types'][
         'panel'] == 1, "Expecting there to be 1 Panel types"
     assert meta_data['visible'] == 4, "Expecting there to be 4 visible"
     assert meta_data['invisible'] == 3, "Expecting there to be 3 invisible"
     assert meta_data[
         'do-not-check'] == 2, "Expecting there to be 2 do-not-check"
コード例 #23
0
    def test_take_implicit_element_screenshot_enabled_is_visible(self):
        page = GooglePage(driver=self.driver, url="http://www.google.com")
        page.open().wait_for_page_load()
        page.element = Element(self.driver, Locator.by_xpath("//foo"))
        num_files_before = self.count_files(seleniumconfig.screenshot_dir)

        try:
            page.element.is_visible(timeout=1)
        except TimeoutException:
            pass
        except NoSuchElementException:
            pass

        num_files_after = self.count_files(seleniumconfig.screenshot_dir)
        assert num_files_after == num_files_before, "Expecting there to be the same number of screenshots taken"
コード例 #24
0
    def test_take_implicit_webpage_screenshot_disabled(self):
        page = GooglePage(driver=self.driver, url="http://www.google.com")
        page.open().wait_for_page_load()
        page.invalid_element = Element(self.driver, Locator.by_xpath("//foo"))
        num_files_before = self.count_files(seleniumconfig.screenshot_dir)

        # Disable taking screenshot globally
        seleniumconfig.screenshot_enabled = False

        try:
            page.wait_for_page_load(timeout=5)
        except TimeoutException:
            num_files_after = self.count_files(seleniumconfig.screenshot_dir)
            assert num_files_after == num_files_before, "Expecting there to be the same number of screenshots taken"
        finally:
            seleniumconfig.screenshot_enabled = True
コード例 #25
0
 def test_complex_page_with_do_not_check_widget(self):
     page = testingwebpages.MyComplexPage(self.driver)
     page.visible_widget = testingwebpages.MyComplexWidget(
         self.driver, Locator.by_xpath("//widget")).mark_do_not_check()
     elements = page.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 4, "Expecting there to be 4 elements in this test complex page"
     assert meta_data['types'][
         'element'] == 3, "Expecting there to be 3 Element types"
     assert meta_data['types'][
         'widget'] == 1, "Expecting there to be 1 Widget types"
     assert meta_data['visible'] == 1, "Expecting there to be 1 visible"
     assert meta_data['invisible'] == 1, "Expecting there to be 1 invisible"
     assert meta_data[
         'do-not-check'] == 2, "Expecting there to be 2 do-not-check"
コード例 #26
0
 def test_complex_page_with_iframe(self):
     page = testingwebpages.MyComplexPage(self.driver)
     page.visible_iframe = testingwebpages.MyComplexIframe(
         self.driver, Locator.by_xpath("//iframe"))
     elements = page.get_element_attr()
     meta_data = self.calculate_meta(elements)
     assert len(
         elements
     ) == 4, "Expecting there to be 4 elements in this test complex page"
     assert meta_data['types'][
         'element'] == 3, "Expecting there to be 3 Element types"
     assert meta_data['types'][
         'iframe'] == 1, "Expecting there to be 1 IFrame types"
     assert meta_data['visible'] == 2, "Expecting there to be 2 visible"
     assert meta_data['invisible'] == 1, "Expecting there to be 1 invisible"
     assert meta_data[
         'do-not-check'] == 1, "Expecting there to be 1 do-not-check"
コード例 #27
0
 def __init__(self, driver, url):
     super(SuperWikipedia, self).__init__(driver, url)
     self.mainpage_link = Link(
         driver, Locator.by_xpath("//li[@id='n-mainpage-description']/a"))
     self.personal_widget = WikipediaPersonal(
         driver, Locator.by_xpath("//div[@id='p-personal']"))
コード例 #28
0
 def __init__(self, driver, locator=None):
     super(MyComplexIframeWithErrorProperty, self).__init__(driver=driver, locator=locator)
     self.regular_element = Element(driver, Locator.by_xpath("//j"))
     self.invisible_element = Element(driver, Locator.by_xpath("//k")).mark_invisible()
     self.not_checked_element = Element(driver, Locator.by_xpath("//l")).mark_do_not_check()
コード例 #29
0
 def __init__(self, driver, locator=None):
     super(MyComplexPanel, self).__init__(driver=driver, locator=locator)
     self.regular_element = Element(driver, Locator.by_xpath("//g"))
     self.invisible_element = Element(driver, Locator.by_xpath("//h")).mark_invisible()
     self.not_checked_element = Element(driver, Locator.by_xpath("//i")).mark_do_not_check()
コード例 #30
0
 def __init__(self, driver, locator=None):
     super(MyComplexWidgetWithErrorProperty, self).__init__(driver=driver, locator=locator)
     self.regular_element_on_widget = Element(driver, Locator.by_xpath("//d"))
     self.invisible_element_on_widget = Element(driver, Locator.by_xpath("//e")).mark_invisible()
     self.not_checked_element_on_widget = Element(driver, Locator.by_xpath("//f")).mark_do_not_check()