Пример #1
0
    def test_stale_element_in_wait(self):
        """ https://github.com/alisaifee/issues/23
        """
        driver = get_driver()

        def rem():
            driver.execute_script("""
            if ( document.getElementsByClassName('stale').length > 1 ){
                var f = document.getElementById('container').firstChild;
                document.getElementById('container').removeChild(f);
            }
            """)

        class P(Page):
            e = Elements(Locators.CLASS_NAME,
                         "stale",
                         timeout=1,
                         only_if=lambda els: rem() or any(e.is_displayed()
                                                          for e in els))

        uri = make_temp_page("""
<html>
<body>
<div id='container'><div class="stale">1</div><div class="stale">2</div></div>
</body>
</html>
        """)
        p = P(driver, uri)
        self.assertEqual(len(p.e), 1)
Пример #2
0
    def test_stale_element_in_wait(self):
        """ https://github.com/alisaifee/issues/23
        """
        driver = get_driver()

        def rem():
            driver.execute_script(
                """
            if ( document.getElementsByClassName('stale').length > 1 ){
                var f = document.getElementById('container').firstChild;
                document.getElementById('container').removeChild(f);
            }
            """
            )

        class P(Page):
            e = Elements(
                Locators.CLASS_NAME, "stale", timeout=1, only_if=lambda els: rem() or any(e.is_displayed() for e in els)
            )

        uri = make_temp_page(
            """
        <html><body>
        <div id='container'><div class="stale">1</div><div class="stale">2</div></div>
        </body></html>
        """
        )
        p = P(driver, uri)
        self.assertEqual(len(p.e), 1)
Пример #3
0
 def test_sections_by_index(self):
     driver = get_driver()
     page = """
     <body>
         <div class='section'>
             <div class='token'>t0</div>
         </div>
         <div class='section'>
             <div class='token'>t1</div>
         </div>
         <div class='section'>
             <div class='token'>t2</div>
         </div>
         <div class='section'>
             <div class='token'>t3</div>
         </div>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPageWithSections(driver, uri)
     self.assertEqual(len(po.sections), 4)
     self.assertEqual("t0", po.sections[0].tokens[0].text)
     self.assertEqual("t1", po.sections[1].tokens[0].text)
     self.assertEqual("t2", po.sections[2].tokens[0].text)
     self.assertEqual("t3", po.sections[3].tokens[0].text)
Пример #4
0
 def test_sections_by_index(self):
     driver = get_driver()
     page = """
     <body>
         <div class='section'>
             <div class='token'>t0</div>
         </div>
         <div class='section'>
             <div class='token'>t1</div>
         </div>
         <div class='section'>
             <div class='token'>t2</div>
         </div>
         <div class='section'>
             <div class='token'>t3</div>
         </div>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPageWithSections(driver, uri)
     self.assertEqual(len(po.sections), 4)
     self.assertEqual("t0", po.sections[0].tokens[0].text)
     self.assertEqual("t1", po.sections[1].tokens[0].text)
     self.assertEqual("t2", po.sections[2].tokens[0].text)
     self.assertEqual("t3", po.sections[3].tokens[0].text)
Пример #5
0
 def test_fluent(self):
     class FluentPage(Page):
         thing = Element(Locators.NAME, "thing")
         def get_text(self):
             return self.thing.text
         def click_thing(self):
             self.thing.click()
     page = "<div name='thing'>i am thing</div>"
     driver = get_driver()
     uri = make_temp_page(page)
     page = FluentPage(driver, uri)
     self.assertTrue(page.click_thing().get_text(), "i am thing")
Пример #6
0
 def test_basic_po_real(self):
     driver = get_driver()
     page = """
     <body>
         <div id='section'>
             <div class='token'>
                 <div class='el'>
                     section element 1
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 2
                 </div>
             </div>
         </div>
         <div id='section_2'>
             <div class='token'>
                 <div class='el'>
                     section element 3
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 4
                 </div>
             </div>
         </div>
         <span class='token'>
             <div class='el'>
                 element 5
             </div>
         </span>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPage(driver, uri)
     self.assertEqual(len(po.tokens), 5)
     self.assertEqual(len(po.section.tokens), 2)
     self.assertEqual(len(po.section_2.tokens), 2)
     for i in range(0, 2):
         self.assertEqual(po.section.tokens[i].text,
                          "section element %s" % (i + 1))
     for i in range(0, 2):
         self.assertEqual(po.section_2.tokens[i].text,
                          "section element %s" % (i + 3))
     self.assertEqual(po.tokens[0].text, 'section element 1')
     self.assertEqual(po.tokens[1].text, 'section element 2')
     self.assertEqual(po.tokens[2].text, 'section element 3')
     self.assertEqual(po.tokens[3].text, 'section element 4')
Пример #7
0
 def test_basic_po_real(self):
     driver = get_driver()
     page = """
     <body>
         <div id='section'>
             <div class='token'>
                 <div class='el'>
                     section element 1
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 2
                 </div>
             </div>
         </div>
         <div id='section_2'>
             <div class='token'>
                 <div class='el'>
                     section element 3
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 4
                 </div>
             </div>
         </div>
         <span class='token'>
             <div class='el'>
                 element 5
             </div>
         </span>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPage(driver, uri)
     self.assertEqual(len(po.tokens), 5)
     self.assertEqual(len(po.section.tokens), 2)
     self.assertEqual(len(po.section_2.tokens), 2)
     for i in range(0, 2):
         self.assertEqual(po.section.tokens[i].text,
                           "section element %s" % (i + 1))
     for i in range(0, 2):
         self.assertEqual(po.section_2.tokens[i].text,
                           "section element %s" % (i + 3))
     self.assertEqual(po.tokens[0].text, 'section element 1')
     self.assertEqual(po.tokens[1].text, 'section element 2')
     self.assertEqual(po.tokens[2].text, 'section element 3')
     self.assertEqual(po.tokens[3].text, 'section element 4')
Пример #8
0
    def test_fluent(self):
        class FluentPage(Page):
            thing = Element(Locators.NAME, "thing")

            def click_thing(self):
                self.thing.click()

            def get_thing(self):
                return self.thing
        page = "<div name='thing'>i am thing</div>"
        driver = get_driver()
        uri = make_temp_page(page)
        page = FluentPage(driver, uri)
        self.assertTrue(page.click_thing().get_thing().text, "i am thing")
Пример #9
0
    def test_basic_po_with_frame(self):
        frame1 = """"
        <html>
            <body>
                <div class='section'>
                    <div class='frame_el'>frame 1 el</div>
                </div>
            </body>
        </html>"
        """
        frame2 = """"
        <html>
            <body>
                <div class='section'>
                    <div class='frame_el'>frame 2 el</div>
                </div>
            </body>
        </html>
        """

        uri_frame_1 = make_temp_page(frame1)
        uri_frame_2 = make_temp_page(frame2)

        p1 = '''
        <html><body><iframe id="frame_1" src="%s"/></body></html>
        ''' % uri_frame_1
        p2 = '''
        <html>
            <body>
                <iframe id="frame_1" src="%s"></iframe>
                <iframe id="frame_2" src="%s"></iframe>
            </body>
        </html>
        ''' % (uri_frame_1, uri_frame_2)

        driver = get_driver()
        uri = make_temp_page(p1)
        with mock.patch("holmium.core.pageobject.log") as log:
            p = BasicPageIframe(driver, uri, iframe="frame_1")
            self.assertEqual(p.element.text, "frame 1 el")
            self.assertEqual(p.frame_1.element.text, "frame 1 el")
            self.assertTrue(p.frame_2.element is None)
            uri = make_temp_page(p2)
            driver.get(uri)
            self.assertTrue(p.frame_2.element is not None)
            self.assertEqual(p.frame_2.element.text, "frame 2 el")
            self.assertEqual(p.elements[0].text, "frame 1 el")
            self.assertEqual(log.error.call_count, 1)
Пример #10
0
 def test_basic_po_with_sections(self):
     driver = get_driver()
     page = """
     <body>
         <div class='section'>
             <div class='token'>
                 <div class='el'>
                     section element 1
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 2
                 </div>
             </div>
         </div>
         <div class='section'>
             <div class='token'>
                 <div class='el'>
                     section element 3
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 4
                 </div>
             </div>
         </div>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPageWithSections(driver, uri)
     counter = 1
     for section in po.sections:
         for token in section.tokens:
             self.assertEqual(token.text, "section element %s" % counter)
             counter += 1
     self.assertEqual(len(po.sections), 2)
     self.assertRaises(IndexError, lambda: po.sections[2])
     self.assertRaises(IndexError, lambda: po.missing_sections[0])
Пример #11
0
 def test_basic_po_with_sections(self):
     driver = get_driver()
     page = """
     <body>
         <div class='section'>
             <div class='token'>
                 <div class='el'>
                     section element 1
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 2
                 </div>
             </div>
         </div>
         <div class='section'>
             <div class='token'>
                 <div class='el'>
                     section element 3
                 </div>
             </div>
             <div class='token'>
                 <div class='el'>
                     section element 4
                 </div>
             </div>
         </div>
     </body>
     """
     uri = make_temp_page(page.strip())
     po = BasicPageWithSections(driver, uri)
     counter = 1
     for section in po.sections:
         for token in section.tokens:
             self.assertEqual(token.text, "section element %s" % counter)
             counter += 1
     self.assertEqual(len(po.sections), 2)
     self.assertRaises(IndexError, lambda: po.sections[2])
     self.assertRaises(IndexError, lambda: po.missing_sections[0])
Пример #12
0
    def test_basic_po_with_frame(self):
        frame1 = "<html><body><div class='section'><div class='frame_el'>frame 1 el</div></div></body></html>"
        frame2 = "<html><body><div class='section'><div class='frame_el'>frame 2 el</div></div></body></html>"

        uri_frame_1 = make_temp_page(frame1)
        uri_frame_2 = make_temp_page(frame2)

        p1 = '<html><body><iframe id="frame_1" src="%s"/></body></html>' % uri_frame_1
        p2 = '<html><body><iframe id="frame_1" src="%s"></iframe><iframe id="frame_2" src="%s"></iframe></body></html>' % ( uri_frame_1, uri_frame_2)

        driver = get_driver()
        uri = make_temp_page(p1)
        with mock.patch("holmium.core.pageobject.log") as log:
            p = BasicPageIframe(driver, uri, iframe="frame_1")
            self.assertEqual(p.element.text, "frame 1 el")
            self.assertEqual(p.frame_1.element.text, "frame 1 el")
            self.assertTrue(p.frame_2.element == None)
            uri = make_temp_page(p2)
            driver.get(uri)
            self.assertTrue(p.frame_2.element is not None)
            self.assertEqual(p.frame_2.element.text, "frame 2 el")
            self.assertEqual(p.elements[0].text, "frame 1 el")
            self.assertEqual(log.error.call_count, 1)
 def setUp(self):
     self.driver = get_driver()
Пример #14
0
 def setUp(self):
     self.driver = get_driver()
     self.uri = make_temp_page("<div id='simple_id'>default text</div>")
Пример #15
0
    def test_all_features(self):
        driver = get_driver()
        content = """
        <div name='e1'>e1</div>
        <div>
            <div name='e2'>e2 - 1
                <div name='e6'>e6</div>
            </div>
            <div name='e2'>e2 - 2</div>
        </div>
        <div>
            <div name='e3'>e3 - 1</div>
            <div name='e3'>e3 - 2</div>
        </div>
        <div name='e4'>e4</div>
        """
        uri = make_temp_page(content)

        driver.get(uri)
        # this may appear weird, but its to test the usecase of providing a WebElement
        # as a base_element. #fml.
        web_element = driver.find_element_by_name("e2")

        class ExhaustivePage(Page):
            element = Element(Locators.NAME, "e1")
            element_invalid = Element(Locators.NAME, "3e")
            elements = Elements(Locators.NAME, "e2")
            elements_invalid = Elements(Locators.NAME, "3e")
            elementmap = ElementMap(Locators.NAME, "e3")
            elementmap_for_ref = ElementMap(Locators.NAME, "e2")
            elementmap_invalid = ElementMap(Locators.NAME, "3e")
            elementmap_raw = {
                "e4": Element(Locators.NAME, "e4"),
                "e2": Elements(Locators.NAME, "e2"),
                "e3": ElementMap(Locators.NAME, "e3")
            }
            elements_raw = [
                Element(Locators.NAME, "e4"),
                Elements(Locators.NAME, "e2"),
                ElementMap(Locators.NAME, "e3")
            ]
            element_list_raw = [
                Element(Locators.NAME, "e4"),
                Element(Locators.NAME, "e6")
            ]
            element_map_raw = {
                "e4": Element(Locators.NAME, "e4"),
                "e6": Element(Locators.NAME, "e6")
            }
            element_second = Element(Locators.NAME, "e2")
            element_ref = Element(Locators.NAME,
                                  "e6",
                                  base_element=elements[0])
            element_map_ref = Element(
                Locators.NAME,
                "e6",
                base_element=elementmap_for_ref["e2 - 1\ne6"])
            element_ref_direct = Element(Locators.NAME,
                                         "e6",
                                         base_element=element_second)
            element_ref_webelement = Element(Locators.NAME,
                                             "e6",
                                             base_element=web_element)
            element_ref_invalid = Element(Locators.NAME, "e6", base_element=42)

        page = ExhaustivePage(driver)
        self.assertEqual(page.element.text, "e1")
        self.assertEqual([el.text for el in page.elements],
                         ["e2 - 1\ne6", "e2 - 2"])
        self.assertEqual([(k, k) for k in page.elementmap],
                         [("e3 - 1", "e3 - 1"), ("e3 - 2", "e3 - 2")])
        self.assertEqual([k.text for k in page.element_list_raw], ["e4", "e6"])
        self.assertEqual(
            sorted([k.text for k in page.element_map_raw.values()]),
            sorted(["e4", "e6"]))
        v1, v2 = page.element_map_raw.items()
        self.assertEquals(sorted([v1[0], v1[1].text, v2[0], v2[1].text]),
                          sorted(["e4", "e4", "e6", "e6"]))
        self.assertEqual(page.elements_raw[0].text, "e4")
        self.assertEqual([k.text for k in page.elements_raw[1]],
                         ["e2 - 1\ne6", "e2 - 2"])
        self.assertEqual([k.text for k in page.elements_raw[2].values()],
                         ["e3 - 1", "e3 - 2"])
        self.assertEqual(page.elementmap_raw["e4"].text, "e4")
        self.assertEqual([k.text for k in page.elementmap_raw["e2"]],
                         ["e2 - 1\ne6", "e2 - 2"])
        self.assertEqual([k.text for k in page.elementmap_raw["e3"].values()],
                         ["e3 - 1", "e3 - 2"])
        self.assertEqual(page.element_ref.text, "e6")
        self.assertEqual(page.element_ref_direct.text, "e6")
        self.assertEqual(page.element_ref_webelement.text, "e6")
        self.assertEqual(page.element_map_ref.text, "e6")
        self.assertRaises(TypeError, lambda: page.element_ref_invalid)
        self.assertEqual(page.element_invalid, None)
        self.assertEqual(page.elements_invalid, [])
        self.assertEqual(page.elementmap_invalid, {})
Пример #16
0
 def test_basic_po_real(self):
     driver = get_driver()
     uri = make_temp_page(
         """<body><div id='test_id'>test_text</div></body>""")
     po = PageTest.BasicPage(driver, uri)
     self.assertEqual(po.element.text, "test_text")
Пример #17
0
    def test_all_features(self):
        driver = get_driver()
        content = """
        <div name='e1'>e1</div>
        <div>
            <div name='e2'>e2 - 1
                <div name='e6'>e6</div>
            </div>
            <div name='e2'>e2 - 2</div>
        </div>
        <div>
            <div name='e3'>e3 - 1</div>
            <div name='e3'>e3 - 2</div>
        </div>
        <div name='e4'>e4</div>
        """
        uri = make_temp_page(content)

        driver.get(uri)
        # this may appear weird, but its to test the usecase of providing a WebElement
        # as a base_element. #fml.
        web_element = driver.find_element_by_name("e2")


        class ExhaustivePage(Page):
            element = Element(Locators.NAME, "e1")
            element_invalid = Element(Locators.NAME, "3e")
            elements = Elements(Locators.NAME, "e2")
            elements_invalid = Elements(Locators.NAME, "3e")
            elementmap = ElementMap(Locators.NAME, "e3")
            elementmap_for_ref = ElementMap(Locators.NAME, "e2")
            elementmap_invalid = ElementMap(Locators.NAME, "3e")
            elementmap_raw = { "e4": Element(Locators.NAME, "e4")
                            , "e2": Elements(Locators.NAME, "e2")
                            , "e3": ElementMap(Locators.NAME, "e3")
                            }
            elements_raw = [ Element(Locators.NAME, "e4")
                            , Elements(Locators.NAME, "e2")
                            , ElementMap(Locators.NAME, "e3")
                            ]
            element_list_raw = [
                Element(Locators.NAME, "e4"),
                Element(Locators.NAME, "e6")
            ]
            element_map_raw = {
                "e4":Element(Locators.NAME, "e4"),
                "e6":Element(Locators.NAME, "e6")
            }
            element_second = Element(Locators.NAME, "e2")
            element_ref = Element( Locators.NAME, "e6", base_element = elements[0] )
            element_map_ref = Element( Locators.NAME, "e6", base_element = elementmap_for_ref["e2 - 1\ne6"] )
            element_ref_direct = Element( Locators.NAME, "e6", base_element = element_second )
            element_ref_webelement = Element( Locators.NAME, "e6", base_element = web_element )
            element_ref_invalid = Element( Locators.NAME, "e6", base_element = 42 )

        page = ExhaustivePage(driver)
        self.assertEqual( page.element.text, "e1" )
        self.assertEqual( [el.text for el in page.elements], ["e2 - 1\ne6", "e2 - 2"] )
        self.assertEqual( [(k, k) for k in page.elementmap], [("e3 - 1","e3 - 1"), ("e3 - 2", "e3 - 2")])
        self.assertEqual( [k.text for k in page.element_list_raw], ["e4", "e6"])
        self.assertEqual( sorted([k.text for k in page.element_map_raw.values()]), sorted(["e4", "e6"]))
        v1, v2 = page.element_map_raw.items()
        self.assertEquals(sorted([v1[0], v1[1].text, v2[0], v2[1].text]), sorted(["e4","e4", "e6", "e6"]))
        self.assertEqual( page.elements_raw[0].text, "e4" )
        self.assertEqual( [k.text for k in page.elements_raw[1]], ["e2 - 1\ne6","e2 - 2"])
        self.assertEqual( [k.text for k in page.elements_raw[2].values()], ["e3 - 1","e3 - 2"])
        self.assertEqual( page.elementmap_raw["e4"].text, "e4" )
        self.assertEqual( [k.text for k in page.elementmap_raw["e2"]], ["e2 - 1\ne6", "e2 - 2"])
        self.assertEqual( [k.text for k in page.elementmap_raw["e3"].values()], ["e3 - 1","e3 - 2"])
        self.assertEqual( page.element_ref.text, "e6" )
        self.assertEqual( page.element_ref_direct.text, "e6" )
        self.assertEqual( page.element_ref_webelement.text, "e6" )
        self.assertEqual( page.element_map_ref.text, "e6")
        self.assertRaises( TypeError, lambda: page.element_ref_invalid)
        self.assertEqual( page.element_invalid , None)
        self.assertEqual( page.elements_invalid, [])
        self.assertEqual(page.elementmap_invalid, {})
Пример #18
0
 def test_basic_po_real(self):
     driver = get_driver()
     uri = make_temp_page("""<body><div id='test_id'>test_text</div></body>""")
     po = PageTest.BasicPage(driver, uri)
     self.assertEqual(po.element.text, "test_text")
Пример #19
0
 def setUp(self):
     self.driver = get_driver()
Пример #20
0
 def setUp(self):
     super(FacetsTests, self).setUp()
     self.driver = get_driver()
     self.base_url = self.get_server_url()
 def setUp(self):
     self.driver = get_driver()
     self.uri = make_temp_page("<div id='simple_id'>default text</div>")