Пример #1
0
def element_has_text(
        expected: str,
        describing_matched_to='has text',
        compared_by_predicate_to=predicate.includes) -> Condition[Element]:
    return ElementCondition.raise_if_not_actual(
        describing_matched_to + ' ' + expected, query.text,
        compared_by_predicate_to(expected))
Пример #2
0
def element_has_tag(
        expected: str,
        describing_matched_to='has tag',
        compared_by_predicate_to=predicate.equals) -> Condition[Element]:
    return ElementCondition.raise_if_not_actual(
        f'{describing_matched_to} + {expected}', query.tag,
        compared_by_predicate_to(expected))
Пример #3
0
def element_has_css_class(expected: str) -> Condition[Element]:
    def class_attribute_value(element: Element) -> str:
        return element().get_attribute('class')

    return ElementCondition.raise_if_not_actual(
        f"has css class '{expected}'", class_attribute_value,
        predicate.includes_word(expected))
Пример #4
0
 def value_containing(self, expected: str, ignore_case=False) -> ElementCondition:
     if ignore_case:
         warnings.warn('ignore_case syntax is experimental and might change in future', FutureWarning)
     return ElementCondition.raise_if_not_actual(
         f"has attribute '{name}' with value containing '{expected}'",
         attribute_value,
         predicate.includes(expected, ignore_case))
Пример #5
0
def element_has_attribute(name: str):
    def attribute_value(element: Element) -> str:
        return element().get_attribute(name)

    def attribute_values(collection: Collection) -> List[str]:
        return [element.get_attribute(name) for element in collection()]

    raw_attribute_condition = ElementCondition.raise_if_not_actual(
        'has attribute ' + name, attribute_value, predicate.is_truthy
    )

    class ConditionWithValues(ElementCondition):
        def value(
            self, expected: str, ignore_case=False
        ) -> Condition[Element]:
            if ignore_case:
                warnings.warn(
                    'ignore_case syntax is experimental and might change in future',
                    FutureWarning,
                )
            return ElementCondition.raise_if_not_actual(
                f"has attribute '{name}' with value '{expected}'",
                attribute_value,
                predicate.equals(expected, ignore_case),
            )

        def value_containing(
            self, expected: str, ignore_case=False
        ) -> Condition[Element]:
            if ignore_case:
                warnings.warn(
                    'ignore_case syntax is experimental and might change in future',
                    FutureWarning,
                )
            return ElementCondition.raise_if_not_actual(
                f"has attribute '{name}' with value containing '{expected}'",
                attribute_value,
                predicate.includes(expected, ignore_case),
            )

        def values(self, *expected: str) -> Condition[Collection]:
            return CollectionCondition.raise_if_not_actual(
                f"has attribute '{name}' with values '{expected}'",
                attribute_values,
                predicate.equals_to_list(expected),
            )

        def values_containing(self, *expected: str) -> Condition[Collection]:
            return CollectionCondition.raise_if_not_actual(
                f"has attribute '{name}' with values containing '{expected}'",
                attribute_values,
                predicate.equals_by_contains_to_list(expected),
            )

    return ConditionWithValues(
        str(raw_attribute_condition), raw_attribute_condition.call
    )
Пример #6
0
def element_has_css_property(name: str):
    def property_value(element: Element) -> str:
        return element().value_of_css_property(name)

    def property_values(collection: Collection) -> List[str]:
        return [
            element.value_of_css_property(name) for element in collection()
        ]

    raw_property_condition = ElementCondition.raise_if_not_actual(
        'has css property ' + name, property_value, predicate.is_truthy
    )

    class ConditionWithValues(ElementCondition):
        def value(self, expected: str) -> Condition[Element]:
            return ElementCondition.raise_if_not_actual(
                f"has css property '{name}' with value '{expected}'",
                property_value,
                predicate.equals(expected),
            )

        def value_containing(self, expected: str) -> Condition[Element]:
            return ElementCondition.raise_if_not_actual(
                f"has css property '{name}' with value containing '{expected}'",
                property_value,
                predicate.includes(expected),
            )

        def values(self, *expected: str) -> Condition[Collection]:
            return CollectionCondition.raise_if_not_actual(
                f"has css property '{name}' with values '{expected}'",
                property_values,
                predicate.equals_to_list(expected),
            )

        def values_containing(self, *expected: str) -> Condition[Collection]:
            return CollectionCondition.raise_if_not_actual(
                f"has css property '{name}' with values containing '{expected}'",
                property_values,
                predicate.equals_by_contains_to_list(expected),
            )

    return ConditionWithValues(
        str(raw_property_condition), raw_property_condition.call
    )
Пример #7
0
def element_has_js_property(name: str):  # todo: should we keep simpler but less obvious name - *_has_property ?
    def property_value(element: Element) -> str:
        return element().get_property(name)

    def property_values(collection: Collection) -> List[str]:
        return [element.get_property(name) for element in collection()]

    raw_property_condition = ElementCondition.raise_if_not_actual(
        'has js property ' + name,
        property_value,
        predicate.is_truthy)

    class ConditionWithValues(ElementCondition):

        def value(self, expected: str) -> ElementCondition:
            return ElementCondition.raise_if_not_actual(
                f"has js property '{name}' with value '{expected}'",
                property_value,
                predicate.equals(expected))

        def value_containing(self, expected: str) -> ElementCondition:
            return ElementCondition.raise_if_not_actual(
                f"has js property '{name}' with value containing '{expected}'",
                property_value,
                predicate.includes(expected))

        def values(self, *expected: str) -> CollectionCondition:
            return CollectionCondition.raise_if_not_actual(
                f"has js property '{name}' with values '{expected}'",
                property_values,
                predicate.equals_to_list(expected))

        def values_containing(self, *expected: str) -> CollectionCondition:
            return CollectionCondition.raise_if_not_actual(
                f"has js property '{name}' with values containing '{expected}'",
                property_values,
                predicate.equals_by_contains_to_list(expected))

    return ConditionWithValues(str(raw_property_condition), raw_property_condition.call)
Пример #8
0
 def value_containing(self, expected: str) -> Condition[Element]:
     return ElementCondition.raise_if_not_actual(
         f"has css property '{name}' with value containing '{expected}'",
         property_value,
         predicate.includes(expected),
     )
Пример #9
0
 def value(self, expected: str) -> Condition[Element]:
     return ElementCondition.raise_if_not_actual(
         f"has css property '{name}' with value '{expected}'",
         property_value,
         predicate.equals(expected),
     )