20
20
from selenium .common .exceptions import NoSuchWindowException
21
21
from selenium .common .exceptions import WebDriverException
22
22
from selenium .webdriver .common .by import By
23
+ from selenium .webdriver .support import expected_conditions as EC
24
+ from selenium .webdriver .support .ui import WebDriverWait
23
25
24
26
25
27
class WindowSwitchingTests (unittest .TestCase ):
26
28
27
- @pytest .mark .ignore_marionette
28
29
def testShouldSwitchFocusToANewWindowWhenItIsOpenedAndNotStopFutureOperations (self ):
29
30
self ._loadPage ("xhtmlTest" )
30
31
current = self .driver .current_window_handle
@@ -62,7 +63,10 @@ def testShouldThrowNoSuchWindowException(self):
62
63
def testShouldThrowNoSuchWindowExceptionOnAnAttemptToGetItsHandle (self ):
63
64
self ._loadPage ("xhtmlTest" )
64
65
current = self .driver .current_window_handle
66
+ handles = self .driver .window_handles
65
67
self .driver .find_element (By .LINK_TEXT , "Open new window" ).click ()
68
+
69
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
66
70
handles = self .driver .window_handles
67
71
handles .remove (current )
68
72
self .driver .switch_to .window (handles [0 ])
@@ -78,12 +82,13 @@ def testShouldThrowNoSuchWindowExceptionOnAnAttemptToGetItsHandle(self):
78
82
79
83
@pytest .mark .ignore_chrome
80
84
@pytest .mark .ignore_ie
81
- @pytest .mark .ignore_marionette
82
85
def testShouldThrowNoSuchWindowExceptionOnAnyOperationIfAWindowIsClosed (self ):
83
86
self ._loadPage ("xhtmlTest" )
84
87
current = self .driver .current_window_handle
85
-
88
+ handles = self . driver . window_handles
86
89
self .driver .find_element (By .LINK_TEXT , "Open new window" ).click ()
90
+
91
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
87
92
handles = self .driver .window_handles
88
93
handles .remove (current )
89
94
self .driver .switch_to .window (handles [0 ])
@@ -105,12 +110,13 @@ def testShouldThrowNoSuchWindowExceptionOnAnyOperationIfAWindowIsClosed(self):
105
110
106
111
@pytest .mark .ignore_chrome
107
112
@pytest .mark .ignore_ie
108
- @pytest .mark .ignore_marionette
109
113
def testShouldThrowNoSuchWindowExceptionOnAnyElementOperationIfAWindowIsClosed (self ):
110
114
self ._loadPage ("xhtmlTest" )
111
115
current = self .driver .current_window_handle
116
+ handles = self .driver .window_handles
112
117
self .driver .find_element (By .LINK_TEXT , "Open new window" ).click ()
113
118
119
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
114
120
handles = self .driver .window_handles
115
121
handles .remove (current )
116
122
self .driver .switch_to .window (handles [0 ])
@@ -130,10 +136,12 @@ def testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang(self
130
136
self ._loadPage ("xhtmlTest" )
131
137
132
138
current = self .driver .current_window_handle
133
-
139
+ handles = self . driver . window_handles
134
140
self .driver .find_element_by_name ("windowThree" ).click ()
135
141
142
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
136
143
handles = self .driver .window_handles
144
+
137
145
handles .remove (current )
138
146
self .driver .switch_to .window (handles [0 ])
139
147
@@ -148,9 +156,10 @@ def testCanCallGetWindowHandlesAfterClosingAWindow(self):
148
156
self ._loadPage ("xhtmlTest" )
149
157
150
158
current = self .driver .current_window_handle
151
-
159
+ handles = self . driver . window_handles
152
160
self .driver .find_element_by_name ("windowThree" ).click ()
153
161
162
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
154
163
handles = self .driver .window_handles
155
164
handles .remove (current )
156
165
self .driver .switch_to .window (handles [0 ])
@@ -187,9 +196,10 @@ def testThatAccessingFindingAnElementAfterWindowIsClosedAndHaventswitchedDoesntC
187
196
self ._loadPage ("xhtmlTest" )
188
197
189
198
current = self .driver .current_window_handle
190
-
199
+ handles = self . driver . window_handles
191
200
self .driver .find_element_by_name ("windowThree" ).click ()
192
201
202
+ WebDriverWait (self .driver , 3 ).until (EC .new_window_is_opened (handles ))
193
203
handles = self .driver .window_handles
194
204
handles .remove (current )
195
205
self .driver .switch_to .window (handles [0 ])
0 commit comments