From 402ae37873974afa5093e6d6149175a118979cd9 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Tue, 5 Oct 2021 12:15:21 +0200 Subject: [PATCH] Refs #33029 -- Fixed popups Selenium tests in headless mode. Co-authored-by: Yash Jhunjhunwala --- tests/admin_views/tests.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 863521bee5..0ba81fde87 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4649,6 +4649,8 @@ class SeleniumTests(AdminSeleniumTestCase): # Tabular inlines ---------------------------------------------------- # Initial inline + element = self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-status') + self.selenium.execute_script('window.scrollTo(0, %s);' % element.location['y']) self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-pubdate').send_keys('1234-12-07') self.select_option('#id_relatedprepopulated_set-2-0-status', 'option two') self.selenium.find_element_by_id('id_relatedprepopulated_set-2-0-name').send_keys( @@ -4992,32 +4994,35 @@ class SeleniumTests(AdminSeleniumTestCase): add_url = reverse('admin:admin_views_box_add', current_app=site.name) self.selenium.get(self.live_server_url + add_url) + base_window = self.selenium.current_window_handle self.selenium.find_element_by_id('add_id_next_box').click() self.wait_for_and_switch_to_popup() + popup_window_test = self.selenium.current_window_handle self.selenium.find_element_by_id('id_title').send_keys('test') self.selenium.find_element_by_id('add_id_next_box').click() self.wait_for_and_switch_to_popup(num_windows=3) + popup_window_test2 = self.selenium.current_window_handle self.selenium.find_element_by_id('id_title').send_keys('test2') self.selenium.find_element_by_id('add_id_next_box').click() self.wait_for_and_switch_to_popup(num_windows=4) self.selenium.find_element_by_id('id_title').send_keys('test3') self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.selenium.switch_to.window(popup_window_test2) select = Select(self.selenium.find_element_by_id('id_next_box')) next_box_id = str(Box.objects.get(title="test3").id) self.assertEqual(select.first_selected_option.get_attribute('value'), next_box_id) self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.selenium.switch_to.window(popup_window_test) select = Select(self.selenium.find_element_by_id('id_next_box')) next_box_id = str(Box.objects.get(title="test2").id) self.assertEqual(select.first_selected_option.get_attribute('value'), next_box_id) self.selenium.find_element_by_xpath('//input[@value="Save"]').click() - self.selenium.switch_to.window(self.selenium.window_handles[-1]) + self.selenium.switch_to.window(base_window) select = Select(self.selenium.find_element_by_id('id_next_box')) next_box_id = str(Box.objects.get(title="test").id) self.assertEqual(select.first_selected_option.get_attribute('value'), next_box_id) @@ -5046,11 +5051,13 @@ class SeleniumTests(AdminSeleniumTestCase): self.selenium.switch_to.window(test2_window) self.selenium.find_element_by_xpath('//input[@value="Save"]').click() + self.wait_until(lambda d: len(d.window_handles) == 2, 1) self.assertEqual(len(self.selenium.window_handles), 2) # Close final popup to clean up test. self.selenium.switch_to.window(test_window) self.selenium.find_element_by_xpath('//input[@value="Save"]').click() + self.wait_until(lambda d: len(d.window_handles) == 1, 1) self.selenium.switch_to.window(self.selenium.window_handles[-1])