Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wait Until keywords for Textarea #1727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions src/SeleniumLibrary/keywords/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,106 @@ def wait_until_element_does_not_contain(
error,
)

@keyword
def wait_until_textarea_contains(
self,
locator: Union[WebElement, None, str],
text: str,
timeout: Optional[timedelta] = None,
message: Optional[str] = None,
):
"""Waits until the textarea ``locator`` contains ``text``.

Fails if ``timeout`` expires before the text appears. See
the `Timeouts` section for more information about using timeouts and
their default value and the `Locating elements` section for details
about the locator syntax.

The ``message`` argument can be used to override the default error
message.
"""
self._wait_until(
lambda: text in self._get_value(locator, "text area"),
f"Textarea '{locator}' did not get text '{text}' in <TIMEOUT>.",
timeout,
message,
)

@keyword
def wait_until_textarea_does_not_contain(
self,
locator: Union[WebElement, None, str],
text: str,
timeout: Optional[timedelta] = None,
message: Optional[str] = None,
):
"""Waits until the textarea ``locator`` does not contain ``text``.

Fails if ``timeout`` expires before the text disappears. See
the `Timeouts` section for more information about using timeouts and
their default value and the `Locating elements` section for details
about the locator syntax.

The ``message`` argument can be used to override the default error
message.
"""
self._wait_until(
lambda: text not in self._get_value(locator, "text area"),
f"Textarea '{locator}' still had text '{text}' after <TIMEOUT>.",
timeout,
message,
)

@keyword
def wait_until_textarea_value_is(
self,
locator: Union[WebElement, None, str],
text: str,
timeout: Optional[timedelta] = None,
message: Optional[str] = None,
):
"""Waits until the textarea ``locator`` has exactly text ``text``.

Fails if ``timeout`` expires before the text appears. See
the `Timeouts` section for more information about using timeouts and
their default value and the `Locating elements` section for details
about the locator syntax.

The ``message`` argument can be used to override the default error
message.
"""
self._wait_until(
lambda: text == self._get_value(locator, "text area"),
f"Textarea '{locator}' did not get text '{text}' in <TIMEOUT>.",
timeout,
message,
)

@keyword
def wait_until_textarea_value_is_not(
self,
locator: Union[WebElement, None, str],
text: str,
timeout: Optional[timedelta] = None,
message: Optional[str] = None,
):
"""Waits until the textarea ``locator`` does not has exactly text ``text``.

Fails if ``timeout`` expires before the text appears. See
the `Timeouts` section for more information about using timeouts and
their default value and the `Locating elements` section for details
about the locator syntax.

The ``message`` argument can be used to override the default error
message.
"""
self._wait_until(
lambda: text != self._get_value(locator, "text area"),
f"Textarea '{locator}' still had text '{text}' in <TIMEOUT>.",
timeout,
message,
)

def _wait_until(self, condition, error, timeout=None, custom_error=None):
timeout = self.get_timeout(timeout)
if custom_error is None:
Expand All @@ -441,3 +541,6 @@ def _wait_until_worker(self, condition, timeout, error):
not_found = None
time.sleep(0.2)
raise AssertionError(not_found or error)

def _get_value(self, locator, tag):
return self.find_element(locator, tag).get_attribute("value")
56 changes: 56 additions & 0 deletions utest/test/keywords/test_keyword_arguments_waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,59 @@ def test_wait_until_page_contains(waiting):
with pytest.raises(AssertionError) as error:
waiting.wait_until_page_contains(text, None, "error")
assert "error" in str(error.value)


def test_wait_until_textarea_contains(waiting):
locator = "//textarea"
element = mock()
when(waiting).find_element(locator, "text area").thenReturn(element)
when(element).get_attribute("value").thenReturn("no")
with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_contains(locator, "value")
assert "did not get text" in str(error.value)

with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_contains(locator, "value", None, "foobar error")
assert "foobar error" in str(error.value)


def test_wait_until_textarea_does_not_contain(waiting):
locator = "//textarea"
element = mock()
when(waiting).find_element(locator, "text area").thenReturn(element)
when(element).get_attribute("value").thenReturn("value")
with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_does_not_contain(locator, "value")
assert "still had text" in str(error.value)

with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_does_not_contain(locator, "value", None, "foobar error")
assert "foobar error" in str(error.value)


def test_wait_until_textarea_value_is(waiting):
locator = "//textarea"
element = mock()
when(waiting).find_element(locator, "text area").thenReturn(element)
when(element).get_attribute("value").thenReturn("no")
with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_value_is(locator, "value")
assert "did not get text" in str(error.value)

with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_value_is(locator, "value", None, "foobar error")
assert "foobar error" in str(error.value)


def test_wait_until_textarea_value_is_not(waiting):
locator = "//textarea"
element = mock()
when(waiting).find_element(locator, "text area").thenReturn(element)
when(element).get_attribute("value").thenReturn("value")
with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_value_is_not(locator, "value")
assert "still had text" in str(error.value)

with pytest.raises(AssertionError) as error:
waiting.wait_until_textarea_value_is_not(locator, "value", None, "foobar error")
assert "foobar error" in str(error.value)