Skip to content

Commit

Permalink
add Wait Until keywords for Textarea
Browse files Browse the repository at this point in the history
Wait Until Textarea Contains - wait_until_textarea_contains
Wait Until Textarea Does Not Contain - wait_until_textarea_does_not_contain
Wait Until Textarea Value Is - wait_until_textarea_value_is
Wait Until Textarea Value Is Not - wait_until_textarea_value_is_not
  • Loading branch information
GISINC\Nathan.Hannig committed May 6, 2021
1 parent 489178c commit 51ac272
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 0 deletions.
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)

0 comments on commit 51ac272

Please sign in to comment.