Skip to content
Permalink
Browse files

Merge pull request #4647 from jmchilton/selenium_fixes_28

Improved state handling for @anatskiy-style Selenium tests.
  • Loading branch information...
martenson committed Sep 19, 2017
2 parents 844f083 + 87bb576 commit 3f51e7dc1ef99a68aa8694cfe6858a70e9482e50
@@ -6,8 +6,8 @@
import json
import os
import time

import traceback
import unittest

from functools import partial, wraps

@@ -221,6 +221,38 @@ def workflow_populator(self):
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):
@@ -3,15 +3,16 @@
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 @@ def navigate_to_custom_builds_page(self):
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)

@@ -3,15 +3,15 @@
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 @@ def set_annotation(self, annotation):
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)
@@ -3,15 +3,16 @@
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 @@ def navigate_to_saved_histories_page(self):
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()

0 comments on commit 3f51e7d

Please sign in to comment.
You can’t perform that action at this time.