@@ -110,38 +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- self .login ()
115- device = self ._create_config (organization = self ._get_org ()).device
116- path = reverse ('admin:config_device_change' , args = [device .id ])
117- self .open (path )
118- with self .subTest ('Alert should not be displayed without any change' ):
119- self .open (path )
120- try :
121- WebDriverWait (self .web_driver , 1 ).until (EC .alert_is_present ())
122- except TimeoutException :
123- pass
124- else :
125- self .fail ('Unsaved changes alert displayed without any change' )
126-
127- with self .subTest ('Alert should be displayed after making changes' ):
128- # simulate hand gestures
129- self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
130- self .find_element (by = By .NAME , value = 'name' ).click ()
131- # set name
132- self .find_element (by = By .NAME , value = 'name' ).send_keys ('new.device.name' )
133- # simulate hand gestures
134- self .find_element (by = By .TAG_NAME , value = 'body' ).click ()
135- self .web_driver .refresh ()
136- try :
137- WebDriverWait (self .web_driver , 5 ).until (EC .alert_is_present ())
138- except TimeoutException :
139- for entry in self .get_browser_logs ():
140- print (entry )
141- self .fail ('Timed out wating for unsaved changes alert' )
142- else :
143- self .web_driver .switch_to .alert .accept ()
144-
145113 def test_multiple_organization_templates (self ):
146114 shared_required_template = self ._create_template (
147115 name = 'shared required' , organization = None
@@ -312,6 +280,53 @@ def test_force_delete_multiple_devices_with_deactivating_config(self):
312280 self .assertEqual (Device .objects .count (), 0 )
313281
314282
283+ @tag ('selenium_tests' )
284+ class TestDeviceAdminUnsavedChanges (
285+ DeviceAdminSeleniumTextMixin ,
286+ CreateConfigTemplateMixin ,
287+ StaticLiveServerTestCase ,
288+ ):
289+ web_driver = '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+
315330@tag ('selenium_tests' )
316331class TestVpnAdmin (
317332 SeleniumTestMixin ,
0 commit comments