Skip to content

Commit 85cc369

Browse files
author
GISINC\Nathan.Hannig
committed
add Wait Until keywords for Textarea
Wait Until Textarea Contains - wait_until_textarea_contains Wait Until Textarea Does Not Contains - 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
1 parent 489178c commit 85cc369

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

src/SeleniumLibrary/keywords/waiting.py

+103
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,106 @@ def wait_until_element_does_not_contain(
417417
error,
418418
)
419419

420+
@keyword
421+
def wait_until_textarea_contains(
422+
self,
423+
locator: Union[WebElement, None, str],
424+
text: str,
425+
timeout: Optional[timedelta] = None,
426+
message: Optional[str] = None,
427+
):
428+
"""Waits until the textarea ``locator`` contains ``text``.
429+
430+
Fails if ``timeout`` expires before the text appears. See
431+
the `Timeouts` section for more information about using timeouts and
432+
their default value and the `Locating elements` section for details
433+
about the locator syntax.
434+
435+
The ``message`` argument can be used to override the default error
436+
message.
437+
"""
438+
self._wait_until(
439+
lambda: text in self._get_value(locator, "text area"),
440+
f"Textarea '{locator}' did not get text '{text}' in <TIMEOUT>.",
441+
timeout,
442+
message,
443+
)
444+
445+
@keyword
446+
def wait_until_textarea_does_not_contain(
447+
self,
448+
locator: Union[WebElement, None, str],
449+
text: str,
450+
timeout: Optional[timedelta] = None,
451+
message: Optional[str] = None,
452+
):
453+
"""Waits until the textarea ``locator`` does not contain ``text``.
454+
455+
Fails if ``timeout`` expires before the text disappears. See
456+
the `Timeouts` section for more information about using timeouts and
457+
their default value and the `Locating elements` section for details
458+
about the locator syntax.
459+
460+
The ``message`` argument can be used to override the default error
461+
message.
462+
"""
463+
self._wait_until(
464+
lambda: text not in self._get_value(locator, "text area"),
465+
f"Textarea '{locator}' still had text '{text}' after <TIMEOUT>.",
466+
timeout,
467+
message,
468+
)
469+
470+
@keyword
471+
def wait_until_textarea_value_is(
472+
self,
473+
locator: Union[WebElement, None, str],
474+
text: str,
475+
timeout: Optional[timedelta] = None,
476+
message: Optional[str] = None,
477+
):
478+
"""Waits until the textarea ``locator`` has exactly text ``text``.
479+
480+
Fails if ``timeout`` expires before the text appears. See
481+
the `Timeouts` section for more information about using timeouts and
482+
their default value and the `Locating elements` section for details
483+
about the locator syntax.
484+
485+
The ``message`` argument can be used to override the default error
486+
message.
487+
"""
488+
self._wait_until(
489+
lambda: text == self._get_value(locator, "text area"),
490+
f"Textarea '{locator}' did not get text '{text}' in <TIMEOUT>.",
491+
timeout,
492+
message,
493+
)
494+
495+
@keyword
496+
def wait_until_textarea_value_is_not(
497+
self,
498+
locator: Union[WebElement, None, str],
499+
text: str,
500+
timeout: Optional[timedelta] = None,
501+
message: Optional[str] = None,
502+
):
503+
"""Waits until the textarea ``locator`` does not has exactly text ``text``.
504+
505+
Fails if ``timeout`` expires before the text appears. See
506+
the `Timeouts` section for more information about using timeouts and
507+
their default value and the `Locating elements` section for details
508+
about the locator syntax.
509+
510+
The ``message`` argument can be used to override the default error
511+
message.
512+
"""
513+
self._wait_until(
514+
lambda: text != self._get_value(locator, "text area"),
515+
f"Textarea '{locator}' still had text '{text}' in <TIMEOUT>.",
516+
timeout,
517+
message,
518+
)
519+
420520
def _wait_until(self, condition, error, timeout=None, custom_error=None):
421521
timeout = self.get_timeout(timeout)
422522
if custom_error is None:
@@ -441,3 +541,6 @@ def _wait_until_worker(self, condition, timeout, error):
441541
not_found = None
442542
time.sleep(0.2)
443543
raise AssertionError(not_found or error)
544+
545+
def _get_value(self, locator, tag):
546+
return self.find_element(locator, tag).get_attribute("value")

utest/test/keywords/test_keyword_arguments_waiting.py

+56
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,59 @@ def test_wait_until_page_contains(waiting):
4040
with pytest.raises(AssertionError) as error:
4141
waiting.wait_until_page_contains(text, None, "error")
4242
assert "error" in str(error.value)
43+
44+
45+
def test_wait_until_textarea_contains(waiting):
46+
locator = "//textarea"
47+
element = mock()
48+
when(waiting).find_element(locator, "text area").thenReturn(element)
49+
when(element).get_attribute("value").thenReturn("no")
50+
with pytest.raises(AssertionError) as error:
51+
waiting.wait_until_textarea_contains(locator, "value")
52+
assert "did not get text" in str(error.value)
53+
54+
with pytest.raises(AssertionError) as error:
55+
waiting.wait_until_textarea_contains(locator, "value", None, "foobar error")
56+
assert "foobar error" in str(error.value)
57+
58+
59+
def test_wait_until_textarea_does_not_contain(waiting):
60+
locator = "//textarea"
61+
element = mock()
62+
when(waiting).find_element(locator, "text area").thenReturn(element)
63+
when(element).get_attribute("value").thenReturn("value")
64+
with pytest.raises(AssertionError) as error:
65+
waiting.wait_until_textarea_does_not_contain(locator, "value")
66+
assert "still had text" in str(error.value)
67+
68+
with pytest.raises(AssertionError) as error:
69+
waiting.wait_until_textarea_does_not_contain(locator, "value", None, "foobar error")
70+
assert "foobar error" in str(error.value)
71+
72+
73+
def test_wait_until_textarea_value_is(waiting):
74+
locator = "//textarea"
75+
element = mock()
76+
when(waiting).find_element(locator, "text area").thenReturn(element)
77+
when(element).get_attribute("value").thenReturn("no")
78+
with pytest.raises(AssertionError) as error:
79+
waiting.wait_until_textarea_value_is(locator, "value")
80+
assert "did not get text" in str(error.value)
81+
82+
with pytest.raises(AssertionError) as error:
83+
waiting.wait_until_textarea_value_is(locator, "value", None, "foobar error")
84+
assert "foobar error" in str(error.value)
85+
86+
87+
def test_wait_until_textarea_value_is_not(waiting):
88+
locator = "//textarea"
89+
element = mock()
90+
when(waiting).find_element(locator, "text area").thenReturn(element)
91+
when(element).get_attribute("value").thenReturn("value")
92+
with pytest.raises(AssertionError) as error:
93+
waiting.wait_until_textarea_value_is_not(locator, "value")
94+
assert "still had text" in str(error.value)
95+
96+
with pytest.raises(AssertionError) as error:
97+
waiting.wait_until_textarea_value_is_not(locator, "value", None, "foobar error")
98+
assert "foobar error" in str(error.value)

0 commit comments

Comments
 (0)