Exemple #1
0
    def click_do_nothing(self,
                         locator_to_click,
                         locator_expectation=None,
                         retries=1,
                         timeout=2,
                         delay=POLL_FREQUENCY):
        """ use this with assert, example:
                assert page.click_do_nothing(locator.ID("dis-button"), timeout=3)

        check if some event(locator_expectation) happened after trying to click.

        :type locator_to_click: tuple(str, str | list[WebElement] | WebElement)
        :type locator_expectation: tuple(str, str | list[WebElement] | WebElement)
        :type retries: int
        :type timeout: float | int
        :type delay: float | int
        :rtype: bool
        """
        if locator_expectation is None:
            locator_expectation = ('css', '*')

        initial_results = len(self.try_to_find_all(locator_expectation))

        for i in range(1 + retries):
            t = time()
            try:
                self.click(locator_to_click, timeout)
                if len(self.find_all(locator_expectation,
                                     timeout)) != initial_results:
                    return False
            except:
                return True
            dynamic_delay(t, delay)
        return True
Exemple #2
0
 def click_until_url_changes(self,
                             locator,
                             retries=5,
                             timeout=2,
                             delay=POLL_FREQUENCY):
     """ click on element, check if url changed, if not, click again
     :type locator: tuple(str, str | list[WebElement] | WebElement)
     :type retries: int
     :type timeout: int
     :type delay: int
     :rtype: list[WebElement]
     """
     url = self.driver.current_url
     for i in range(1 + retries):
         t = time()
         try:
             self.click(locator, timeout)
         except Exception as e:
             if i == retries:
                 raise ClickExpectationException(
                     "url did not change") from e
         if url != self.driver.current_url:
             return
         elif i == retries:
             raise ClickExpectationException("url did not change")
         dynamic_delay(t, delay)
Exemple #3
0
    def confirm_element_is_deleted(self,
                                   locator,
                                   expected_count_results=0,
                                   retries=7,
                                   timeout=2,
                                   delay=POLL_FREQUENCY):
        """ try to find element, confirm element has been deleted with expected_count_results,
        check if element exist... if its not deleted retry!
        return None for success or raise Exception for failure.

        :type locator: tuple(str, str | list[WebElement] | WebElement)
        :type expected_count_results: int
        :type retries: int
        :type timeout: float | int
        :type delay: float | int
        :rtype: bool
        """
        for i in range(1 + retries):
            t = time()
            try:
                if len(self.try_to_find_all(
                        locator, timeout)) <= expected_count_results:
                    return
                elif i == retries:
                    raise ElementPresenceException("element should not exist")
            except Exception as e:
                if i == retries:
                    raise ElementPresenceException(
                        "element should not exist") from e
            dynamic_delay(t, delay)
Exemple #4
0
    def click_until_condition_as_expected(self,
                                          locator_to_click,
                                          locator_condition,
                                          condition_expected_count_results,
                                          retries=7,
                                          timeout=2,
                                          delay=POLL_FREQUENCY):
        """ click on element, check if:
        locator_condition count is equal to condition_expected_count_results, if not, click again.
        return None for success or raise Exception for failure.

        :type locator_to_click: tuple(str, str | list[WebElement] | WebElement)
        :type locator_condition: tuple(str, str | list[WebElement] | WebElement)
        :type condition_expected_count_results: int
        :type retries: int
        :type timeout: float | int
        :type delay: float | int
        :rtype: bool
        """
        for i in range(1 + retries):
            t = time()
            try:
                self.click(locator_to_click, timeout)
                if len(self.try_to_find_all(
                        locator_condition,
                        timeout)) == condition_expected_count_results:
                    return
                elif i == retries:
                    raise ClickExpectationException(
                        "elements count expectation failed")
            except Exception as e:
                if i == retries:
                    raise ClickExpectationException(
                        "elements count expectation failed") from e
            dynamic_delay(t, delay)
Exemple #5
0
    def click_until_element_is_created(self,
                                       locator_to_click,
                                       locator_of_created_element,
                                       retries=7,
                                       timeout=2,
                                       delay=POLL_FREQUENCY):
        """ click on element, check if condition element is created, if not, click again.
        return None for success or raise Exception for failure.

        :type locator_to_click: tuple(str, str | list[WebElement] | WebElement)
        :type locator_of_created_element: tuple(str, str | list[WebElement] | WebElement)
        :type retries: int
        :type timeout: float | int
        :type delay: float | int
        :rtype: bool
        """
        initial_results = len(self.try_to_find_all(locator_of_created_element))

        for i in range(1 + retries):
            t = time()
            try:
                self.click(locator_to_click, timeout)
                if len(
                        self.try_to_find_all(locator_of_created_element,
                                             timeout)) > initial_results:
                    return
                elif i == retries:
                    raise ClickExpectationException("element creation failed")
            except Exception as e:
                if i == retries:
                    raise ClickExpectationException(
                        "element creation failed") from e
            dynamic_delay(t, delay)
Exemple #6
0
    def try_to_click_until_element_is_deleted(self,
                                              locator_to_click,
                                              locator_of_deleted_element=None,
                                              retries=7,
                                              timeout=2,
                                              delay=POLL_FREQUENCY):
        """ try to click on element, check if:
        locator_of_deleted_element has been deleted, if its not deleted retry!
        return None for success or return Exception for failure.

        :type locator_to_click: tuple(str, str | list[WebElement] | WebElement)
        :type locator_of_deleted_element: tuple(str, str | list[WebElement] | WebElement)
        :type retries: int
        :type timeout: float | int
        :type delay: float | int
        :rtype: bool | Exception
        """
        if locator_of_deleted_element is None:
            locator_of_deleted_element = locator_to_click

        initial_results = len(self.try_to_find_all(locator_of_deleted_element))

        for i in range(1 + retries):
            t = time()
            try:
                self.click(locator_to_click, timeout)
                if len(
                        self.try_to_find_all(locator_of_deleted_element,
                                             timeout)) < initial_results:
                    return
                elif i == retries:
                    return ClickExpectationException("element deletion failed")
            except Exception as e:
                if i == retries:
                    return e
            dynamic_delay(t, delay)