Skip to content

Commit ac49c0a

Browse files
Zeckieaaltat
authored andcommitted
Handle errors other than Timeout in keyword 'Handle Alert' (robotframework#1501)
Raise the current exception only for TimeoutException and add new except block for WebDriverException. robotframework#1500
1 parent bebc892 commit ac49c0a

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

atest/acceptance/keywords/alerts.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ Alert Should Be Present with custom timeout
120120
... Alert Should Be Present timeout=1ms
121121
Alert Should Be Present Alert after 500ms! ACCEPT 3s
122122

123+
Handle Alert when popup window closes
124+
[Documentation] Popup window is closed by javascript while
125+
... 'Handle Alert' keyword is waiting for alert
126+
... FAIL GLOB: An exception occurred waiting for alert*
127+
[Setup] Go To Page "javascript/self_closing_popup.html"
128+
Click Button Self Closing
129+
${handle} = Switch Window NEW
130+
Handle Alert timeout=10s
131+
[Teardown] Switch Window ${handle}
132+
123133
*** Keywords ***
124134
Wait For Title Change
125135
[Arguments] ${expected}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<html>
2+
<head>
3+
<title>Self Closing Popup</title>
4+
<script type="text/javascript">
5+
function openCloseAfterDelay() {
6+
var popupWindow = window.open("alert.html");
7+
window.setTimeout(function(){
8+
popupWindow.close();
9+
},500);
10+
}
11+
</script>
12+
</head>
13+
<body>
14+
<p>When you click this button, another window / tab will open and automatically close 0.5s later</p>
15+
<button onclick="openCloseAfterDelay()">Self Closing</button>
16+
</body>
17+
</html>

src/SeleniumLibrary/keywords/alert.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from selenium.common.exceptions import WebDriverException
17+
from selenium.common.exceptions import TimeoutException, WebDriverException
1818
from selenium.webdriver.support import expected_conditions as EC
1919
from selenium.webdriver.support.ui import WebDriverWait
2020

@@ -133,6 +133,9 @@ def _wait_alert(self, timeout=None):
133133
wait = WebDriverWait(self.driver, timeout)
134134
try:
135135
return wait.until(EC.alert_is_present())
136-
except WebDriverException:
136+
except TimeoutException:
137137
raise AssertionError('Alert not found in %s.'
138-
% secs_to_timestr(timeout))
138+
% secs_to_timestr(timeout))
139+
except WebDriverException as err:
140+
raise AssertionError('An exception occurred waiting for alert: %s'
141+
% err)

0 commit comments

Comments
 (0)