diff --git a/tests/jenkins/pages/treeherder.py b/tests/jenkins/pages/treeherder.py index 9d3bab812..50d8e6ca3 100644 --- a/tests/jenkins/pages/treeherder.py +++ b/tests/jenkins/pages/treeherder.py @@ -37,10 +37,6 @@ class TreeherderPage(Page): def info_panel(self): return self.InfoPanel(self) - @property - def pinboard(self): - return self.Pinboard(self) - @property def pushes(self): return [self.ResultSet(self, el) for el in self.find_elements(*self._pushes_locator)] @@ -111,10 +107,6 @@ class TreeherderPage(Page): self.find_element(By.CSS_SELECTOR, 'body').send_keys('n') self.wait.until(lambda _: self.info_panel.is_open) - def pin_using_spacebar(self): - self.find_element(By.CSS_SELECTOR, 'body').send_keys(Keys.SPACE) - self.wait.until(lambda _: self.pinboard.is_pinboard_open) - def select_next_job(self): self.find_element(By.CSS_SELECTOR, 'body').send_keys(Keys.ARROW_RIGHT) @@ -132,7 +124,6 @@ class TreeherderPage(Page): _exception_jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown.btn-purple') _jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown') _pending_jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown.btn-ltgray') - _pin_all_jobs_locator = (By.CLASS_NAME, 'pin-all-jobs-btn') _restarted_jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown.btn-dkblue') _running_jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown.btn-dkgray') _successful_jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown.btn-green') @@ -163,9 +154,6 @@ class TreeherderPage(Page): def pending_jobs(self): return [self.Job(self.page, root=el) for el in self.find_elements(*self._pending_jobs_locator)] - def pin_all_jobs(self): - return self.find_element(*self._pin_all_jobs_locator).click() - @property def restarted_jobs(self): return [self.Job(self.page, root=el) for el in self.find_elements(*self._restarted_jobs_locator)] @@ -204,10 +192,6 @@ class TreeherderPage(Page): def selected(self): return 'selected-job' in self.root.get_attribute('class') - @property - def symbol(self): - return self.root.text - @property def title(self): return self.root.get_attribute('title') @@ -253,7 +237,6 @@ class TreeherderPage(Page): _root_locator = (By.ID, 'job-details-panel') _job_keyword_locator = (By.CSS_SELECTOR, '#job-details-pane > ul > li > a:nth-last-child(1)') _logviewer_button_locator = (By.ID, 'logviewer-btn') - _pin_job_locator = (By.ID, 'pin-job-btn') @property def job_keyword_name(self): @@ -269,46 +252,6 @@ class TreeherderPage(Page): self.selenium.switch_to.window(handle) return LogviewerPage(self.selenium, self.page.base_url).wait_for_page_to_load() - def pin_job(self): - self.find_element(*self._pin_job_locator).click() - self.wait.until(lambda _: self.page.pinboard.is_pinboard_open) - - class Pinboard(Region): - - _root_locator = (By.ID, 'pinboard-panel') - _clear_all_menu_locator = (By.CSS_SELECTOR, '#pinboard-controls .dropdown-menu li:nth-child(5) a') - _jobs_locator = (By.CLASS_NAME, 'pinned-job') - _open_save_menu_locator = (By.CSS_SELECTOR, '#pinboard-controls .save-btn-dropdown') - _pinboard_remove_job_locator = (By.CSS_SELECTOR, '#pinned-job-list .pinned-job-close-btn') - - @property - def is_pinboard_open(self): - return self.root.is_displayed() - - @property - def jobs(self): - return [self.Job(self.page, el) for el in self.find_elements(*self._jobs_locator)] - - @property - def selected_job(self): - return next(j for j in self.jobs if j.is_selected) - - def clear_pinboard(self): - el = self.find_element(*self._open_save_menu_locator) - el.click() - self.wait.until(lambda _: el.get_attribute('aria-expanded') == 'true') - self.find_element(*self._clear_all_menu_locator).click() - - class Job(Region): - - @property - def is_selected(self): - return 'selected-job' in self.root.get_attribute('class') - - @property - def symbol(self): - return self.root.text - class LogviewerPage(Page): diff --git a/tests/jenkins/tests/test_pin_job.py b/tests/jenkins/tests/test_pin_job.py deleted file mode 100644 index 4155133ef..000000000 --- a/tests/jenkins/tests/test_pin_job.py +++ /dev/null @@ -1,44 +0,0 @@ -import random - -from pages.treeherder import TreeherderPage - - -def test_pin_job(base_url, selenium): - """Open treeherder page, select first job and pin it""" - page = TreeherderPage(selenium, base_url).open() - job = random.choice(page.all_jobs) - job.click() - assert 0 == len(page.pinboard.jobs) - page.pin_using_spacebar() - assert 1 == len(page.pinboard.jobs) - assert job.symbol == page.pinboard.selected_job.symbol - - -def test_pin_job_from_job_details(base_url, selenium): - """Open treeherder page, select first job, pin it by the pin icon""" - page = TreeherderPage(selenium, base_url).open() - job = random.choice(page.all_jobs) - job.click() - assert 0 == len(page.pinboard.jobs) - page.info_panel.job_details.pin_job() - assert 1 == len(page.pinboard.jobs) - assert job.symbol == page.pinboard.selected_job.symbol - - -def test_clear_pinboard(base_url, selenium): - """Open treeherder page, pin a job and then clear the pinboard""" - page = TreeherderPage(selenium, base_url).open() - random.choice(page.all_jobs).click() - page.pin_using_spacebar() - assert 1 == len(page.pinboard.jobs) - page.pinboard.clear_pinboard() - assert page.pinboard.is_pinboard_open - assert 0 == len(page.pinboard.jobs) - - -def test_pin_all_jobs(base_url, selenium): - """Open treeherder page, pin all jobs, confirm no more than 500 pins in pinboard""" - page = TreeherderPage(selenium, base_url).open() - result_set = next(r for r in page.pushes if len(r.jobs) > 1) - result_set.pin_all_jobs() - assert len(result_set.jobs) <= len(page.pinboard.jobs) <= 500 diff --git a/tests/selenium/pages/treeherder.py b/tests/selenium/pages/treeherder.py index eda9bf0d4..9e5394add 100644 --- a/tests/selenium/pages/treeherder.py +++ b/tests/selenium/pages/treeherder.py @@ -66,6 +66,10 @@ class Treeherder(Base): def info_panel(self): return self.InfoPanel(self) + @property + def pinboard(self): + return self.Pinboard(self) + @property def pushes(self): return [self.ResultSet(self, el) for el in self.find_elements(*self._pushes_locator)] @@ -184,6 +188,7 @@ class Treeherder(Base): _commits_locator = (By.CSS_SELECTOR, '.revision-list .revision') _job_groups_locator = (By.CSS_SELECTOR, '.job-group') _jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown') + _pin_all_jobs_locator = (By.CLASS_NAME, 'pin-all-jobs-btn') _set_bottom_of_range_locator = (By.CSS_SELECTOR, 'ul.dropdown-menu > li:nth-child(6)') _set_top_of_range_locator = (By.CSS_SELECTOR, 'ul.dropdown-menu > li:nth-child(5)') @@ -211,6 +216,10 @@ class Treeherder(Base): self.find_element(*self._author_locator).click() return self.page.wait_for_page_to_load() + def pin_all_jobs(self): + self.find_element(*self._pin_all_jobs_locator).click() + self.wait.until(lambda _: self.page.pinboard.is_displayed) + def set_as_bottom_of_range(self): # FIXME workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1411264 el = self.page.find_element(By.CSS_SELECTOR, 'body') @@ -244,6 +253,10 @@ class Treeherder(Base): def selected(self): return 'selected-job' in self.root.get_attribute('class') + @property + def symbol(self): + return self.root.text + class JobGroup(Region): _jobs_locator = (By.CSS_SELECTOR, '.job-btn.filter-shown') @@ -299,6 +312,7 @@ class Treeherder(Base): _root_locator = (By.ID, 'job-details-panel') _keywords_locator = (By.CSS_SELECTOR, 'a[title="Filter jobs containing these keywords"]') + _pin_job_locator = (By.ID, 'pin-job-btn') _result_locator = (By.CSS_SELECTOR, '#result-status-pane div:nth-of-type(1) span') @property @@ -311,3 +325,38 @@ class Treeherder(Base): def filter_by_keywords(self): self.find_element(*self._keywords_locator).click() + + def pin_job(self, method='pointer'): + if method == 'keyboard': + el = self.page.find_element(By.CSS_SELECTOR, 'body') + el.send_keys(Keys.SPACE) + else: + self.find_element(*self._pin_job_locator).click() + self.wait.until(lambda _: self.page.pinboard.is_displayed) + + class Pinboard(Region): + + _root_locator = (By.ID, 'pinboard-panel') + _clear_all_locator = (By.CSS_SELECTOR, '#pinboard-controls .dropdown-menu li:nth-child(5) a') + _jobs_locator = (By.CLASS_NAME, 'pinned-job') + _save_menu_locator = (By.CSS_SELECTOR, '#pinboard-controls .save-btn-dropdown') + + def clear(self): + el = self.find_element(*self._save_menu_locator) + el.click() + self.wait.until(lambda _: el.get_attribute('aria-expanded') == 'true') + self.find_element(*self._clear_all_locator).click() + + @property + def is_displayed(self): + return self.root.is_displayed() + + @property + def jobs(self): + return [self.Job(self.page, el) for el in self.find_elements(*self._jobs_locator)] + + class Job(Region): + + @property + def symbol(self): + return self.root.text diff --git a/tests/selenium/test_pin_jobs.py b/tests/selenium/test_pin_jobs.py new file mode 100644 index 000000000..5c87a54a9 --- /dev/null +++ b/tests/selenium/test_pin_jobs.py @@ -0,0 +1,43 @@ +import copy + +import pytest + +from pages.treeherder import Treeherder + + +@pytest.fixture +def test_jobs(eleven_job_blobs, create_jobs): + job_blobs = [] + for i in range(len(eleven_job_blobs)): + job = copy.deepcopy(eleven_job_blobs[0]) + job['job'].update({ + 'job_guid': eleven_job_blobs[i]['job']['job_guid'], + 'job_symbol': 'job{}'.format(i)}) + job_blobs.append(job) + return create_jobs(job_blobs) + + +@pytest.mark.parametrize('method', [('keyboard'), ('pointer')]) +def test_pin_job(base_url, selenium, test_jobs, method): + page = Treeherder(selenium, base_url).open() + page.all_jobs[0].click() + assert len(page.pinboard.jobs) == 0 + page.info_panel.job_details.pin_job(method) + assert len(page.pinboard.jobs) == 1 + assert page.pinboard.jobs[0].symbol == page.all_jobs[0].symbol + + +def test_clear_pinboard(base_url, selenium, test_jobs): + page = Treeherder(selenium, base_url).open() + page.all_jobs[0].click() + page.info_panel.job_details.pin_job() + assert len(page.pinboard.jobs) == 1 + page.pinboard.clear() + assert len(page.pinboard.jobs) == 0 + + +def test_pin_all_jobs(base_url, selenium, test_jobs): + page = Treeherder(selenium, base_url).open() + push = next(p for p in page.pushes if len(p.jobs) > 1) + push.pin_all_jobs() + assert len(page.pinboard.jobs) == len(test_jobs)