示例#1
0
def field(field_name):
    """
    Return the locator for any field displayed on a django model form.

    :param field_name: name of the field
    :return: the locator for the field with the corresponding name
    """
    return Locate.by_name(field_name)
示例#2
0
def field_error(field_name):
    """
    Return the locator for the error message associated with a model field widget.

    :param field_name: name of the field
    :return: the locator for the field error associated with the field
    """
    return Locate.by_css("#id_{}_container .errors .error".format(field_name))
示例#3
0
def material_design_dropdown(field_name):
    """
    The material design dropdown menu is implemented with a ul/li structure.  The <select> and <option> elements are
    hidden.  This prevents Selenium from interacting with them.

    This method provides you with the locator for the input field (which a user would normally click).

    :param field_name: name attribute of the form field
    """
    return Locate.by_xpath(
        "//div[@id='id_{}_container']//input".format(field_name))
示例#4
0
def material_design_dropdown_option(field_name, option_text):
    """
    The material design dropdown menu is implemented with a ul/li structure.  The <select> and <option> elements are
    hidden.  This prevents Selenium from interacting with them.

    This method provides you with the locator for the list elements (which a user would normally click after selecting
    the input field).

    :param field_name: name attribute of the form field
    :param option_text: the text of the option that should be located
    """
    return Locate.by_xpath(
        "//div[@id='id_{}_container']//ul//span[contains(., '{}')]".format(
            field_name, option_text))
示例#5
0
 def test_class_constructed_with_locator_and_strategy(self):
     """
     Clear question can be constructed either: directly, using class methods
     """
     examples = {
         "class constructed with constructor":
         Class("element", strategy=By.CSS_SELECTOR),
         "class constructed using class method, text and strategy":
         Class.on("element"),
         "class constructed using class method and Locator":
         Class.on(Locate.by_css("element"))
     }
     for desc, classs in examples.items():
         with self.subTest(desc):
             self.assertEqual(classs.locator, "element")
             self.assertEqual(classs.strategy, By.CSS_SELECTOR)
示例#6
0
    def test_each_class_sets_correct_strategy(self):
        """
        Each of the typed locator classes correctly define their locating strategy and locator
        """
        locator = '#my_button'

        examples = {
            Locate.by_class_name(locator): By.CLASS_NAME,
            Locate.by_css(locator): By.CSS_SELECTOR,
            Locate.by_id(locator): By.ID,
            Locate.by_link_text(locator): By.LINK_TEXT,
            Locate.by_name(locator): By.NAME,
            Locate.by_partial_link_text(locator): By.PARTIAL_LINK_TEXT,
            Locate.by_tag_name(locator): By.TAG_NAME,
            Locate.by_xpath(locator): By.XPATH
        }

        for locate, strat in examples.items():
            with self.subTest(locate.__str__()):
                self.assertEqual(locate.strategy, strat)
                self.assertEqual(locate.locator, locator)
示例#7
0
from screenpy.web.locators import Locate

featured_story = Locate.by_css(
    ".distinct-component-group.container-buzzard .title-link h3")
示例#8
0
from screenpy.web.locators import Locate

heading = Locate.by_css(".story-body__h1")
示例#9
0
def _nav_locator(text):
    return Locate.by_css('nav li.orb-nav-{}'.format(text))
示例#10
0
from screenpy.web.locators import Locate


def _nav_locator(text):
    return Locate.by_css('nav li.orb-nav-{}'.format(text))


news = _nav_locator('news')
sport = _nav_locator('sport')
weather = _nav_locator('weather')

search = Locate.by_id('orb-search-q')
示例#11
0
 def nav_link(text):
     return Locate.by_xpath("//nav[@class='nw-c-nav__wide']//span[text()='{}']/parent::a".format(text))
示例#12
0
 def heading():
     return Locate.by_css('header #brand span.gs-u-vh')
示例#13
0
from screenpy.web.locators import Locate


sport = Locate.by_class_name('global-header__logo')
weather = Locate.by_css('.wr-c-masthead foreignObject')


class News:

    @staticmethod
    def heading():
        return Locate.by_css('header #brand span.gs-u-vh')

    @staticmethod
    def nav_link(text):
        return Locate.by_xpath("//nav[@class='nw-c-nav__wide']//span[text()='{}']/parent::a".format(text))
示例#14
0
from screenpy.web.locators import Locate


def field(field_name):
    """
    Return the locator for any field displayed on a django model form.

    :param field_name: name of the field
    :return: the locator for the field with the corresponding name
    """
    return Locate.by_name(field_name)


def field_error(field_name):
    """
    Return the locator for the error message associated with a model field widget.

    :param field_name: name of the field
    :return: the locator for the field error associated with the field
    """
    return Locate.by_css("#id_{}_container .errors .error".format(field_name))


submit = Locate.by_css("button[type='submit']")