コード例 #1
0
ファイル: match.py プロジェクト: vfalco02/selene
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
ファイル: match.py プロジェクト: vfalco02/selene
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
ファイル: match.py プロジェクト: vfalco02/selene
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 have_produced_todos(number: int) -> Condition[Element]:
    def fn(entity: Element) -> None:
        size = len(browser.all("#todo-list>li"))
        produced_enough = size >= number
        if not produced_enough:
            entity.type('one more').press_enter()
            raise AssertionError(f'actual produced todos were: {size}')

    return ElementCondition(f'have produced {number} todos', fn)
コード例 #7
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
    )
コード例 #8
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)
コード例 #9
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),
     )
コード例 #10
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),
     )
コード例 #11
0
import warnings
from typing import List, Any

from selene.common import predicate
from selene.core import query
from selene.core.condition import Condition
from selene.core.conditions import (
    ElementCondition,
    CollectionCondition,
    BrowserCondition,
)
from selene.core.entity import Collection, Element, Browser

# todo: consider moving to selene.match.element.is_visible, etc...
element_is_visible: Condition[Element] = ElementCondition.raise_if_not(
    'is visible', lambda element: element().is_displayed()
)

element_is_hidden: Condition[Element] = ElementCondition.as_not(
    element_is_visible, 'is hidden'
)

element_is_enabled: Condition[Element] = ElementCondition.raise_if_not(
    'is enabled', lambda element: element().is_enabled()
)

element_is_disabled: Condition[Element] = ElementCondition.as_not(
    element_is_enabled
)

element_is_clickable: Condition[Element] = element_is_visible.and_(