Exemple #1
0
def _get_element(finder_function,
                 first,
                 last,
                 pattern,
                 expect_not_to_find=False,
                 leave_in_list=False):

    ele = world.browser.__getattribute__(finder_function)(pattern)

    try:
        if first:
            ele = ele.first
        if last:
            ele = ele.last

        if not "WebDriverElement" in "%s" % type(ele):
            if len(ele) > 1:
                logger.warn(
                    "More than one element found when looking for %s for %s.  Using the first one. "
                    % (finder_function, pattern))

            if not leave_in_list:
                ele = ele.first

    except ElementDoesNotExist:
        if not expect_not_to_find:
            logger.error("Element not found: %s for %s" %
                         (finder_function, pattern))
        raise ElementDoesNotExist

    world.current_element = ele
    return ele
Exemple #2
0
        def _polling_assertion_step(step, negate, pick, find_pattern, *args):
            wait_time = int(args[-1] or 0)
            args = args[:-1]  # Chop off the wait_time arg

            waiter = SaladWaiter(wait_time, ignored_exceptions=AssertionError)
            try:
                waiter.until(self.check_element, finder_function, negate, pick,
                             find_pattern, wait_time, *args)
            except TimeoutException as t:
                # BEWARE: only way to get step regular expression
                expression, func = step._get_match()
                logger.error(t.message)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                message = ("Element not found or assertion failed using "
                           "pattern '%s' after %s seconds" %
                           (find_pattern, wait_time))
                raise AssertionError(message)
            except Exception as error:
                # BEWARE: only way to get step regular expression
                expression, func = step._get_match()
                logger.error("%s" % error)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                raise
Exemple #3
0
        def _polling_assertion_step(step, negate, pick, find_pattern, *args):
            wait_time = int(args[-1] or 0)
            args = args[:-1]  # Chop off the wait_time arg

            waiter = SaladWaiter(wait_time, ignored_exceptions=AssertionError)
            try:
                waiter.until(self.check_element, finder_function,
                             negate, pick, find_pattern, wait_time, *args)
            except TimeoutException as t:
                # BEWARE: only way to get step regular expression
                expression, func = step._get_match()
                logger.error(t.message)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                message = ("Element not found or assertion failed using "
                           "pattern '%s' after %s seconds" %
                           (find_pattern, wait_time))
                raise AssertionError(message)
            except Exception as error:
                # BEWARE: only way to get step regular expression
                expression, func = step._get_match()
                logger.error("%s" % error)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                raise
Exemple #4
0
def create_page_object(page):
    # Check if already created
    if page in leaf_world.pages:
        return leaf_world.pages[page]

    if page not in leaf_world.available_pages:
        raise KeyError('"%s" page is undefined.' % page)

    try:
        page_class = leaf_world.available_pages[page]
    except KeyError:
        logger.error(' "%s" page is undefined.' % page)
        return None

    page_object = page_class()

    leaf_world.pages.update({
        page: page_object
    })

    return page_object
Exemple #5
0
def _get_element(finder_function, first, last, pattern, expect_not_to_find=False, leave_in_list=False):

    ele = world.browser.__getattribute__(finder_function)(pattern)

    try:
        if first:
            ele = ele.first
        if last:
            ele = ele.last

        if not "WebDriverElement" in "%s" % type(ele):
            if len(ele) > 1:
                logger.warn("More than one element found when looking for %s for %s.  Using the first one. " % (finder_function, pattern))

            if not leave_in_list:
                ele = ele.first

    except ElementDoesNotExist:
            if not expect_not_to_find:
                logger.error("Element not found: %s for %s" % (finder_function, pattern))
            raise ElementDoesNotExist

    world.current_element = ele
    return ele
Exemple #6
0
        def _dynamic_step(step, negate, element_name, *args):
            wait_time = int(args[-1] or 0)
            args = args[:-1]  # Chop off the wait_time arg

            waiter = SaladWaiter(wait_time, ignored_exceptions=AssertionError)
            try:
                waiter.until(self._execute, negate, element_name,
                             wait_time, *args)
            except TimeoutException as t:
                expression, func = step._get_match()
                logger.error(t.message)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                message = ("Element not found or assertion failed after %s seconds" % wait_time)
                raise AssertionError(message)
            except Exception as error:
                # BEWARE: only way to get step regular expression
                expression, func = step._get_match()
                logger.error("%s" % error)
                logger.error("Encountered error using definition '%s'" %
                             expression.re.pattern)
                raise