Skip to content

Commit 676b207

Browse files
committed
merge with master
2 parents 2844643 + 9336b8c commit 676b207

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Release Notes
33

44
1.7 (unreleased)
55
----------------
6+
<<<<<<< HEAD
67
- Added keyword 'List Windows' to return a list of all window handles.
78
[divfor]
89

@@ -11,6 +12,8 @@ Release Notes
1112
by special locator 'new' (the simplified but less strict way).
1213
[divfor]
1314

15+
=======
16+
>>>>>>> master
1417
- Added new keyword 'Wait Until Page Does Not Contain'.
1518
[deiga]
1619

src/Selenium2Library/keywords/_waiting.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ def wait_until_page_contains(self, text, timeout=None, error=None):
4545
error = "Text '%s' did not appear in <TIMEOUT>" % text
4646
self._wait_until(timeout, error, self._is_text_present, text)
4747

48+
def wait_until_page_does_not_contain(self, text, timeout=None, error=None):
49+
"""Waits until `text` disappears from current page.
50+
51+
Fails if `timeout` expires before the `text` disappears. See
52+
`introduction` for more information about `timeout` and its
53+
default value.
54+
55+
`error` can be used to override the default error message.
56+
57+
See also `Wait Until Page Contains`, `Wait For Condition`,
58+
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
59+
Keyword Succeeds`.
60+
"""
61+
def check_present():
62+
present = self._is_text_present(text)
63+
if not present:
64+
return
65+
else:
66+
return error or "Text '%s' did not disappear in %s" % (text, self._format_timeout(timeout))
67+
self._wait_until_no_error(timeout, check_present)
68+
4869
def wait_until_page_contains_element(self, locator, timeout=None, error=None):
4970
"""Waits until element specified with `locator` appears on current page.
5071
@@ -155,6 +176,52 @@ def check_enabled():
155176

156177
self._wait_until_no_error(timeout, check_enabled)
157178

179+
def wait_until_element_contains(self, locator, text, timeout=None, error=None):
180+
"""Waits until given element contains `text`.
181+
182+
Fails if `timeout` expires before the text appears on given element. See
183+
`introduction` for more information about `timeout` and its
184+
default value.
185+
186+
`error` can be used to override the default error message.
187+
188+
See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`,
189+
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
190+
Keyword Succeeds`.
191+
"""
192+
element = self._element_find(locator, True, True)
193+
def check_text():
194+
actual = element.text
195+
if text in actual:
196+
return
197+
else:
198+
return error or "Text '%s' did not appear in %s to element '%s'. " \
199+
"Its text was '%s'." % (text, self._format_timeout(timeout), locator, actual)
200+
self._wait_until_no_error(timeout, check_text)
201+
202+
203+
def wait_until_element_does_not_contain(self, locator, text, timeout=None, error=None):
204+
"""Waits until given element does not contain `text`.
205+
206+
Fails if `timeout` expires before the text disappears from given element. See
207+
`introduction` for more information about `timeout` and its
208+
default value.
209+
210+
`error` can be used to override the default error message.
211+
212+
See also `Wait Until Page Contains`, `Wait Until Page Contains Element`, `Wait For Condition`,
213+
`Wait Until Element Is Visible` and BuiltIn keyword `Wait Until
214+
Keyword Succeeds`.
215+
"""
216+
element = self._element_find(locator, True, True)
217+
def check_text():
218+
actual = element.text
219+
if not text in actual:
220+
return
221+
else:
222+
return error or "Text '%s' did not disappear in %s from element '%s'." % (text, self._format_timeout(timeout), locator)
223+
self._wait_until_no_error(timeout, check_text)
224+
158225
# Private
159226

160227
def _wait_until(self, timeout, error, function, *args):

test/acceptance/keywords/waiting.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ Wait Until Page Contains
1212
Wait Until Page Contains New Content 2 s
1313
Run Keyword And Expect Error Text 'invalid' did not appear in 100 milliseconds Wait Until Page Contains invalid 0.1
1414

15+
Wait Until Page Does Not Contain
16+
Wait Until Page Does Not Contain This is content 2 s
17+
Run Keyword And Expect Error Text 'Initially hidden' did not disappear in 100 milliseconds Wait Until Page Does Not Contain Initially hidden 0.1
18+
1519
Wait Until Page Contains Element
1620
[Documentation] Tests also that format characters (e.g. %c) are handled correctly in error messages
1721
Wait Until Page Contains Element new div 2 seconds
@@ -34,3 +38,16 @@ Wait Until Element Is Enabled
3438
Run Keyword And Expect Error Element locator 'id=invalid' did not match any elements after 100 milliseconds Wait Until Element Is Enabled id=invalid 0.1
3539
Run Keyword And Expect Error User error message Wait Until Element Is Enabled id=invalid 0.1 User error message
3640

41+
Wait Until Element Contains
42+
Run Keyword And Expect Error Text 'New' did not appear in 100 milliseconds to element 'id=content'. Its text was 'This is content'. Wait Until Element Contains id=content New 0.1
43+
Wait Until Element Contains content New Content 2 s
44+
Wait Until Element Contains content New 2 s
45+
Run Keyword And Expect Error User error message Wait Until Element Contains content Error 0.1 User error message
46+
Run Keyword And Expect Error ValueError: Element locator 'id=invalid' did not match any elements. Wait Until Element Contains id=invalid content 0.1
47+
48+
Wait Until Element Does Not Contain
49+
Run Keyword And Expect Error Text 'This is' did not disappear in 100 milliseconds from element 'id=content'. Wait Until Element Does Not Contain id=content This is 0.1
50+
Wait Until Element Does Not Contain content This is 2 s
51+
Wait Until Element Does Not Contain id=content content 2 s
52+
Run Keyword And Expect Error User error message Wait Until Element Does Not Contain content New Content 0.1 User error message
53+

test/resources/html/javascript/delayed_events.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<div id="content">This is content</div>
4545
<div id="container"></div>
4646
<div id="not_present">Element that should disappear</div>
47-
<div id="hidden" style="display:none;">Inititally hidden content</div>
48-
<button id="disabled" disabled>Inititally disabled content</button>
47+
<div id="hidden" style="display:none;">Initially hidden content</div>
48+
<button id="disabled" disabled>Initially disabled content</button>
4949
</body>
5050
</html>

test/resources/html/jquery.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<head>
33
<title>(root)/links.html</title>
44
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
5-
<script src="http://code.jquery.com/jquery-1.9.1.min.js" type="text/javascript"></script>
5+
<script src="javascript/jquery.js" type="text/javascript"></script>
66
</head>
77
<body>
88
<div id="div_id">
@@ -23,7 +23,7 @@
2323
Link with whitespace
2424
</a><br/>
2525
<a href="target/third.html">
26-
Link with
26+
Link with
2727
whitespace within
2828
</a><br/>
2929
<a href="target/first.html" id="bold_id"><b>Link with bolded text</b></a>

0 commit comments

Comments
 (0)