Skip to content

Commit 9ad3eda

Browse files
Caos-Maker89aaltat
authored andcommitted
Add new Wait Until Location Contains keyword (robotframework#1293)
robotframework#1108
1 parent 8b5b7ef commit 9ad3eda

File tree

5 files changed

+108
-31
lines changed

5 files changed

+108
-31
lines changed

atest/acceptance/keywords/content_assertions.robot

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,6 @@ Default Tags assertions
55
Resource ../resource.robot
66

77
*** Test Cases ***
8-
Location Should Be
9-
[Documentation] LOG 2:4 Current location is '${FRONT PAGE}'.
10-
Location Should Be ${FRONT PAGE}
11-
Location Should Be ${FRONT PAGE} message=taco
12-
Location Should Be ${FRONT PAGE} message=None
13-
Run Keyword And Expect Error
14-
... Location should have been 'non existing' but was '${FRONT PAGE}'.
15-
... Location Should Be non existing
16-
Run Keyword And Expect Error
17-
... not a url
18-
... Location Should Be non existing message=not a url
19-
Run Keyword And Expect Error
20-
... Location should have been 'non existing' but was 'http://localhost:7000/html/'.
21-
... Location Should Be non existing message=None
22-
23-
Location Should Contain
24-
[Documentation] LOG 2:4 Current location contains 'html'.
25-
Location Should Contain html
26-
Location Should Contain html message=foobar
27-
Location Should Contain html message=None
28-
Run Keyword And Expect Error
29-
... Location should have contained 'not a location' but it was '${FRONT PAGE}'.
30-
... Location Should Contain not a location
31-
Run Keyword And Expect Error
32-
... did not find it
33-
... Location Should Contain not a location message=did not find it
34-
Run Keyword And Expect Error
35-
... Location should have contained 'not a location' but it was 'http://localhost:7000/html/'.
36-
... Location Should Contain not a location message=None
37-
388
Title Should Be
399
[Documentation] LOG 2:4 Page title is '(root)/index.html'.
4010
Title Should Be (root)/index.html
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
*** Settings ***
2+
Test Setup Go To Front Page
3+
Default Tags assertions
4+
Resource ../resource.robot
5+
6+
*** Test Cases ***
7+
Location Should Be
8+
[Documentation] LOG 2:4 Current location is '${FRONT PAGE}'.
9+
Location Should Be ${FRONT PAGE}
10+
Location Should Be ${FRONT PAGE} message=taco
11+
Location Should Be ${FRONT PAGE} message=None
12+
Run Keyword And Expect Error
13+
... Location should have been 'non existing' but was '${FRONT PAGE}'.
14+
... Location Should Be non existing
15+
Run Keyword And Expect Error
16+
... not a url
17+
... Location Should Be non existing message=not a url
18+
Run Keyword And Expect Error
19+
... Location should have been 'non existing' but was 'http://localhost:7000/html/'.
20+
... Location Should Be non existing message=None
21+
22+
Location Should Contain
23+
[Documentation] LOG 2:4 Current location contains 'html'.
24+
Location Should Contain html
25+
Location Should Contain html message=foobar
26+
Location Should Contain html message=None
27+
Run Keyword And Expect Error
28+
... Location should have contained 'not a location' but it was '${FRONT PAGE}'.
29+
... Location Should Contain not a location
30+
Run Keyword And Expect Error
31+
... did not find it
32+
... Location Should Contain not a location message=did not find it
33+
Run Keyword And Expect Error
34+
... Location should have contained 'not a location' but it was 'http://localhost:7000/html/'.
35+
... Location Should Contain not a location message=None
36+
37+
Wait Until Location Contains At The End
38+
[Setup] Go To Page "javascript/wait_location.html"
39+
Click Element button
40+
Wait Until Location Contains html
41+
42+
Wait Until Location Contains In The Middle
43+
[Setup] Go To Page "javascript/wait_location.html"
44+
Click Element button
45+
Wait Until Location Contains 7000
46+
47+
Wait Until Location Contains As Number
48+
[Setup] Go To Page "javascript/wait_location.html"
49+
Click Element button
50+
Wait Until Location Contains ${7000}
51+
52+
Wait Until Location Contains Fails
53+
[Setup] Go To Page "javascript/wait_location.html"
54+
${orig_timeout}= Set Selenium Timeout 2 s
55+
Click Element button
56+
Run Keyword And Expect Error
57+
... Location did not contain 'not_here' in 2 seconds.
58+
... Wait Until Location Contains not_here
59+
Set Selenium Timeout ${orig_timeout}
60+
61+
Wait Until Location Contains Fails With Timeout
62+
[Setup] Go To Page "javascript/wait_location.html"
63+
Click Element button
64+
Run Keyword And Expect Error
65+
... my_message
66+
... Wait Until Location Contains not_here timeout=0.1 message=my_message
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<script type="text/javascript">
4+
function modifyAfterDelay() {
5+
setTimeout('doLocation()', 1000)
6+
}
7+
function doLocation() {
8+
self.location = 'http://localhost:7000/html/'
9+
}
10+
</script>
11+
<head>
12+
<meta charset="UTF-8">
13+
<title>Title</title>
14+
</head>
15+
<body>
16+
<p>Test</p>
17+
<button id="button" onclick="modifyAfterDelay()">OK</button>
18+
19+
</body>
20+
</html>

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def location_should_be(self, url, message=None):
269269
def location_should_contain(self, expected, message=None):
270270
"""Verifies that current URL contains ``expected``.
271271
272-
The ``url`` argument contains the expected value in url.
272+
The ``expected`` argument contains the expected value in url.
273273
274274
The ``message`` argument can be used to override the default error
275275
message.

src/SeleniumLibrary/keywords/waiting.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ def wait_for_condition(self, condition, timeout=None, error=None):
5353
timeout, error
5454
)
5555

56+
@keyword
57+
def wait_until_location_contains(self, expected, timeout=None, message=None):
58+
"""Wait until that current URL contains ``expected``.
59+
60+
The ``expected`` argument contains the expected value in url.
61+
62+
Fails if ``timeout`` expires before the location contains. See
63+
the `Timeouts` section for more information about using timeouts
64+
and their default value.
65+
66+
The ``message`` argument can be used to override the default error
67+
message.
68+
69+
New in SeleniumLibrary 3.4.0
70+
"""
71+
expected = str(expected)
72+
self._wait_until(lambda: expected in self.driver.current_url,
73+
"Location did not contain '%s' in <TIMEOUT>." % expected,
74+
timeout, message)
75+
76+
5677
@keyword
5778
def wait_until_page_contains(self, text, timeout=None, error=None):
5879
"""Waits until ``text`` appears on current page.

0 commit comments

Comments
 (0)