Esempio n. 1
0
    def test_set_attrs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]
        element.set_attrs({"foo": "bar"})

        self.assertTrue(element.has_attr("foo"))
        self.assertIn("foo", element.get_attrs())
Esempio n. 2
0
    def test_get_title_element(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("title")
        self.assertEqual(len(elements), 1)
        self.assertEqual(elements[0].name, "TITLE")
        self.assertEqual(elements[0].inner_html(), "simple title")
Esempio n. 3
0
 def test_evaluate_js_01(self):
     """
     Evaluate js method can return strings.
     """
     frame = ph.open(TEST_FILE)
     result = frame.evaluate('document.getElementsByTagName("h1")[0].innerHTML')
     self.assertEqual(result, "Title")
Esempio n. 4
0
    def test_wrap(self):
        p = ph.open(TEST_FILE)

        self.assertEqual(len(p.cssselect("section > #footer")), 0)
        element = p.cssselect("#footer")[0]
        element.wrap("<section />")
        self.assertEqual(len(p.cssselect("section > #footer")), 1)
Esempio n. 5
0
    def test_wrap(self):
        p = ph.open(TEST_FILE)

        self.assertEqual(len(p.cssselect("section > #footer")), 0)
        element = p.cssselect("#footer")[0]
        element.wrap("<section />")
        self.assertEqual(len(p.cssselect("section > #footer")), 1)
Esempio n. 6
0
    def test_remove_all_childs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]

        self.assertEqual(len(element.cssselect("*")), 1)
        element.remove_childs()
        self.assertEqual(len(element.cssselect("*")), 0)
Esempio n. 7
0
    def test_remove_from_document(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]
        element.remove()

        self.assertEqual(len(p.cssselect("#footer")), 0)
        self.assertTrue(element.is_none())
Esempio n. 8
0
    def test_get_title_element(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("title")
        self.assertEqual(len(elements), 1)
        self.assertEqual(elements[0].name, "TITLE")
        self.assertEqual(elements[0].inner_html(), "simple title")
Esempio n. 9
0
    def test_remove_from_document(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]
        element.remove()

        self.assertEqual(len(p.cssselect("#footer")), 0)
        self.assertTrue(element.is_none())
Esempio n. 10
0
    def test_remove_all_childs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]

        self.assertEqual(len(element.cssselect("*")), 1)
        element.remove_childs()
        self.assertEqual(len(element.cssselect("*")), 0)
Esempio n. 11
0
    def test_retrieve_page_background_responses(self):
        frame = ph.open(TEST_FILE)
        response = frame.page.get_response_by_url('http://code.jquery.com/jquery-1.9.1.min.js')

        self.assertNotEqual(response["size"], 0)
        self.assertEqual(response["status"], 200)
        self.assertNotEqual(len(response["headers"]), 0)
Esempio n. 12
0
    def test_set_attrs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]
        element.set_attrs({"foo": "bar"})

        self.assertTrue(element.has_attr("foo"))
        self.assertIn("foo", element.get_attrs())
Esempio n. 13
0
    def test_retrieve_page_background_responses(self):
        frame = ph.open(TEST_FILE)
        response = frame.page.get_response_by_url('http://code.jquery.com/jquery-1.9.1.min.js')

        self.assertNotEqual(response["size"], 0)
        self.assertEqual(response["status"], 200)
        self.assertNotEqual(len(response["headers"]), 0)
Esempio n. 14
0
 def test_evaluate_js_01(self):
     """
     Evaluate js method can return strings.
     """
     frame = ph.open(TEST_FILE)
     result = frame.evaluate('document.getElementsByTagName("h1")[0].innerHTML')
     self.assertEqual(result, "Title")
Esempio n. 15
0
    def test_has_class(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect(".section")
        self.assertEqual(len(elements), 2)
        self.assertTrue(elements[0].has_class("barsection"))
        self.assertTrue(elements[1].has_class("foosection"))
        self.assertFalse(elements[1].has_class("barsection"))
Esempio n. 16
0
    def test_get_inner_text(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("#footer")
        self.assertEqual(len(elements), 1)

        text = elements[0].inner_text()
        self.assertEqual(text.strip(), "some footer")
Esempio n. 17
0
    def test_get_inner_html(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("#footer")
        self.assertEqual(len(elements), 1)

        html = elements[0].inner_html()
        self.assertEqual(html.strip(), "<span>some footer</span>")
Esempio n. 18
0
    def test_cssseelect_first(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect_first("#footer")
        self.assertTrue(element.has_attr("id"))

        with self.assertRaises(ValueError):
            element = p.cssselect_first("#footer2")
Esempio n. 19
0
    def test_get_classes(self):
        p = ph.open(TEST_FILE)
        elements = p.cssselect(".section")

        classes = elements[0].get_classes()

        self.assertEqual(len(classes), 2)
        self.assertEqual(classes, ['section', 'barsection'])
Esempio n. 20
0
    def test_append_01(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect("#footer")[0]
        self.assertEqual(len(element.cssselect("span")), 1)

        element.append("<span>Fooo</span>")
        self.assertEqual(len(element.cssselect("span")), 2)
Esempio n. 21
0
    def test_get_classes(self):
        p = ph.open(TEST_FILE)
        elements = p.cssselect(".section")

        classes = elements[0].get_classes()

        self.assertEqual(len(classes), 2)
        self.assertEqual(classes, ['section', 'barsection'])
Esempio n. 22
0
    def test_inject_jquery(self):
        frame = ph.open(TEST_FILE_SIMPLE)

        with io.open(JQUERY_FILE, "rb") as f:
            frame.evaluate(f.read())

        result = frame.evaluate("$('title').html()")
        self.assertEqual(result, "simple title")
Esempio n. 23
0
    def test_append_01(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect("#footer")[0]
        self.assertEqual(len(element.cssselect("span")), 1)

        element.append("<span>Fooo</span>")
        self.assertEqual(len(element.cssselect("span")), 2)
Esempio n. 24
0
    def test_has_class(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect(".section")
        self.assertEqual(len(elements), 2)
        self.assertTrue(elements[0].has_class("barsection"))
        self.assertTrue(elements[1].has_class("foosection"))
        self.assertFalse(elements[1].has_class("barsection"))
Esempio n. 25
0
    def test_inject_jquery(self):
        frame = ph.open(TEST_FILE_SIMPLE)

        with io.open(JQUERY_FILE, "rb") as f:
            frame.evaluate(f.read())

        result = frame.evaluate("$('title').html()")
        self.assertEqual(result, "simple title")
Esempio n. 26
0
    def test_get_inner_html(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("#footer")
        self.assertEqual(len(elements), 1)

        html = elements[0].inner_html()
        self.assertEqual(html.strip(), "<span>some footer</span>")
Esempio n. 27
0
    def test_get_inner_text(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect("#footer")
        self.assertEqual(len(elements), 1)

        text = elements[0].inner_text()
        self.assertEqual(text.strip(), "some footer")
Esempio n. 28
0
 def test_evaluate_js_02(self):
     """
     Evaluate js method can return dicts and
     arrays.
     """
     frame = ph.open(TEST_FILE)
     result = frame.evaluate('$("#footer").data()')
     self.assertEqual(result, {'id': 1.0})
Esempio n. 29
0
    def test_cssseelect_first(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect_first("#footer")
        self.assertTrue(element.has_attr("id"))

        with self.assertRaises(ValueError):
            element = p.cssselect_first("#footer2")
Esempio n. 30
0
 def test_evaluate_js_02(self):
     """
     Evaluate js method can return dicts and
     arrays.
     """
     frame = ph.open(TEST_FILE)
     result = frame.evaluate('$("#footer").data()')
     self.assertEqual(result, {'id': 1.0})
Esempio n. 31
0
    def test_has_attrs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer span")[0]
        self.assertFalse(element.has_attrs())

        element = p.cssselect("#footer")[0]
        self.assertTrue(element.has_attrs())
        self.assertTrue(element.has_attr("id"))
        self.assertFalse(element.has_attr("class"))
Esempio n. 32
0
    def test_has_attrs(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer span")[0]
        self.assertFalse(element.has_attrs())

        element = p.cssselect("#footer")[0]
        self.assertTrue(element.has_attrs())
        self.assertTrue(element.has_attr("id"))
        self.assertFalse(element.has_attr("class"))
Esempio n. 33
0
    def test_next(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect(".barsection")[0]
        next_element = element.next()
        self.assertTrue(next_element.has_class("foosection"))

        element = p.cssselect("#div-with-attrs")[0].next()
        self.assertTrue(element.is_none())
Esempio n. 34
0
    def test_prev(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect(".foosection")[0]
        prev_element = element.prev()
        self.assertTrue(prev_element.has_class("barsection"))

        element = p.cssselect("h1")[0].prev()
        self.assertTrue(element.is_none())
Esempio n. 35
0
    def test_next(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect(".barsection")[0]
        next_element = element.next()
        self.assertTrue(next_element.has_class("foosection"))

        element = p.cssselect("#div-with-attrs")[0].next()
        self.assertTrue(element.is_none())
Esempio n. 36
0
    def test_prev(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect(".foosection")[0]
        prev_element = element.prev()
        self.assertTrue(prev_element.has_class("barsection"))

        element = p.cssselect("h1")[0].prev()
        self.assertTrue(element.is_none())
Esempio n. 37
0
    def test_remove_class(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect(".barsection")
        self.assertEqual(len(elements), 1)

        elements[0].remove_class("barsection")

        elements = p.cssselect(".barsection")
        self.assertEqual(len(elements), 0)
Esempio n. 38
0
    def test_page_cookies(self):
        frame = ph.open("http://www.facebook.com")
        ctx = ph.context.context()

        cookies = ctx.get_all_cookies()
        self.assertNotEqual(len(cookies), 0)
        self.assertIn("value", cookies[0])
        self.assertIn("name", cookies[0])
        self.assertIn("domain", cookies[0])
        self.assertIn("expires", cookies[0])
Esempio n. 39
0
    def test_remove_class(self):
        p = ph.open(TEST_FILE)

        elements = p.cssselect(".barsection")
        self.assertEqual(len(elements), 1)

        elements[0].remove_class("barsection")

        elements = p.cssselect(".barsection")
        self.assertEqual(len(elements), 0)
Esempio n. 40
0
    def test_page_cookies(self):
        frame = ph.open("http://www.facebook.com")
        ctx = ph.context.context()

        cookies = ctx.get_all_cookies()
        self.assertNotEqual(len(cookies), 0)
        self.assertIn("value", cookies[0])
        self.assertIn("name", cookies[0])
        self.assertIn("domain", cookies[0])
        self.assertIn("expires", cookies[0])
Esempio n. 41
0
 def test_get_attrs(self):
     p = ph.open(TEST_FILE)
     element = p.cssselect("#div-with-attrs")[0]
     attrs = element.get_attrs()
     self.assertIn("data-id", attrs)
     self.assertEqual(attrs, {
         'data-id': '1',
         'data-url': '/foo',
         'id': 'div-with-attrs'
     })
Esempio n. 42
0
    def test_append_02(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect("#footer")[0]
        self.assertEqual(len(element.cssselect("div")), 0)

        tmpelement = p.cssselect(".barsection")[0]
        element.append(tmpelement)

        self.assertEqual(len(element.cssselect("div")), 1)
        self.assertEqual(len(p.cssselect("div")), 4)
Esempio n. 43
0
    def test_remove_attr(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#div-with-attrs")[0]

        attrs = element.get_attrs()
        self.assertIn("data-id", attrs)

        element.remove_attr("data-id")
        attrs = element.get_attrs()
        self.assertNotIn("data-id", attrs)
        self.assertFalse(element.has_attr("data-id"))
Esempio n. 44
0
    def test_append_02(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect("#footer")[0]
        self.assertEqual(len(element.cssselect("div")), 0)

        tmpelement = p.cssselect(".barsection")[0]
        element.append(tmpelement)

        self.assertEqual(len(element.cssselect("div")), 1)
        self.assertEqual(len(p.cssselect("div")), 4)
Esempio n. 45
0
    def test_remove_attr(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#div-with-attrs")[0]

        attrs = element.get_attrs()
        self.assertIn("data-id", attrs)

        element.remove_attr("data-id")
        attrs = element.get_attrs()
        self.assertNotIn("data-id", attrs)
        self.assertFalse(element.has_attr("data-id"))
Esempio n. 46
0
    def test_get_attr(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect_first("#div-with-attrs")

        self.assertEqual(element.get_attr("data-id"), "1")
        self.assertEqual(element.get_attr("data-foo", default=None), None)

        with self.assertRaises(AttributeError):
            attr = element.get_attr("data-foo")

        with self.assertRaises(ValueError):
            attr = element.get_attr("data-id", foo="bar")
Esempio n. 47
0
    def test_get_attr(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect_first("#div-with-attrs")

        self.assertEqual(element.get_attr("data-id"), "1")
        self.assertEqual(element.get_attr("data-foo", default=None), None)

        with self.assertRaises(AttributeError):
            attr = element.get_attr("data-foo")

        with self.assertRaises(ValueError):
            attr = element.get_attr("data-id", foo="bar")
Esempio n. 48
0
 def test_evaluate_js(self):
     frame = ph.open(TEST_FILE)
     result = frame.evaluate('document.getElementsByTagName("h1")[0].innerHTML')
     self.assertEqual(result, "Title")
Esempio n. 49
0
 def test_load_page(self):
     frame = ph.open(TEST_FILE)
     html_data = frame.to_html()
     self.assertNotEqual(len(html_data), 0)
Esempio n. 50
0
 def test_load_page(self):
     frame = ph.open(TEST_FILE)
     html_data = frame.to_html()
     self.assertNotEqual(len(html_data), 0)
Esempio n. 51
0
 def test_load_page(self):
     #import pdb; pdb.set_trace()
     frame = ph.open(TEST_FILE)
     html_data = frame.to_html()
     self.assertNotEqual(len(html_data), 0)
Esempio n. 52
0
    def test_get_null_element(self):
        p = ph.open(TEST_FILE)

        element = p.cssselect("foo")
        self.assertTrue(element.is_none())
Esempio n. 53
0
    def test_capture_page(self):
        p = ph.open(TEST_FILE)
        img = p.to_image()
        blob = img.to_blob()

        self.assertEqual(len(blob), 10931)
Esempio n. 54
0
    def test_inner_cssselect(self):
        p = ph.open(TEST_FILE)
        element = p.cssselect("#footer")[0]

        elements = element.cssselect("span")
        self.assertEqual(len(elements), 1)
Esempio n. 55
0
 def test_replace_02(self):
     p = ph.open(TEST_FILE)
     element = p.cssselect("#footer")[0]
     element.replace(p.cssselect(".barsection")[0])
     self.assertEqual(len(p.cssselect("#footer")), 0)
Esempio n. 56
0
 def test_replace_01(self):
     p = ph.open(TEST_FILE)
     element = p.cssselect("#footer")[0]
     element.replace("<section>kk</section>")
     self.assertEqual(len(p.cssselect("#footer")), 0)
Esempio n. 57
0
    def test_capture_page(self):
        p = ph.open(TEST_FILE)
        img = p.to_image()
        blob = img.to_blob()

        self.assertEqual(len(blob), 10931)
Esempio n. 58
0
 def test_page_cookies(self):
     frame = ph.open("http://www.facebook.com")
     cookies = frame.page.cookies()
     self.assertIsInstance(cookies, dict)
Esempio n. 59
0
 def test_page_all_requests(self):
     frame = ph.open(TEST_FILE)
     self.assertIn('http://code.jquery.com/jquery-1.9.1.min.js',
                   frame.page.get_requested_urls())
     self.assertEqual(len(frame.page.get_requested_urls()), 2)
Esempio n. 60
0
 def test_page_all_requests(self):
     frame = ph.open(TEST_FILE)
     self.assertEqual(frame.page.requested_urls(),
         ['http://code.jquery.com/jquery-1.9.1.min.js'])
     self.assertEqual(len(frame.page.requested_urls()), 1)