示例#1
0
    def __init__(self, expected_title, exact=False, wait=None):
        self.expected_title = (expected_title if isregex(expected_title) else
                               normalize_text(expected_title))
        self.actual_title = None
        self.search_regexp = toregex(expected_title, exact=exact)

        self.options = {"wait": wait}
示例#2
0
    def __init__(self, query_type, expected_text=None, between=None, count=None, exact_text=False,
                 maximum=None, minimum=None, wait=None):
        if expected_text is None:
            expected_text = query_type
            query_type = None

        if query_type is None:
            query_type = ("visible" if capybara.ignore_hidden_elements or capybara.visible_text_only
                          else "all")

        assert query_type in VALID_QUERY_TYPE, \
            "invalid option {query_type} for query_type, should be one of {valid_values}".format(
                query_type=desc(query_type),
                valid_values=", ".join(desc(VALID_QUERY_TYPE)))

        self.expected_text = (expected_text if isregex(expected_text)
                              else normalize_text(expected_text))
        self.query_type = query_type
        self.search_regexp = toregex(expected_text, exact=exact_text)
        self.options = {
            "between": between,
            "count": count,
            "exact_text": exact_text,
            "maximum": maximum,
            "minimum": minimum,
            "wait": wait}
        self.node = None
        self.actual_text = None
        self.count = None
示例#3
0
    def matches_filters(self, node):
        """
        Returns whether the given node matches all filters.

        Args:
            node (Element): The node to evaluate.

        Returns:
            bool: Whether the given node matches.
        """

        visible = self.visible

        if self.options["text"]:
            if isregex(self.options["text"]):
                regex = self.options["text"]
            elif self.exact_text is True:
                regex = re.compile(r"\A{}\Z".format(
                    re.escape(self.options["text"])))
            else:
                regex = toregex(self.options["text"])

            text = normalize_text(node.all_text if visible ==
                                  "all" else node.visible_text)

            if not regex.search(text):
                return False

        if isinstance(self.exact_text, (bytes_, str_)):
            regex = re.compile(r"\A{}\Z".format(re.escape(self.exact_text)))

            text = normalize_text(node.all_text if visible ==
                                  "all" else node.visible_text)

            if not regex.search(text):
                return False

        if visible == "visible":
            if not node.visible:
                return False
        elif visible == "hidden":
            if node.visible:
                return False

        for name, query_filter in iter(self._query_filters.items()):
            if name in self.filter_options:
                if not query_filter.matches(node, self.filter_options[name]):
                    return False
            elif query_filter.has_default:
                if not query_filter.matches(node, query_filter.default):
                    return False

        if self.options["filter"] and not self.options["filter"](node):
            return False

        return True
 def _find_modal(self, text=None, wait=None):
     wait = wait or capybara.default_max_wait_time
     try:
         alert = WebDriverWait(self.browser, wait).until(EC.alert_is_present())
         regexp = toregex(text)
         if not regexp.search(alert.text):
             qualifier = "matching" if isregex(text) else "with"
             raise ModalNotFound("Unable to find modal dialog {0} {1}".format(qualifier, desc(text)))
         return alert
     except TimeoutException:
         raise ModalNotFound("Unable to find modal dialog")
示例#5
0
    def resolves_for(self, node):
        """
        Resolves this query relative to the given node.

        Args:
            node (node.Base): The node to be evaluated.

        Returns:
            int: The number of matches found.
        """

        self.node = node
        self.actual_styles = node.style(*self.expected_styles.keys())

        return all(
            toregex(value).search(self.actual_styles[style])
            for style, value in iter(self.expected_styles.items()))
示例#6
0
    def matches_filters(self, node):
        """
        Returns whether the given node matches all filters.

        Args:
            node (Element): The node to evaluate.

        Returns:
            bool: Whether the given node matches.
        """

        visible = self.visible

        if self.options["text"]:
            regex = toregex(self.options["text"])
            text = normalize_text(node.all_text if visible ==
                                  "all" else node.visible_text)

            if not regex.search(text):
                return False

        if visible == "visible":
            if not node.visible:
                return False
        elif visible == "hidden":
            if node.visible:
                return False

        for name, query_filter in iter(self._query_filters.items()):
            if name in self.filter_options:
                if not query_filter.matches(node, self.filter_options[name]):
                    return False
            elif query_filter.has_default:
                if not query_filter.matches(node, query_filter.default):
                    return False
        return True
示例#7
0
 def __init__(self, expected_title):
     self.expected_title = (expected_title if isregex(expected_title) else
                            normalize_text(expected_title))
     self.actual_title = None
     self.search_regexp = toregex(expected_title)