@@ -110,51 +110,6 @@ def test_device_preview_keyboard_shortcuts(self):
110110 actions .send_keys (Keys .ESCAPE ).perform ()
111111 self .wait_for_invisibility (By .CSS_SELECTOR , '.djnjc-overlay:not(.loading)' )
112112
113- def test_unsaved_changes (self ):
114- """
115- Execute this test using Chrome instead of Firefox.
116-
117- Firefox automatically accepts the beforeunload alert, which makes it
118- impossible to test the unsaved changes alert.
119- """
120- self .login ()
121- device = self ._create_config (organization = self ._get_org ()).device
122- path = reverse ('admin:config_device_change' , args = [device .id ])
123- self .open (path )
124- with self .subTest ('Alert should not be displayed without any change' ):
125- self .open (path )
126- try :
127- WebDriverWait (self .web_driver , 1 ).until (EC .alert_is_present ())
128- except TimeoutException :
129- pass
130- else :
131- self .fail ('Unsaved changes alert displayed without any change' )
132-
133- with self .subTest ('Alert should be displayed after making changes' ):
134- # The WebDriver automatically accepts the
135- # beforeunload confirmation dialog. To verify the message,
136- # we log it to the console and check its content.
137- self .web_driver .execute_script (
138- 'django.jQuery(window).on("beforeunload", function(e) {'
139- ' console.warn(e.returnValue); });'
140- )
141- # simulate hand gestures
142- self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
143- self .find_element (by = By .NAME , value = 'name' ).click ()
144- # set name
145- self .find_element (by = By .NAME , value = 'name' ).send_keys ('new.device.name' )
146- # simulate hand gestures
147- self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
148- self .web_driver .refresh ()
149- for entry in self .get_browser_logs ():
150- if (
151- entry ['level' ] == 'WARNING'
152- and "You haven\' t saved your changes yet!" in entry ['message' ]
153- ):
154- break
155- else :
156- self .fail ('Unsaved changes code was not executed.' )
157-
158113 def test_multiple_organization_templates (self ):
159114 shared_required_template = self ._create_template (
160115 name = 'shared required' , organization = None
@@ -325,6 +280,53 @@ def test_force_delete_multiple_devices_with_deactivating_config(self):
325280 self .assertEqual (Device .objects .count (), 0 )
326281
327282
283+ @tag ('selenium_tests' )
284+ class TestDeviceAdminUnsavedChanges (
285+ DeviceAdminSeleniumTextMixin ,
286+ CreateConfigTemplateMixin ,
287+ StaticLiveServerTestCase ,
288+ ):
289+ browser = 'chrome'
290+
291+ def test_unsaved_changes (self ):
292+ """
293+ Execute this test using Chrome instead of Firefox.
294+
295+ Firefox automatically accepts the beforeunload alert, which makes it
296+ impossible to test the unsaved changes alert.
297+ """
298+ self .login ()
299+ device = self ._create_config (organization = self ._get_org ()).device
300+ path = reverse ('admin:config_device_change' , args = [device .id ])
301+ self .open (path )
302+ with self .subTest ('Alert should not be displayed without any change' ):
303+ self .open (path )
304+ try :
305+ WebDriverWait (self .web_driver , 1 ).until (EC .alert_is_present ())
306+ except TimeoutException :
307+ pass
308+ else :
309+ self .fail ('Unsaved changes alert displayed without any change' )
310+
311+ with self .subTest ('Alert should be displayed after making changes' ):
312+ # simulate hand gestures
313+ self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
314+ self .find_element (by = By .NAME , value = 'name' ).click ()
315+ # set name
316+ self .find_element (by = By .NAME , value = 'name' ).send_keys ('new.device.name' )
317+ # simulate hand gestures
318+ self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
319+ self .web_driver .refresh ()
320+ try :
321+ WebDriverWait (self .web_driver , 5 ).until (EC .alert_is_present ())
322+ except TimeoutException :
323+ for entry in self .get_browser_logs ():
324+ print (entry )
325+ self .fail ('Timed out wating for unsaved changes alert' )
326+ else :
327+ self .web_driver .switch_to .alert .accept ()
328+
329+
328330@tag ('selenium_tests' )
329331class TestVpnAdmin (
330332 SeleniumTestMixin ,
0 commit comments