Skip to content

Commit

Permalink
Rework published histories selenium test a bit.
Browse files Browse the repository at this point in the history
- Wait for elements to be clickable before clicking them.
- Allow individual tests to be run on their own and out of order.
- Use randomly generated emails - the tests still can't really be applied to an external Galaxy test server but this gets us closer.
  • Loading branch information
jmchilton authored and anatskiy committed Aug 29, 2017
1 parent 773029b commit a464fe9
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions test/selenium_tests/test_published_histories_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from .framework import SeleniumTestCase, selenium_test

# Test case data
USER1_EMAIL = 'test_user1@test.test'
USER2_EMAIL = 'test_user2@test.test'
HISTORY1_NAME = 'First'
HISTORY2_NAME = 'Second'
HISTORY3_NAME = 'Third'
Expand All @@ -17,12 +15,14 @@

class HistoryGridTestCase(SeleniumTestCase):

def setUp(self):
super(HistoryGridTestCase, self).setUp()
self.ensure_users_and_histories()

@selenium_test
def test_history_grid_histories(self):
self.setup_users_and_histories()
self.navigate_to_published_histories_page()
histories = self.get_histories()
assert histories == [HISTORY2_NAME, HISTORY3_NAME, HISTORY1_NAME]
self.assert_grid_histories_are([HISTORY2_NAME, HISTORY3_NAME, HISTORY1_NAME])

@selenium_test
def test_history_grid_search_standard(self):
Expand All @@ -32,15 +32,13 @@ def test_history_grid_search_standard(self):
search_input = self.wait_for_selector(input_selector)
search_input.send_keys(HISTORY1_NAME)
self.send_enter(search_input)
histories = self.get_histories()
assert histories == [HISTORY1_NAME]
self.assert_grid_histories_are([HISTORY1_NAME])

self.unset_filter('free-text-search', HISTORY1_NAME)
search_input = self.wait_for_selector(input_selector)
search_input.send_keys(HISTORY4_NAME)
self.send_enter(search_input)
histories = self.get_histories()
assert histories == ['No Items']
self.assert_grid_histories_are(['No Items'])

@selenium_test
def test_history_grid_search_advanced(self):
Expand All @@ -57,45 +55,39 @@ def test_history_grid_search_advanced(self):

# Search by name
self.set_filter(name_filter_selector, HISTORY1_NAME)
histories = self.get_histories()
assert histories == [HISTORY1_NAME]
self.assert_grid_histories_are([HISTORY1_NAME])
self.unset_filter('name', HISTORY1_NAME)

# Search by annotation
annotation = HISTORY3_ANNOT.split(' ')[0]
self.set_filter(annot_filter_selector, annotation)
histories = self.get_histories()
assert histories == [HISTORY3_NAME]
self.assert_grid_histories_are([HISTORY3_NAME])
self.unset_filter('annotation', annotation)

# Search by owner
owner = USER2_EMAIL.split('@')[0]
owner = self.user2_email.split('@')[0]
self.set_filter(owner_filter_selector, owner)
histories = self.get_histories()
assert histories == [HISTORY2_NAME]
self.assert_grid_histories_are([HISTORY2_NAME])
self.unset_filter('username', owner)

# Search by tags
self.set_filter(tags_filter_selector, HISTORY1_TAGS[0])
histories = self.get_histories()
assert histories == [HISTORY3_NAME, HISTORY1_NAME]
self.assert_grid_histories_are([HISTORY3_NAME, HISTORY1_NAME])
self.unset_filter('tags', HISTORY1_TAGS[0])

@selenium_test
def test_history_grid_sort_by_name(self):
self.navigate_to_published_histories_page()
sort_link = self.wait_for_selector('th#name-header > a')
sort_link.click()
histories = self.get_histories()
assert histories == [HISTORY1_NAME, HISTORY2_NAME, HISTORY3_NAME]
self.assert_grid_histories_are([HISTORY1_NAME, HISTORY2_NAME, HISTORY3_NAME])

@selenium_test
def test_history_grid_sort_by_owner(self):
self.navigate_to_published_histories_page()
sort_link = self.wait_for_selector('th#username-header > a')
sort_link.click()
histories = self.get_histories()
assert histories == [HISTORY1_NAME, HISTORY3_NAME, HISTORY2_NAME]
self.assert_grid_histories_are([HISTORY1_NAME, HISTORY3_NAME, HISTORY2_NAME])

@selenium_test
def test_history_grid_tag_click(self):
Expand All @@ -116,10 +108,9 @@ def test_history_grid_tag_click(self):

tag_button.click()

histories = self.get_histories()
assert histories == [HISTORY3_NAME, HISTORY1_NAME]
self.assert_grid_histories_are([HISTORY3_NAME, HISTORY1_NAME])

def get_histories(self):
def get_histories(self, sleep=False):
time.sleep(1.5)

names = []
Expand All @@ -130,17 +121,23 @@ def get_histories(self):

return names

def assert_grid_histories_are(self, expected_histories, sort_matters=True):
actual_histories = self.get_histories()
if not sort_matters:
expected_histories = set(expected_histories)
actual_histories = set(actual_histories)

self.assertEqual(expected_histories, actual_histories)

def set_filter(self, selector, value):
filter_input = self.wait_for_selector(selector)
time.sleep(.5)
filter_input.click()
filter_input = self.wait_for_selector_clickable(selector)
filter_input.send_keys(value)
self.send_enter(filter_input)

def unset_filter(self, filter_key, filter_value):
close_link_selector = 'a[filter_key="%s"][filter_val="%s"]' % \
(filter_key, filter_value)
close_link = self.wait_for_selector(close_link_selector)
close_link = self.wait_for_selector_clickable(close_link_selector)
close_link.click()
time.sleep(.5)

Expand All @@ -149,12 +146,11 @@ def set_tags(self, tags):
tag_area_selector = self.test_data['historyPanel']['selectors']['history']['tagArea']

if not self.is_displayed(tag_area_selector):
tag_icon = self.wait_for_selector(tag_icon_selector)
tag_icon = self.wait_for_selector_clickable(tag_icon_selector)
tag_icon.click()
time.sleep(.5)

tag_area_selector += ' .tags-input input'
tag_area = self.wait_for_selector(tag_area_selector)
tag_area = self.wait_for_selector_clickable(tag_area_selector)
tag_area.click()

for tag in tags:
Expand All @@ -167,25 +163,29 @@ def set_annotation(self, annotation):
anno_area_selector = self.test_data['historyPanel']['selectors']['history']['annoArea']

if not self.is_displayed(anno_area_selector):
annon_icon = self.wait_for_selector(anno_icon_selector)
annon_icon = self.wait_for_selector_clickable(anno_icon_selector)
annon_icon.click()

anno_area_selector += ' .annotation'
annon_area = self.wait_for_selector(anno_area_selector)
time.sleep(.5)
annon_area = self.wait_for_selector_clickable(anno_area_selector)
annon_area.click()

area_editable_selector = anno_area_selector + ' textarea'
done_button_selector = anno_area_selector + ' button'
annon_area_editable = self.wait_for_selector(area_editable_selector)
anno_done_button = self.wait_for_selector(done_button_selector)
annon_area_editable = self.wait_for_selector_clickable(area_editable_selector)
anno_done_button = self.wait_for_selector_clickable(done_button_selector)

annon_area_editable.click()
annon_area_editable.send_keys(annotation)
anno_done_button.click()

def setup_users_and_histories(self):
self.register(USER1_EMAIL)
def ensure_users_and_histories(self):
if getattr(HistoryGridTestCase, "user1_email", None):
return

HistoryGridTestCase.user1_email = self._get_random_email()
HistoryGridTestCase.user2_email = self._get_random_email()
self.register(self.user1_email)
self.create_history(HISTORY1_NAME)
self.set_tags(HISTORY1_TAGS)
self.publish_current_history()
Expand All @@ -196,7 +196,7 @@ def setup_users_and_histories(self):
self.publish_current_history()
self.logout_if_needed()

self.register(USER2_EMAIL)
self.register(self.user2_email)
self.create_history(HISTORY2_NAME)
self.set_tags(HISTORY2_TAGS)
self.publish_current_history()
Expand All @@ -213,7 +213,7 @@ def publish_current_history(self):
self.click_history_option('Share or Publish')
with self.main_panel():
selector = 'input[name="make_accessible_and_publish"]'
publish_button = self.wait_for_selector(selector)
publish_button = self.wait_for_selector_clickable(selector)
publish_button.click()

def navigate_to_published_histories_page(self):
Expand All @@ -222,7 +222,7 @@ def navigate_to_published_histories_page(self):
self.click_label(
self.navigation_data['labels']['masthead']['menus']['libraries'])
selector = 'a[href="/histories/list_published"]'
histories_link = self.wait_for_selector(selector)
histories_link = self.wait_for_selector_clickable(selector)
histories_link.click()

def click_history_option(self, option_label):
Expand Down

0 comments on commit a464fe9

Please sign in to comment.