예제 #1
0
def element_has_css_class(expected: str) -> Condition[SeleneElement]:
    def class_attribute_value(element: SeleneElement) -> str:
        return element().get_attribute('class')

    return Condition.raise_if_not_actual(f"has css class '{expected}'",
                                         class_attribute_value,
                                         predicate.includes_word(expected))
예제 #2
0
def element_has_attribute(name: str):
    def attribute_value(element: SeleneElement) -> str:
        return element().get_attribute(name)

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

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

    class ConditionWithValues(Condition[SeleneElement]):
        def value(self, expected: str) -> Condition[SeleneElement]:
            return Condition.raise_if_not_actual(
                f"has attribute '{name}' with value '{expected}'",
                attribute_value, predicate.equals(expected))

        def value_containing(self, expected: str) -> Condition[SeleneElement]:
            return Condition.raise_if_not_actual(
                f"has attribute '{name}' with value containing '{expected}'",
                attribute_value, predicate.includes(expected))

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

        def values_containing(
                self, *expected: List[str]) -> Condition[SeleneCollection]:
            return Condition.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)
예제 #3
0
def browser_has_js_returned(expected: Any, script: str,
                            *args) -> Condition[SeleneDriver]:
    def script_result(browser: SeleneDriver):
        return browser().execute_script(script, *args)

    return Condition.raise_if_not_actual(
        f'has the ```{script}``` script returned {expected}', script_result,
        predicate.equals(expected))
예제 #4
0
def browser_has_tabs_number(
        expected: int,
        describing_matched_to='has tabs number',
        compared_by_predicate_to=predicate.equals) -> Condition[SeleneDriver]:
    def tabs_number(browser: SeleneDriver) -> int:
        return len(browser().window_handles)

    return Condition.raise_if_not_actual(f'{describing_matched_to} {expected}',
                                         tabs_number,
                                         compared_by_predicate_to(expected))
예제 #5
0
def browser_has_title(
        expected: str,
        describing_matched_to='has title',
        compared_by_predicate_to=predicate.equals) -> Condition[SeleneDriver]:
    def title(browser: SeleneDriver) -> str:
        return browser().title

    return Condition.raise_if_not_actual(
        f'{describing_matched_to} + {expected}', title,
        compared_by_predicate_to(expected))
예제 #6
0
def browser_has_url(
        expected: str,
        describing_matched_to='has url',
        compared_by_predicate_to=predicate.equals) -> Condition[SeleneDriver]:
    def url(browser: SeleneDriver) -> str:
        return browser().current_url

    return Condition.raise_if_not_actual(
        f'{describing_matched_to} + {expected}', url,
        compared_by_predicate_to(expected))
예제 #7
0
def element_has_text(
        expected: str,
        describing_matched_to='has text',
        compared_by_predicate_to=predicate.includes
) -> Condition[SeleneElement]:
    def text(element: SeleneElement) -> str:
        return element().text

    return Condition.raise_if_not_actual(
        describing_matched_to + ' ' + expected, text,
        compared_by_predicate_to(expected))
예제 #8
0
def collection_has_exact_texts(
        self, *expected: List[str]) -> Condition[SeleneCollection]:
    def visible_texts(collection: SeleneCollection) -> List[str]:
        return [
            webelement.text for webelement in collection()
            if webelement.is_displayed()
        ]

    return Condition.raise_if_not_actual(f'has exact texts {expected}',
                                         visible_texts,
                                         predicate.equals_to_list(expected))
예제 #9
0
def collection_has_size(
        expected: int,
        describing_matched_to='has size',
        compared_by_predicate_to=predicate.equals
) -> Condition[SeleneCollection]:
    def size(collection: SeleneCollection) -> int:
        return len(collection())

    return Condition.raise_if_not_actual(f'{describing_matched_to} {expected}',
                                         size,
                                         compared_by_predicate_to(expected))
예제 #10
0
 def values(self, *expected: List[str]) -> Condition[SeleneCollection]:
     return Condition.raise_if_not_actual(
         f"has attribute '{name}' with values '{expected}'",
         attribute_values, predicate.equals_to_list(expected))
예제 #11
0
 def value_containing(self, expected: str) -> Condition[SeleneElement]:
     return Condition.raise_if_not_actual(
         f"has attribute '{name}' with value containing '{expected}'",
         attribute_value, predicate.includes(expected))
예제 #12
0
 def value(self, expected: str) -> Condition[SeleneElement]:
     return Condition.raise_if_not_actual(
         f"has attribute '{name}' with value '{expected}'",
         attribute_value, predicate.equals(expected))