Example #1
0
 def test_removes_added_selector(self):
     assert "custom_selector" not in selectors
     with add_selector("custom_selector"):
         pass
     assert "custom_selector" in selectors
     remove_selector("custom_selector")
     assert "custom_selector" not in selectors
Example #2
0
    def test_allows_custom_matcher_using_css(self, string):
        with add_selector("section") as s:
            s.css = lambda css_class: "section .{}".format(css_class)

        assert string.has_selector("section", "subsection")
        assert not string.has_selector("section", "section_8")

        remove_selector("section")
Example #3
0
    def test_css_decorator_with_parens_sets_css_query_function(self):
        with add_selector("custom_selector") as s:

            @s.css()
            def css(id):
                return "h1#{}".format(id)

        selector = selectors["custom_selector"]
        assert selector("foo") == "h1#foo"
Example #4
0
    def test_xpath_decorator_with_parens_sets_xpath_query_function(self):
        with add_selector("custom_selector") as s:

            @s.xpath()
            def xpath(id):
                return ".//h1[./@id = '{}']".format(id)

        selector = selectors["custom_selector"]
        assert selector("foo") == ".//h1[./@id = 'foo']"
Example #5
0
    def test_uses_a_custom_selector(self, session):
        with add_selector("level") as s:
            @s.xpath
            def xpath(num):
                return ".//*[@id='ancestor{num}']".format(num=num)

        el = session.find("css", "#child")
        assert el.ancestor("level", 1).text == "Ancestor Child"
        assert el.ancestor("level", 3).text == "Ancestor Ancestor Ancestor Child"
Example #6
0
    def test_uses_a_custom_selector(self, session):
        with add_selector("data_attribute") as s:

            @s.xpath
            def xpath(attr):
                return ".//*[@data-{}]".format(attr)

        el = session.find("css", "#mid_sibling")
        assert el.sibling("data_attribute", "pre").has_text("Pre Sibling")
        assert el.sibling("data_attribute", "post").has_text("Post Sibling")
Example #7
0
    def test_allows_using_custom_matchers(self, string):
        with add_selector("lifeform") as s:
            s.xpath = lambda name: "//option[contains(.,'{}')]".format(name)

        assert string.has_selector("id", "page")
        assert not string.has_selector("id", "does-not-exist")
        assert string.has_selector("lifeform", "Monkey")
        assert not string.has_selector("lifeform", "Gorilla")

        remove_selector("lifeform")
Example #8
0
    def test_uses_a_custom_selector(self, session):
        with add_selector("beatle") as s:
            s.xpath = lambda name: ".//*[@id='{}']".format(name)

        assert session.find("beatle", "john").text == "John"
        assert session.find("beatle", "paul").text == "Paul"
Example #9
0
 def test_css_assignment_sets_css_query_function(self):
     with add_selector("custom_selector") as s:
         s.css = lambda id: "h1#{}".format(id)
     selector = selectors["custom_selector"]
     assert selector("foo") == "h1#foo"
Example #10
0
 def test_xpath_assignment_sets_xpath_query_function(self):
     with add_selector("custom_selector") as s:
         s.xpath = lambda id: ".//h1[./@id = '{}']".format(id)
     selector = selectors["custom_selector"]
     assert selector("foo") == ".//h1[./@id = 'foo']"
Example #11
0
 def test_label_assignment_sets_label(self):
     with add_selector("custom_selector") as s:
         s.label = "My Custom Selector"
     selector = selectors["custom_selector"]
     assert selector.label == "My Custom Selector"
Example #12
0
 def test_sets_name(self):
     with add_selector("custom_selector"):
         pass
     selector = selectors["custom_selector"]
     assert selector.name == "custom_selector"