예제 #1
0
 def click_and_wait_for_disappear(self):
     """
     Return True or throw exceptions if element visible after timeout
     """
     self.click()
     is_not_visible = self.wait_for_not_visible()
     if not is_not_visible:
         raise UIException('WebClickable still visible  [{0}:{1}]'.format(self.by, self.value))
예제 #2
0
 def set_and_check(self, text):
     """
     Clear input and set text, throw exception if fails or no elements presented,
     and if input text is not equals to desired
     """
     self.set(text)
     actual_text = self.get_text()
     if text != actual_text:
         raise UIException(
             'WebInput text [{0}] != [{1}] for [{2}:{3}]'.format(
                 text, actual_text, self.by, self.value))
     else:
         return True
    def wait_text_not_empty(self, wait_time=WAIT_TIME):
        """
        Wait text to be not empty, in other case will raise Exception
        """
        start_time = time.time()
        execution_time = 0
        element_text = ""
        while (element_text == "") & (execution_time < wait_time):
            element_text = self.get_text()
            execution_time = time.time() - start_time

        if element_text == "":
            raise UIException("WebElement is still empty [{0}:{1}]".format(
                self.by, self.value))
    def wait_text_not_equal(self, not_expected_text, wait_time=WAIT_TIME):
        """
        Wait text to be not equal provided value, in other case will raise Exception
        """
        start_time = time.time()
        execution_time = 0
        element_text = ""
        while (str(element_text)
               == str(not_expected_text)) & (execution_time < wait_time):
            element_text = self.get_text()
            execution_time = time.time() - start_time

        if str(element_text) == str(not_expected_text):
            raise UIException(
                "WebElement text not changed from [{0}] to [{1}] [{2}:{3}]".
                format(element_text, not_expected_text, self.by, self.value))
 def get_element(self,
                 condition='presence_of_element_located',
                 wait_time=WAIT_TIME):
     """
     When called, driver starts actual search of element on page, normally won't be called directly
     """
     if self._target_element:
         element = self._target_element
         return element
     try:
         element = WebDriverWait(self.driver, wait_time).until(
             getattr(EC, condition)((self.by, self.value)))
         logging.getLogger('ui').info(
             'WebElement with condition [{0}] presented for [{1}:{2}]'.
             format(condition, self.by, self.value))
         return element
     except Exception:
         raise UIException(
             'WebElement with condition [{0}] NOT presented for [{1}:{2}]'.
             format(condition, self.by, self.value))
예제 #6
0
    def wait_for_count_to_be(self,
                             expected_count,
                             condition='presence_of_all_elements_located',
                             wait_time=WebBaseElement.WAIT_TIME):
        elements_presented = len(self._get_elements(condition, wait_time))
        expected_count = int(expected_count)
        start_time = time.time()
        execution_time = 0
        while (expected_count != elements_presented) & (execution_time <
                                                        wait_time):
            elements_presented = len(self._get_elements())
            execution_time = time.time() - start_time
        log_msg = "WebElement array has size[{0}], and expected was [{1}] with condition presented for [{2}:{3}]"

        self.logger.info(
            log_msg.format(elements_presented, expected_count, self.by,
                           self.value))
        if expected_count != elements_presented:
            raise UIException(
                "WebElements count is not equal to expected in array")

        return self.get()
    def wait_css_property_changed_from(self,
                                       property_name,
                                       not_expected_property_value,
                                       wait_time=WAIT_TIME):
        """
        Wait text to be not equal provided value, in other case will raise Exception
        """
        start_time = time.time()
        execution_time = 0
        element_property = self.get_css_property(property_name)
        while (str(element_property) == str(not_expected_property_value)) & (
                execution_time < wait_time):
            element_property = self.get_css_property(property_name)
            execution_time = time.time() - start_time

        if str(element_property) == str(not_expected_property_value):
            raise UIException(
                "WebElement css property [{0}] not changed from [{1}] to [{2}] [{3}:{4}]"
                .format(
                    property_name,
                    element_property,
                    not_expected_property_value,  # noqa: E501
                    self.by,
                    self.value))