diff --git a/test/selenium_tests/framework.py b/test/selenium_tests/framework.py index 1374e34af8f..3576354d9b4 100644 --- a/test/selenium_tests/framework.py +++ b/test/selenium_tests/framework.py @@ -6,8 +6,8 @@ import datetime import json import os import time - import traceback +import unittest from functools import partial, wraps @@ -221,6 +221,38 @@ class SeleniumTestCase(FunctionalTestCase, NavigatesGalaxy): return SeleniumSessionWorkflowPopulator(self) +class SharedStateSeleniumTestCase(SeleniumTestCase): + """This describes a class Selenium tests that setup class state for all tests. + + This is a bit hacky because we are simulating class level initialization + with instance level methods. The problem is that super.setUp() works at + instance level. It might be worth considering having two variants of + SeleniumTestCase - one that initializes with the class and the other that + initializes with the instance but all the helpers are instance helpers. + """ + + shared_state_initialized = False + shared_state_in_error = False + + def setUp(self): + super(SharedStateSeleniumTestCase, self).setUp() + if not self.__class__.shared_state_initialized: + try: + self.setup_shared_state() + self.logout_if_needed() + except Exception: + self.__class__.shared_state_in_error = True + raise + finally: + self.__class__.shared_state_initialized = True + else: + if self.__class__.shared_state_in_error: + raise unittest.SkipTest("Skipping test, failed to initialize state previously.") + + def setup_shared_state(self): + """Override this to setup shared data for tests that gets initialized only once.""" + + class UsesHistoryItemAssertions: def assert_item_peek_includes(self, hid, expected): diff --git a/test/selenium_tests/test_custom_builds.py b/test/selenium_tests/test_custom_builds.py index 13c16e92e9f..55946b91e06 100644 --- a/test/selenium_tests/test_custom_builds.py +++ b/test/selenium_tests/test_custom_builds.py @@ -3,15 +3,16 @@ import time from .framework import ( retry_assertion_during_transitions, selenium_test, - SeleniumTestCase, + SharedStateSeleniumTestCase, ) -class CustomBuildsTestcase(SeleniumTestCase): +class CustomBuildsTestcase(SharedStateSeleniumTestCase): def setUp(self): super(CustomBuildsTestcase, self).setUp() - self.ensure_user() + self.home() # ensure Galaxy is loaded + self.submit_login(self.user_email) @selenium_test def test_build_add(self): @@ -91,12 +92,7 @@ class CustomBuildsTestcase(SeleniumTestCase): self.click_label(label) self.wait_for_and_click_selector('a[href="/custom_builds"]') - def ensure_user(self): - if getattr(CustomBuildsTestcase, 'user_email', None): - self.home() # ensure Galaxy is loaded - self.submit_login(self.user_email) - return - + def setup_shared_state(self): CustomBuildsTestcase.user_email = self._get_random_email() self.register(self.user_email) diff --git a/test/selenium_tests/test_published_histories_grid.py b/test/selenium_tests/test_published_histories_grid.py index 56f7411696a..a6b610118c1 100644 --- a/test/selenium_tests/test_published_histories_grid.py +++ b/test/selenium_tests/test_published_histories_grid.py @@ -3,15 +3,15 @@ import time from .framework import ( retry_assertion_during_transitions, selenium_test, - SeleniumTestCase, + SharedStateSeleniumTestCase, ) -class HistoryGridTestCase(SeleniumTestCase): +class HistoryGridTestCase(SharedStateSeleniumTestCase): def setUp(self): super(HistoryGridTestCase, self).setUp() - self.ensure_users_and_histories() + self.home() @selenium_test def test_history_grid_histories(self): @@ -178,11 +178,7 @@ class HistoryGridTestCase(SeleniumTestCase): annon_area_editable.send_keys(annotation) anno_done_button.click() - def ensure_users_and_histories(self): - if getattr(HistoryGridTestCase, 'user1_email', None): - self.home() # ensure Galaxy is loaded - return - + def setup_shared_state(self): tag1 = self._get_random_name(len=5) tag2 = self._get_random_name(len=5) tag3 = self._get_random_name(len=5) diff --git a/test/selenium_tests/test_saved_histories.py b/test/selenium_tests/test_saved_histories.py index c1b7feec624..83504246cd7 100644 --- a/test/selenium_tests/test_saved_histories.py +++ b/test/selenium_tests/test_saved_histories.py @@ -3,15 +3,16 @@ import time from .framework import ( retry_assertion_during_transitions, selenium_test, - SeleniumTestCase, + SharedStateSeleniumTestCase, ) -class SavedHistoriesTestCase(SeleniumTestCase): +class SavedHistoriesTestCase(SharedStateSeleniumTestCase): def setUp(self): super(SavedHistoriesTestCase, self).setUp() - self.ensure_user_and_histories() + self.home() + self.submit_login(self.user_email) @selenium_test def test_saved_histories_list(self): @@ -263,12 +264,7 @@ class SavedHistoriesTestCase(SeleniumTestCase): self.click_label(label) self.wait_for_and_click_selector('a[href="/histories/list"]') - def ensure_user_and_histories(self): - if getattr(SavedHistoriesTestCase, 'user_email', None): - self.home() # ensure Galaxy is loaded - self.submit_login(self.user_email) - return - + def setup_shared_state(self): SavedHistoriesTestCase.user_email = self._get_random_email() SavedHistoriesTestCase.history1_name = self._get_random_name() SavedHistoriesTestCase.history2_name = self._get_random_name()