Exemplo n.º 1
0
 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 test_start_stop_timer(self):
     element = Element(self.driver, None)
     element_start_time = element.start_timer(type="element")
     time.sleep(0.5)
     element_end_time = element.stop_timer(type="element")
     duration = element.get_duration(type="element")
     self.timer_assertions(element_start_time, element_end_time, duration)
 def test_start_stop_timer(self):
     element = Element(self.driver, None)
     start_time = element.start_timer()
     time.sleep(0.5)
     end_time = element.stop_timer()
     duration = element.get_duration()
     self.timer_assertions(start_time, end_time, duration)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
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_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"
Exemplo n.º 7
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()
Exemplo n.º 8
0
 def test_ensure_element_requires_selenium_driver_without_Webdriver(self):
     """
     This test should raise an exception
     """
     try:
         Element(driver=MyDriver(driver=self.driver), locator=None)
         assert False, "Expecting Element to raise an AttributeError!"
     except AttributeError:
         pass
Exemplo n.º 9
0
 def test_disable_require_webdriver_without_webdriver(self):
     """
     This test is making sure that it does not matter if driver is a Webdriver or not
     """
     try:
         seleniumconfig.disable_check_for_selenium_webdriver = True
         Element(driver=MyDriver(driver=self.driver), locator=None)
     finally:
         seleniumconfig.disable_check_for_selenium_webdriver = False
Exemplo n.º 10
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"
 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)
 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"
Exemplo n.º 13
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()
 def test_get_split_after_reset_timer(self):
     element = Element(self.driver, None)
     start_time = element.start_timer()
     assert hasattr(self.driver, "start_time")
     assert self.driver.start_time == start_time, "Expecting the start_time = {} - actual: {}".format(
         start_time, self.driver.start_time)
     element.reset_timer()
     split_time = element.get_split_time()
     assert split_time == 0, "Expecting the split time to be 0 if I haven't started a timer"
    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"
    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
 def test_start_stop_split_timer(self):
     element = Element(self.driver, None)
     start_time = element.start_timer()
     time.sleep(0.5)
     split_time = element.get_split_time()
     assert split_time > 0
     assert not hasattr(self.driver, "end_time") or self.driver.end_time == 0
     time.sleep(0.5)
     split_time = element.get_split_time()
     assert not hasattr(self.driver, "end_time") or self.driver.end_time == 0
     assert split_time > 0
     time.sleep(0.5)
     end_time = element.stop_timer()
     duration = element.get_duration()
     assert duration > split_time
     self.timer_assertions(start_time, end_time, duration)
 def test_start_get_duration_multiple_times_timer(self):
     element = Element(self.driver, None)
     start_time = element.start_timer()
     time.sleep(0.5)
     duration = element.get_duration()
     end_time = self.driver.end_time
     time.sleep(0.5)
     actual_duration = element.get_duration()
     assert str(actual_duration) == str(duration), "Expecting duration to be the same - actual: {} - expected: {}".format(
         actual_duration, duration)
     time.sleep(0.5)
     actual_duration = element.get_duration()
     assert str(actual_duration) == str(duration), "Expecting duration to be the same - actual: {} - expected: {}".format(
         actual_duration, duration)
     self.timer_assertions(start_time, end_time, duration)
 def __init__(self, driver, url=None):
     super(MyComplexPageWithErrorProperty, self).__init__(driver=driver, url=url)
     self.regular_element = Element(driver, Locator.by_xpath("//a"))
     self.invisible_element = Element(driver, Locator.by_xpath("//b")).mark_invisible()
     self.not_checked_element = Element(driver, Locator.by_xpath("//c")).mark_do_not_check()
 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()
 def test_get_split_timer(self):
     element = Element(self.driver, None)
     split_time = element.get_split_time()
     assert split_time == 0, "Expecting the split time to be 0 if I haven't started a timer"
 def test_start_timer(self):
     element = Element(self.driver, None)
     start_time = element.start_timer()
     assert hasattr(self.driver, "start_time")
     assert self.driver.start_time == start_time, "Expecting the start_time = {} - actual: {}".format(
         start_time, self.driver.start_time)
 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()
 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()
Exemplo n.º 25
0
 def test_ensure_element_requires_selenium_driver_with_Webdriver(self):
     """
     This test should not raise an exception
     """
     Element(driver=self.driver, locator=None)
 def test_element_start_timer(self):
     element = Element(self.driver, None)
     element_start_time = element.start_timer(type="element")
     assert hasattr(self.driver, "element_start_time")
     assert self.driver.element_start_time == element_start_time, "Expecting the element_start_time = {} - actual: {}".format(
         element_start_time, self.driver.element_start_time)
Exemplo n.º 27
0
 def test_define_element_with_no_locator(self):
     element = Element(self.driver, locator=None)
     assert isinstance(element, Element)
     assert element.locator is None
Exemplo n.º 28
0
 def test_instantiate_element(self):
     xpath = "//foo"
     element = Element(self.driver, Locator(By.XPATH, xpath))
     assert element != None
Exemplo n.º 29
0
 def test_element(self):
     """Element --> object"""
     element = Element(self.driver, Locator(By.XPATH, "//foo"))
     assert isinstance(element, Element)
     assert isinstance(element, object)
Exemplo n.º 30
0
 def test_two_elements_are_not_equal_by_by(self):
     xpath = "//foo"
     element1 = Element(self.driver, Locator(By.XPATH, xpath))
     element2 = Element(self.driver, Locator(By.CLASS_NAME, xpath))
     assert element1 != element2
     assert not (element1 == element2)