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 two new keyword in waiting.py #1542

Merged
merged 1 commit into from
Feb 3, 2020
Merged
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
81 changes: 80 additions & 1 deletion atest/acceptance/keywords/location.robot
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,83 @@ Wait Until Location Is Fails With Timeout
Click Element button
Run Keyword And Expect Error
... my_message
... Wait Until Location Is not_here timeout=0.1 message=my_message
... Wait Until Location Is not_here timeout=0.1 message=my_message

Wait Until Location Is Not
[Setup] Go To Page "javascript/wait_location.html"
Click Element button
Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html

Wait Until Location Is Not Fail
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
Run Keyword And Expect Error
... Location is 'http://localhost:7000/html/javascript/wait_location.html' in 2 seconds.
... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html
Set Selenium Timeout ${orig_timeout}

Wait Until Location Is Not Fails With Timeout
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
Click Element button
Run Keyword And Expect Error
... Location is 'http://localhost:7000/html/javascript/wait_location.html' in 1 second.
... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html timeout=1 s
Set Selenium Timeout ${orig_timeout}

Wait Until Location Is Not Fails With Message
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
Run Keyword And Expect Error
... my_message
... Wait Until Location Is Not http://localhost:7000/html/javascript/wait_location.html message=my_message
Set Selenium Timeout ${orig_timeout}

Wait Until Location Does Not Contain
[Setup] Go To Page "javascript/wait_location.html"
Click Element button
Wait Until Location Does Not Contain wait_location

Wait Until Location Does Not Contain Fail
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
run keyword and expect error
... Location did contain 'wait_location.html' in 2 seconds.
... Wait Until Location Does Not Contain wait_location.html
Set Selenium Timeout ${orig_timeout}

Wait Until Location Does Not Contain Fail In The Middle
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
run keyword and expect error
... Location did contain 'javascript' in 2 seconds.
... Wait Until Location Does Not Contain javascript
Set Selenium Timeout ${orig_timeout}

Wait Until Location Does Not Contain Fail As Number
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
run keyword and expect error
... Location did contain '${7000}' in 2 seconds.
... Wait Until Location Does Not Contain ${7000}
Set Selenium Timeout ${orig_timeout}

Wait Until Location Does Not Contain Fail At The End
[Setup] Go To Page "javascript/wait_location.html"
${orig_timeout}= Set Selenium Timeout 2 s
run keyword and expect error
... Location did contain '.html' in 2 seconds.
... Wait Until Location Does Not Contain .html
Set Selenium Timeout ${orig_timeout}

Wait Until Location Does Not Contain Fail With Timeout
[Setup] Go To Page "javascript/wait_location.html"
run keyword and expect error
... Location did contain 'wait_location.html' in 1 second.
... Wait Until Location Does Not Contain wait_location.html timeout= 1 s

Wait Until Location Does Not Contain Fail With Message
[Setup] Go To Page "javascript/wait_location.html"
run keyword and expect error
... my_message
... Wait Until Location Does Not Contain wait_location.html message=my_message
38 changes: 38 additions & 0 deletions src/SeleniumLibrary/keywords/waiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@ def wait_until_location_is(self, expected, timeout=None, message=None):
"Location did not is '%s' in <TIMEOUT>." % expected,
timeout, message)

@keyword
def wait_until_location_is_not(self, location, timeout=None, message=None):
"""Waits until the current URL is not ``location``.

The ``location`` argument is the unexpected value in url.

Fails if ``timeout`` expires before the location is not. See
the `Timeouts` section for more information about using timeouts
and their default value.

The ``message`` argument can be used to override the default error
message.

"""
location = str(location)
self._wait_until(lambda: location != self.driver.current_url,
"Location is '%s' in <TIMEOUT>." % location,
timeout, message)

@keyword
def wait_until_location_contains(self, expected, timeout=None, message=None):
"""Waits until the current URL contains ``expected``.
Expand All @@ -94,6 +113,25 @@ def wait_until_location_contains(self, expected, timeout=None, message=None):
"Location did not contain '%s' in <TIMEOUT>." % expected,
timeout, message)

@keyword
def wait_until_location_does_not_contain(self, location, timeout=None, message=None):
"""Waits until the current URL does not contains ``location``.

The ``location`` argument contains value not expected in url.

Fails if ``timeout`` expires before the location not contains. See
the `Timeouts` section for more information about using timeouts
and their default value.

The ``message`` argument can be used to override the default error
message.

"""
location = str(location)
self._wait_until(lambda: location not in self.driver.current_url,
"Location did contain '%s' in <TIMEOUT>." % location,
timeout, message)

@keyword
def wait_until_page_contains(self, text, timeout=None, error=None):
"""Waits until ``text`` appears on the current page.
Expand Down
2 changes: 1 addition & 1 deletion utest/test/api/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUpClass(cls):
def test_no_libraries(self):
for item in [None, 'None', '']:
sl = SeleniumLibrary(plugins=item)
self.assertEqual(len(sl.get_keyword_names()), 173)
self.assertEqual(len(sl.get_keyword_names()), 175)

def test_parse_library(self):
plugin = 'path.to.MyLibrary'
Expand Down