def test_candidate_filter_history(self):
        self.check_filter('state', 'AL', 4, 'AL')
        self.assertIn('state=AL', self.driver.current_url)
        self.check_filter('state', 'AR', 4, {'AL', 'AR'}, refresh=False, expand=False)
        self.assertIn('state=AL', self.driver.current_url)
        self.assertIn('state=AR', self.driver.current_url)

        # Test back behavior
        self.driver.back()
        self.check_filter_results(4, 'AL')
        self.assertIn('state=AL', self.driver.current_url)
        self.assertNotIn('state=AR', self.driver.current_url)
        self.assertIn('state=AL', self.driver.current_url)

        # Test forward behavior
        self.driver.forward()
        self.check_filter_results(4, {'AL', 'AR'})
        self.assertIn('state=AL', self.driver.current_url)
        self.assertIn('state=AR', self.driver.current_url)

        # Uncheck filters and verify empty query string
        self.click_filter('state', 'AR', expand=False)
        self.click_filter('state', 'AL', expand=False)
        utils.wait_for_event(self.driver, 'draw.dt', 'draw')
        self.assertNotIn('state=AL', self.driver.current_url)
        self.assertNotIn('state=AR', self.driver.current_url)
Ejemplo n.º 2
0
 def check_filter_results(self, index, result):
     utils.wait_for_event(self.driver, 'draw.dt', 'draw', timeout=0.5)
     # Handle stale reference errors in Chrome
     get_values = lambda: [
         row.find_elements_by_tag_name('td')[index].text
         for row in self.driver.find_elements_by_css_selector('tbody tr[role="row"]')
     ]
     values = utils.try_until(get_values, errors=(StaleElementReferenceException, ))
     if callable(result):
         for value in values:
             self.assertTrue(result(value))
     else:
         result = set([result]) if not isinstance(result, set) else result
         self.assertTrue(result.issuperset(values))
    def setUpClass(cls):
        super().setUpClass()

        cls.driver.get(cls.base_url + '/candidates')
        utils.wait_for_event(cls.driver, 'draw.dt', 'draw')
        cls.candidate = cls.driver.find_element_by_css_selector(
            'a[data-category="candidate"]'
        ).text

        cls.driver.get(cls.base_url + '/committees')
        utils.wait_for_event(cls.driver, 'draw.dt', 'draw')
        cls.committee = cls.driver.find_element_by_css_selector(
            'a[data-category="committee"]'
        ).text
    def test_glossary_load_from_term(self):
        self.driver.get(self.base_url + '/candidates')
        utils.wait_for_event(self.driver, 'draw.dt', 'draw')
        self.driver.find_element_by_css_selector('a[data-category="candidate"]').click()

        term = self.driver.find_element_by_class_name('term')
        term.click()
        glossary = self.getGlossary()
        # Glossary is open
        self.assertIn('is-open', glossary.get_attribute('class'))
        highlighted = self.driver.find_elements_by_css_selector('.glossary-term')
        # Exactly one glossary term is highlighted
        self.assertEqual(len(highlighted), 1)
        # Expected term is highlighted
        WebDriverWait(self.driver, 1).until(lambda driver: highlighted[0].text)
        self.assertEqual(term.text.lower(), highlighted[0].text.lower())
        # Definition is expanded
        self.assertTrue(
            self.driver.find_element_by_css_selector('.glossary-definition').text
        )
 def testSingleCandidatePageLoads(self):
     self.driver.get(self.base_url + '/candidates')
     utils.wait_for_event(self.driver, 'draw.dt', 'draw')
     self.driver.find_element_by_css_selector('a[data-category="candidate"]').click()
Ejemplo n.º 6
0
def toggle_sort(driver, index):
    table = driver.find_element_by_css_selector('table#results')
    column = table.find_elements_by_tag_name('th')[index]
    utils.try_until(lambda: column.click())
    utils.wait_for_event(driver, 'draw.dt', 'draw', timeout=0.5)