Example #1
0
 def test_two_buttons_are_not_equal_by_value(self):
     xpath = "//foo"
     xpath2 = "//foo/bar"
     button1 = Button(self.driver, Locator(By.XPATH, xpath))
     button2 = Button(self.driver, Locator(By.XPATH, xpath2))
     assert button1 != button2
     assert not (button1 == button2)
Example #2
0
 def test_two_table_are_not_equal_by_value(self):
     xpath = "//table"
     xpath2 = "//table/bar"
     table1 = Table(self.driver, Locator(By.XPATH, xpath))
     table2 = Table(self.driver, Locator(By.XPATH, xpath2))
     assert table1 != table2
     assert not (table1 == table2)
 def test_two_elements_are_not_equal_by_value(self):
     xpath = "//foo"
     xpath2 = "//foo/bar"
     element1 = Element(self.driver, Locator(By.XPATH, xpath))
     element2 = Element(self.driver, Locator(By.XPATH, xpath2))
     assert element1 != element2
     assert not (element1 == element2)
 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()
Example #5
0
 def test_two_locators_are_the_same(self):
     """
     Make sure equivalence check between two locators that are the same
     :return:
     """
     xpath = "//div/foobar"
     locator1 = Locator(By.XPATH, xpath)
     locator2 = Locator(By.XPATH, xpath)
     assert locator1 == locator2
     assert not (locator1 != locator2)
Example #6
0
 def test_two_locators_are_the_not_same_by_by(self):
     """
     Make sure equivalence check between two locators with the same value but different By
     :return:
     """
     xpath = "//div/foobar"
     locator1 = Locator(By.XPATH, xpath)
     locator2 = Locator(By.CLASS_NAME, xpath)
     assert locator1 != locator2
     assert not (locator1 == locator2)
 def __init__(self, driver, locator):
     super(WikipediaPersonal, self).__init__(driver, locator)
     self.talk_link = Link(driver,
                           Locator(By.XPATH, "//li[@id='pt-anontalk']/a"))
     self.contributions_link = Link(
         driver, Locator(By.XPATH, "//li[@id='pt-anoncontribs']/a"))
     self.createaccount_link = Link(
         driver, Locator(By.XPATH, "//li[@id='pt-createaccount']/a"))
     self.login_link = Link(driver,
                            Locator(By.XPATH, "//li[@id='pt-login']/a"))
Example #8
0
 def test_two_locators_are_the_not_same_by_value(self):
     """
     Make sure equivalence check between two locators with the same By but different value
     :return:
     """
     xpath1 = "//div/foobar"
     xpath2 = "//div/foobar/what"
     locator1 = Locator(By.XPATH, xpath1)
     locator2 = Locator(By.XPATH, xpath2)
     assert locator1 != locator2
     assert not (locator1 == locator2)
Example #9
0
 def test_locator_append(self):
     """
     Tests that locator.append(str) successfully modifies the locator.value
     :return:
     """
     xpath = "//div/foobar"
     locator = Locator(By.XPATH, xpath)
     assert locator != None
     assert locator.by == By.XPATH
     assert locator.value == xpath
     locator.append("/helloworld")
     assert locator.value == "{}{}".format(xpath, "/helloworld")
Example #10
0
 def test_get_locator(self):
     xpath = "//table"
     table = Table(self.driver, Locator(By.XPATH, xpath))
     # Get 2nd row 4th column
     assert table.get_locator(1, 3) == Locator(
         By.XPATH, "{}{}".format(xpath, "/tbody/tr[1]/td[3]"))
     # Get 1st row 2nd column
     assert table.get_locator(0, 1) == Locator(
         By.XPATH, "{}{}".format(xpath, "/tbody/tr[0]/td[1]"))
     # Get 30th row 5th column
     assert table.get_locator(29, 4) == Locator(
         By.XPATH, "{}{}".format(xpath, "/tbody/tr[29]/td[4]"))
    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()
 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
Example #13
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
Example #14
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
    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
    def test_get_number_by_index(self, string, index, expected):
        xpath = "//foo"
        element = Element(self.driver, Locator(By.XPATH, xpath))

        actual = element.get_number(string, result_index=index)
        assert actual == expected, "Expecting '{}' to convert to {} - actual: {}".format(
            string, expected, actual)
 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"
Example #18
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()
 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
Example #20
0
 def test_widget(self):
     """Widget --> Clickable --> Element --> object"""
     widget = Widget(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(widget, Widget)
     assert isinstance(widget, Clickable)
     assert isinstance(widget, Element)
     assert isinstance(widget, object)
Example #21
0
 def test_error_if_specify_table_with_non_xpath_locator(self):
     xpath = "//table"
     try:
         Table(self.driver, Locator(By.CLASS_NAME, xpath))
         assert False, "Expected there to be an AttributeError"
     except AttributeError:
         pass
Example #22
0
 def test_link(self):
     """Link --> Clickable --> Element --> object"""
     link = Link(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(link, Link)
     assert isinstance(link, Clickable)
     assert isinstance(link, Element)
     assert isinstance(link, object)
Example #23
0
 def test_textfield(self):
     """TextField --> TextElement --> Element --> object"""
     textfield = TextField(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(textfield, TextField)
     assert isinstance(textfield, TextElement)
     assert isinstance(textfield, Element)
     assert isinstance(textfield, object)
Example #24
0
 def test_dropdown(self):
     """Dropdown --> Clickable --> Element --> object"""
     dropdown = Dropdown(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(dropdown, Dropdown)
     assert isinstance(dropdown, Clickable)
     assert isinstance(dropdown, Element)
     assert isinstance(dropdown, object)
Example #25
0
 def test_checkbox(self):
     """Checkbox --> Clickable --> Element --> object"""
     checkbox = Checkbox(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(checkbox, Checkbox)
     assert isinstance(checkbox, Clickable)
     assert isinstance(checkbox, Element)
     assert isinstance(checkbox, object)
Example #26
0
 def test_button(self):
     """Button --> Element --> object"""
     button = Button(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(button, Button)
     assert isinstance(button, Clickable)
     assert isinstance(button, Element)
     assert isinstance(button, object)
Example #27
0
    def test_locator_copy(self):
        """
        Tests that we can make a copy of the Locator object and make changes without affecting the other
        :return:
        """
        xpath = "//div/foobar"
        locator1 = Locator(By.XPATH, xpath)
        locator2 = locator1.copy()
        assert locator1 == locator2

        # Change locator2 value
        locator2.value += "/test"
        assert locator1.by == By.XPATH
        assert locator1.value == xpath
        assert locator2.by == By.XPATH
        assert locator2.value == "{}/{}".format(xpath, "test")
        assert locator1 != locator2
Example #28
0
 def test_panel(self):
     """Panel --> Widget --> Clickable --> Element --> object"""
     panel = Panel(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(panel, Panel)
     assert isinstance(panel, Widget)
     assert isinstance(panel, Clickable)
     assert isinstance(panel, Element)
     assert isinstance(panel, object)
Example #29
0
    def test_two_locators_can_be_modified_independently(self):
        """
        Make sure two locators can be created and modified independent of one another
        :return:
        """
        xpath = "//div/foobar"
        locator1 = Locator(By.XPATH, xpath)
        locator2 = Locator(By.XPATH, xpath)
        assert locator1 == locator2
        assert not (locator1 != locator2)

        # Change locator2 value
        locator2.value += "/test"
        assert locator1.by == By.XPATH
        assert locator1.value == xpath
        assert locator2.by == By.XPATH
        assert locator2.value == "{}/{}".format(xpath, "test")
        assert locator1 != locator2
Example #30
0
 def test_iframe(self):
     """IFrame --> Panel --> Widget --> Clickable --> Element --> object"""
     iframe = IFrame(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(iframe, IFrame)
     assert isinstance(iframe, Panel)
     assert isinstance(iframe, Widget)
     assert isinstance(iframe, Clickable)
     assert isinstance(iframe, Element)
     assert isinstance(iframe, object)