diff options
| author | sarahboyce <sarahvboyce95@gmail.com> | 2023-07-04 11:10:37 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-07-05 09:45:50 +0200 |
| commit | 649262a406168709686f97694493aa1f717c6c96 (patch) | |
| tree | e3a7508723a944da5a06a5af571e23a0c6c0f09f /tests/admin_views | |
| parent | 42b4f81e6efd5c4587e1207a2ae3dd0facb1436f (diff) | |
Made some Selenium tests less flaky by adding explicit wait.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/test_autocomplete_view.py | 31 | ||||
| -rw-r--r-- | tests/admin_views/tests.py | 2 |
2 files changed, 21 insertions, 12 deletions
diff --git a/tests/admin_views/test_autocomplete_view.py b/tests/admin_views/test_autocomplete_view.py index ecb5d86bc5..90533ea5b0 100644 --- a/tests/admin_views/test_autocomplete_view.py +++ b/tests/admin_views/test_autocomplete_view.py @@ -431,17 +431,20 @@ class SeleniumTests(AdminSeleniumTestCase): self.live_server_url + reverse("autocomplete_admin:admin_views_answer_add") ) elem = self.selenium.find_element(By.CSS_SELECTOR, ".select2-selection") - elem.click() # Open the autocomplete dropdown. + with self.select2_ajax_wait(): + elem.click() # Open the autocomplete dropdown. results = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results") self.assertTrue(results.is_displayed()) option = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results__option") self.assertEqual(option.text, "No results found") - elem.click() # Close the autocomplete dropdown. + with self.select2_ajax_wait(): + elem.click() # Close the autocomplete dropdown. q1 = Question.objects.create(question="Who am I?") Question.objects.bulk_create( Question(question=str(i)) for i in range(PAGINATOR_SIZE + 10) ) - elem.click() # Reopen the dropdown now that some objects exist. + with self.select2_ajax_wait(): + elem.click() # Reopen the dropdown now that some objects exist. result_container = self.selenium.find_element( By.CSS_SELECTOR, ".select2-results" ) @@ -478,7 +481,8 @@ class SeleniumTests(AdminSeleniumTestCase): ".select2-results__option", 1, root_element=result_container ) # Select the result. - search.send_keys(Keys.RETURN) + with self.select2_ajax_wait(): + search.send_keys(Keys.RETURN) select = Select(self.selenium.find_element(By.ID, "id_question")) self.assertEqual( select.first_selected_option.get_attribute("value"), str(q1.pk) @@ -500,12 +504,14 @@ class SeleniumTests(AdminSeleniumTestCase): self.assertTrue(results.is_displayed()) option = self.selenium.find_element(By.CSS_SELECTOR, ".select2-results__option") self.assertEqual(option.text, "No results found") - elem.click() # Close the autocomplete dropdown. + with self.select2_ajax_wait(): + elem.click() # Close the autocomplete dropdown. Question.objects.create(question="Who am I?") Question.objects.bulk_create( Question(question=str(i)) for i in range(PAGINATOR_SIZE + 10) ) - elem.click() # Reopen the dropdown now that some objects exist. + with self.select2_ajax_wait(): + elem.click() # Reopen the dropdown now that some objects exist. result_container = self.selenium.find_element( By.CSS_SELECTOR, ".select2-results" ) @@ -536,12 +542,13 @@ class SeleniumTests(AdminSeleniumTestCase): self.assertCountSeleniumElements( ".select2-results__option", 1, root_element=result_container ) - # Select the result. - search.send_keys(Keys.RETURN) - # Reopen the dropdown and add the first result to the selection. - elem.click() - search.send_keys(Keys.ARROW_DOWN) - search.send_keys(Keys.RETURN) + with self.select2_ajax_wait(): + # Select the result. + search.send_keys(Keys.RETURN) + # Reopen the dropdown and add the first result to the selection. + elem.click() + search.send_keys(Keys.ARROW_DOWN) + search.send_keys(Keys.RETURN) select = Select(self.selenium.find_element(By.ID, "id_related_questions")) self.assertEqual(len(select.all_selected_options), 2) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 66b7fff04a..26eba69bbd 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -6111,6 +6111,7 @@ class SeleniumTests(AdminSeleniumTestCase): name_input.clear() name_input.send_keys("<i>edited section</i>") 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[0]) # Hide sidebar. toggle_button = self.selenium.find_element( @@ -6133,6 +6134,7 @@ class SeleniumTests(AdminSeleniumTestCase): self.wait_for_text("#content h1", "Add section") self.selenium.find_element(By.ID, "id_name").send_keys("new section") 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[0]) select = Select(self.selenium.find_element(By.ID, "id_form-0-section")) self.assertEqual(select.first_selected_option.text, "new section") |
