Exemplo n.º 1
0
 def test_query_args(self):
     self.assertEquals(
         self.browser.find_elements_by_css_selector.return_value,
         BrowserQuery(self.browser, css='foo').results
     )
     self.assertEquals(
         self.browser.find_elements_by_xpath.return_value,
         BrowserQuery(self.browser, xpath='foo').results
     )
Exemplo n.º 2
0
    def test_error_cases(self):
        with self.assertRaises(TypeError):
            BrowserQuery(self.browser, css='foo', xpath='bar')

        with self.assertRaises(TypeError):
            BrowserQuery(self.browser)

        with self.assertRaises(TypeError):
            BrowserQuery(self.browser, foo='bar')
Exemplo n.º 3
0
    def test_many_problems(self):
        # Test that problems work properly.
        self.browser.get(self.live_server_url + "/scenario/test_many_problems")
        header1 = BrowserQuery(self.browser, css="h1")
        self.assertEqual(header1.text[0], "XBlock: Many problems")

        # Find the numbers on the page.
        nums = self.browser.find_elements_by_css_selector("p.the_numbers")
        num_pairs = [tuple(int(n) for n in num.text.split()) for num in nums]

        # They should be all different.
        self.assertEqual(len(set(num_pairs)), self.num_problems)

        text_ctrls_xpath = '//div[@data-block-type="textinput_demo"][@data-name="sum_input"]/input'
        text_ctrls = self.browser.find_elements_by_xpath(text_ctrls_xpath)
        check_btns = BrowserQuery(self.browser, css='input.check')
        check_indicators = 'span.indicator'

        def assert_image(right_wrong_idx, expected_icon):
            """Assert that the img src text includes `expected_icon`"""
            for _ in range(3):
                try:
                    sources = BrowserQuery(
                        self.browser,
                        css='{} img'.format(check_indicators, ),
                    ).nth(right_wrong_idx).attrs('src')
                    if sources and expected_icon in sources[0]:
                        break
                    else:
                        time.sleep(.25)
                except StaleElementReferenceException as exc:
                    print exc
            self.assertIn(expected_icon, sources[0])

        for i in range(self.num_problems):
            # Before answering, the indicator says Not Attempted.
            self.assertIn(
                "Not attempted",
                BrowserQuery(self.browser,
                             css=check_indicators).nth(i).text[0])

            answer = sum(num_pairs[i])

            for _ in range(2):
                # Answer right.
                text_ctrls[i].clear()
                text_ctrls[i].send_keys(str(answer))
                check_btns[i].click()
                assert_image(i, "/correct-icon.png")

                # Answer wrong.
                text_ctrls[i].clear()
                text_ctrls[i].send_keys(str(answer + 1))
                check_btns[i].click()
                assert_image(i, "/incorrect-icon.png")
 def display_modal(self):
     """
     Click the share button to display the sharing modal for the badge.
     """
     BrowserQuery(self.element, css=".share-button").click()
     EmptyPromise(self.modal_displayed, "Share modal displayed").fulfill()
     EmptyPromise(self.modal_focused, "Focus handed to modal").fulfill()
Exemplo n.º 5
0
 def close_modal(self):
     """
     Close the badges modal and check that it is no longer displayed.
     """
     BrowserQuery(self.full_view, css=".badges-modal .close").click()
     EmptyPromise(lambda: not self.modal_displayed(),
                  "Share modal dismissed").fulfill()
 def assert_image(right_wrong_idx, expected_icon):
     """Assert that the img src text includes `expected_icon`"""
     for _ in range(3):
         try:
             sources = BrowserQuery(
                 self.browser,
                 css=u'{} img'.format(check_indicators, ),
             ).nth(right_wrong_idx).attrs('src')
             if sources and expected_icon in sources[0]:
                 break
             time.sleep(.25)
         except StaleElementReferenceException as exc:
             print(exc)
     self.assertIn(expected_icon, sources[0])
 def is_browser_on_page(self):
     return BrowserQuery(self.element, css=".badge-details").visible
Exemplo n.º 8
0
 def test_repr(self):
     assert repr(BrowserQuery(self.browser,
                              css='foo')) == u"BrowserQuery(css='foo')"
     assert repr(BrowserQuery(self.browser,
                              xpath='foo')) == u"BrowserQuery(xpath='foo')"
Exemplo n.º 9
0
 def test_repr(self):
     self.assertEquals(u"BrowserQuery(css='foo')", repr(BrowserQuery(self.browser, css='foo')))
     self.assertEquals(u"BrowserQuery(xpath='foo')", repr(BrowserQuery(self.browser, xpath='foo')))
Exemplo n.º 10
0
 def modal_focused(self):
     """
     Return True if the badges model has focus, False otherwise.
     """
     return BrowserQuery(self.full_view, css=".badges-modal").is_focused()
Exemplo n.º 11
0
 def modal_displayed(self):
     """
     Verifies that the share modal is diplayed.
     """
     # The modal is on the page at large, and not a subelement of the badge div.
     return BrowserQuery(self.full_view, css=".badges-modal").visible