Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved state handling for @anatskiy-style Selenium tests. #4647

Merged
merged 1 commit into from Sep 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 33 additions & 1 deletion test/selenium_tests/framework.py
Expand Up @@ -6,8 +6,8 @@
import json
import os
import time

import traceback
import unittest

from functools import partial, wraps

Expand Down Expand Up @@ -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):
Expand Down
14 changes: 5 additions & 9 deletions test/selenium_tests/test_custom_builds.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 4 additions & 8 deletions test/selenium_tests/test_published_histories_grid.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions test/selenium_tests/test_saved_histories.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down