Esempio n. 1
0
 def element_should_not_be_enabled(self, locator, timeout=30):
     """
     Assert if the element should not be enabled
     The possible locator could be
     id, xpath, link text, partial link text, name, tag name, class name, css selector
     Example:
     | element should not be enabled | id=kwiws |
     """
     (prefix, criteria) = System.parse_locator(locator)
     if self.is_element_enabled(locator, timeout=timeout):
         message = "Element '%s' is enabled currently." % (
             prefix, criteria).__str__()
         raise AssertionError(message)
Esempio n. 2
0
 def element_should_contain_text(self, locator, expected=None, timeout=30):
     """
     Assert if the element contains expected text
     The possible locator could be
     id, xpath, link text, partial link text, name, tag name, class name, css selector
     Example:
     | element should contain text | id=kw | expectedtext |
     """
     (prefix, criteria) = System.parse_locator(locator)
     actual = self._get_text(locator, timeout=timeout)
     if expected not in actual:
         message = "Element '%s' should have contained text '%s' but " \
                   "its text was '%s'." % ((prefix, criteria), expected, actual)
         raise AssertionError(message)
Esempio n. 3
0
    def _safe_find(self, locator, timeout=30):
        if self._get_platform() == 'ios':
            _locator = normalize('NFD', locator)
        else:
            _locator = locator
        (prefix, criteria) = System.parse_locator(_locator)
        strategy = self._strategies.get(prefix)
        if strategy is None:
            raise ValueError(
                "Element locator with prefix '" + prefix +
                "' is not supported, Please use 'identifier','id','name','xpath','class','class name',"
                "'classname','accessibility_id','android','ios','css',"
                "'ios','css','link','link text','partial link text', 'partial link'"
            )

        start = int(round(time.time() * 1000))
        timeout = robot.utils.timestr_to_secs(
            timeout
        ) if timeout is not None else self.__default_implicit_wait_in_secs
        while timeout * 1000 > int(round(time.time() * 1000)) - start:
            try:
                _driver = self._get_current_browser()
                _driver.implicitly_wait(1)
                element_list = _driver.find_elements(strategy, criteria)
                for element in element_list:
                    if element.is_displayed():
                        _driver.implicitly_wait(
                            self.__default_implicit_wait_in_secs)
                        # print "debug time taken for safe_find is %s millisecond for element %s" % (
                        # int(round(time.time() * 1000)) - start, (by, value).__str__())
                        return element
            except:
                pass
            finally:
                _driver.implicitly_wait(self.__default_implicit_wait_in_secs)
                # print "debug time taken for safe_find is %s millisecond" % (int(round(time.time() * 1000)) - start)
        raise RuntimeError("Could not find element %s within %s millisecond." %
                           ((strategy, criteria).__str__(),
                            int(round(time.time() * 1000)) - start))
Esempio n. 4
0
    def _safe_finds(self, locator, timeout=30):
        if self._get_platform() == 'ios':
            _locator = normalize('NFD', locator)
        else:
            _locator = locator
        (prefix, criteria) = System.parse_locator(_locator)
        strategy = self._strategies.get(prefix)
        if strategy is None:
            raise ValueError(
                "Element locator with prefix '" + prefix +
                "' is not supported, Please use 'identifier','id','name','xpath','class',"
                "'class name','classname','accessibility_id','accessibility id','android',"
                "'ios','css','link','link text','partial link text', 'partial link'"
            )

        start = int(round(time.time() * 1000))
        timeout = robot.utils.timestr_to_secs(
            timeout
        ) if timeout is not None else self.__default_implicit_wait_in_secs
        _driver = self._get_current_browser()
        while timeout * 1000 > int(round(time.time() * 1000)) - start:
            try:
                try:
                    _driver.implicitly_wait(5)
                    WebDriverWait(_driver, 1, poll_frequency=0.1)\
                        .until(ec.visibility_of_any_elements_located(locator=(strategy, criteria)))
                except:
                    pass
                return _driver.find_elements(strategy, criteria)
            except:
                pass
            finally:
                _driver.implicitly_wait(self.__default_implicit_wait_in_secs)
        raise RuntimeError("Could not find element %s within %s millisecond." %
                           ((strategy, criteria).__str__(),
                            int(round(time.time() * 1000)) - start))