Beispiel #1
0
 def test_plural_or_not(self):
     for singular in [1, -1, (2,), ['foo'], {'key': 'value'}, 'x']:
         assert_equal(plural_or_not(singular), '')
     for plural in [0, 2, -2, 42,
                    (), [], {},
                    (1, 2, 3), ['a', 'b'], {'a': 1, 'b': 2},
                    '', 'xx', 'Hello, world!']:
         assert_equal(plural_or_not(plural), 's')
 def _validate_no_named_only_missing(self, named, spec):
     defined = set(named) | set(spec.defaults)
     missing = [arg for arg in spec.kwonlyargs if arg not in defined]
     if missing:
         raise DataError("%s '%s' missing named-only argument%s %s." %
                         (spec.type, spec.name, plural_or_not(missing),
                          seq2str(sorted(missing))))
 def _validate_no_named_only_missing(self, named, spec):
     defined = set(named) | set(spec.defaults)
     missing = [arg for arg in spec.named_only if arg not in defined]
     if missing:
         self._raise_error(
             "missing named-only argument%s %s" %
             (plural_or_not(missing), seq2str(sorted(missing))))
Beispiel #4
0
    def wait_until_page_does_not_contain_element(self,
                                                 locator,
                                                 timeout=None,
                                                 error=None,
                                                 limit=None):
        """Waits until the element ``locator`` disappears from the current page.

        Fails if ``timeout`` expires before the element disappears. See
        the `Timeouts` section for more information about using timeouts and
        their default value and the `Locating elements` section for details
        about the locator syntax.

        ``error`` can be used to override the default error message.

        The ``limit`` argument can used to define how many elements the
        page should not contain. When ``limit`` is `None` (default) page can`t
        contain any elements. When limit is a number, page must not
        contain same number of elements.

        ``limit`` is new in SeleniumLibrary 5.0
        """
        if is_noney(limit):
            self._wait_until(
                lambda: self.find_element(locator, required=False) is None,
                "Element '%s' did not disappear in <TIMEOUT>." % locator,
                timeout, error)
        else:
            limit = int(limit)
            self._wait_until(
                lambda: len(self.find_elements(locator)) != limit,
                'Page should not have contained "%s" element%s but had "%s" using locator "%s" within <TIMEOUT>.'
                % (limit, plural_or_not(limit), len(
                    self.find_elements(locator)), locator), timeout, error)
Beispiel #5
0
 def _press_keys_normal_keys(self, actions, element, key):
     self.info('Sending key%s %s' %
               (plural_or_not(key.converted), key.converted))
     if element:
         actions.send_keys_to_element(element, key.converted)
     else:
         actions.send_keys(key.converted)
Beispiel #6
0
 def start_suite(self, suite):
     if not suite.parent:
         self._stdout.write(
             "Running suite '%s' with %d %s%s.\n" %
             (suite.name, suite.test_count, 'test' if not suite.rpa else
              'task', plural_or_not(suite.test_count)))
         self._stdout.write('=' * self._width + '\n')
 def _validate_no_extra_named(self, named, spec):
     if not spec.kwargs:
         extra = set(named) - set(spec.positional) - set(spec.kwonlyargs)
         if extra:
             raise DataError("%s '%s' got unexpected named argument%s %s."
                             % (spec.type, spec.name, plural_or_not(extra),
                                seq2str(sorted(extra))))
 def _validate_no_named_only_missing(self, named, spec):
     defined = set(named) | set(spec.defaults)
     missing = [arg for arg in spec.kwonlyargs if arg not in defined]
     if missing:
         raise DataError("%s '%s' missing named-only argument%s %s."
                         % (spec.type, spec.name, plural_or_not(missing),
                            seq2str(sorted(missing))))
 def _validate_no_extra_named(self, named, spec):
     if not spec.kwargs:
         extra = set(named) - set(spec.positional) - set(spec.kwonlyargs)
         if extra:
             raise DataError("%s '%s' got unexpected named argument%s %s." %
                             (spec.type, spec.name, plural_or_not(extra),
                              seq2str(sorted(extra))))
Beispiel #10
0
 def _js_logger(self, base, code, args):
     message = '%s:\n%s\n' % (base, code)
     if args:
         message = ('%sBy using argument%s:\n%s' %
                    (message, plural_or_not(args), seq2str(args)))
     else:
         message = '%sWithout any arguments.' % message
     self.info(message)
 def _validate_no_extra_named(self, named, spec):
     if not spec.var_named:
         extra = set(named) - set(spec.positional_or_named) - set(
             spec.named_only)
         if extra:
             self._raise_error(
                 "got unexpected named argument%s %s" %
                 (plural_or_not(extra), seq2str(sorted(extra))))
 def _js_logger(self, base, code, args):
     message = '%s:\n%s\n' % (base, code)
     if args:
         message = ('%sBy using argument%s:\n%s'
                    % (message, plural_or_not(args), seq2str(args)))
     else:
         message = '%sWithout any arguments.' % message
     self.info(message)
Beispiel #13
0
 def _replace_vars_from_items(self, variables):
     items = variables.replace_list(self.items)
     if self.range:
         items = self._get_range_items(items)
     if len(items) % len(self.vars) == 0:
         return items
     raise DataError('Number of FOR loop values should be multiple of '
                     'variables. Got %d variables but %d value%s.' %
                     (len(self.vars), len(items), plural_or_not(items)))
Beispiel #14
0
 def _raise_inv_args(self, arg_count):
     minend = utils.plural_or_not(self.minargs)
     if self.minargs == self.maxargs:
         exptxt = "%d argument%s" % (self.minargs, minend)
     elif self.maxargs != sys.maxint:
         exptxt = "%d to %d arguments" % (self.minargs, self.maxargs)
     else:
         exptxt = "at least %d argument%s" % (self.minargs, minend)
     raise DataError("%s '%s' expected %s, got %d." % (self._type, self._name, exptxt, arg_count))
Beispiel #15
0
 def _raise_creating_instance_failed(self):
     msg, details = utils.get_error_details()
     if self.positional_args:
         args = "argument%s %s" % (utils.plural_or_not(self.positional_args),
                                   utils.seq2str(self.positional_args))
     else:
         args = "no arguments"
     raise DataError("Creating an instance of the test library '%s' with %s "
                     "failed: %s\n%s" % (self.name, args, msg, details))
Beispiel #16
0
 def report(self, suite):
     suite.visit(self)
     stats = suite.statistics
     self._stream.write("%s\nRun suite '%s' with %d test%s in %s.\n\n" %
                        ('=' * self._width, suite.name, stats.all.total,
                         plural_or_not(stats.all.total),
                         secs_to_timestr(suite.elapsedtime / 1000.0)))
     self._stream.highlight(suite.status + 'ED', suite.status)
     self._stream.write('\n%s\n' % stats.message)
 def _replace_vars_from_items(self, variables):
     items = variables.replace_list(self.items)
     if self.range:
         items = self._get_range_items(items)
     if len(items) % len(self.vars) == 0:
         return items
     raise DataError('Number of FOR loop values should be multiple of '
                     'variables. Got %d variables but %d value%s.'
                     % (len(self.vars), len(items), plural_or_not(items)))
Beispiel #18
0
 def report(self, suite):
     suite.visit(self)
     stats = suite.statistics
     self._stream.write("%s\nRun suite '%s' with %d test%s in %s.\n\n"
                        % ('=' * self._width, suite.name,
                           stats.all.total, plural_or_not(stats.all.total),
                           secs_to_timestr(suite.elapsedtime/1000.0)))
     self._stream.highlight(suite.status + 'ED', suite.status)
     self._stream.write('\n%s\n' % stats.message)
 def _raise_inv_args(self, arg_count):
     minend = utils.plural_or_not(self.minargs)
     if self.minargs == self.maxargs:
         exptxt = "%d argument%s" % (self.minargs, minend)
     elif self.maxargs != sys.maxint:
         exptxt = "%d to %d arguments" % (self.minargs, self.maxargs)
     else:
         exptxt = "at least %d argument%s" % (self.minargs, minend)
     raise DataError("%s '%s' expected %s, got %d." %
                     (self._type, self._name, exptxt, arg_count))
Beispiel #20
0
 def remove_tags(self,*tags):
     ctx = self._context
     if ctx.test:
         ctx.test.tags.remove(tags)
         ctx.variables.set_test('@{TEST-tags}',list(ctx.test.tags))
     elif not ctx.in_suite_teardown:
         ctx.suite.set_tags(remove=tags,persist=True)
     else:
         raise RuntimeError("'remove tags' cannot be used in suite teardown.")
     self.log('removed tag%s' %(utils.plural_or_not(tags)))
Beispiel #21
0
 def _raise_creating_instance_failed(self):
     msg, details = utils.get_error_details()
     if self.positional_args:
         args = "argument%s %s" % (utils.plural_or_not(
             self.positional_args), utils.seq2str(self.positional_args))
     else:
         args = "no arguments"
     raise DataError(
         "Creating an instance of the test library '%s' with %s "
         "failed: %s\n%s" % (self.name, args, msg, details))
 def _raise_wrong_count(self, count, spec):
     minend = plural_or_not(spec.minargs)
     if spec.minargs == spec.maxargs:
         expected = '%d argument%s' % (spec.minargs, minend)
     elif not spec.var_positional:
         expected = '%d to %d arguments' % (spec.minargs, spec.maxargs)
     else:
         expected = 'at least %d argument%s' % (spec.minargs, minend)
     if spec.var_named or spec.named_only:
         expected = expected.replace('argument', 'non-named argument')
     self._raise_error("expected %s, got %d" % (expected, count))
Beispiel #23
0
 def set_tags(self,*tags):
     ctx = self._context
     if ctx.test:
         ctx.test.tags.add(tags)
         ctx.variables.set_test('@{TEST_TAGS}',list(ctx.test.tags))
     elif not ctx.in_suite_teardown:
         ctx.cuit.set_tags(tags,persist=True)
     else:
         raise RuntimeError(" 'set tags' cannot be used in suite teardown.")
     self.log('set tags%s %s.' %(utils.plural_or_not(tags),
                                 utils.seq2str(tags)))
 def _raise_wrong_count(self, count, spec):
     minend = plural_or_not(spec.minargs)
     if spec.minargs == spec.maxargs:
         expected = "%d argument%s" % (spec.minargs, minend)
     elif not spec.varargs:
         expected = "%d to %d arguments" % (spec.minargs, spec.maxargs)
     else:
         expected = "at least %d argument%s" % (spec.minargs, minend)
     if spec.kwargs:
         expected = expected.replace("argument", "non-keyword argument")
     raise DataError("%s '%s' expected %s, got %d." % (spec.type, spec.name, expected, count))
Beispiel #25
0
 def report(self, suite):
     suite.visit(self)
     stats = suite.statistics
     self._stream.write(
         "%s\nRun suite '%s' with %d %s%s in %s.\n\n" %
         ('=' * self._width, suite.name, stats.total,
          'test' if not suite.rpa else 'task', plural_or_not(
              stats.total), secs_to_timestr(suite.elapsedtime / 1000.0)))
     self._stream.highlight(
         suite.status + ('PED' if suite.status == 'SKIP' else 'ED'),
         suite.status)
     self._stream.write('\n%s\n' % stats.message)
 def _raise_wrong_count(self, count, spec):
     minend = plural_or_not(spec.minargs)
     if spec.minargs == spec.maxargs:
         expected = '%d argument%s' % (spec.minargs, minend)
     elif not spec.varargs:
         expected = '%d to %d arguments' % (spec.minargs, spec.maxargs)
     else:
         expected = 'at least %d argument%s' % (spec.minargs, minend)
     if spec.kwargs or spec.kwonlyargs:
         expected = expected.replace('argument', 'non-named argument')
     raise DataError("%s '%s' expected %s, got %d."
                     % (spec.type, spec.name, expected, count))
Beispiel #27
0
 def _raise_wrong_count(self, count, spec):
     minend = plural_or_not(spec.minargs)
     if spec.minargs == spec.maxargs:
         expected = '%d argument%s' % (spec.minargs, minend)
     elif not spec.varargs:
         expected = '%d to %d arguments' % (spec.minargs, spec.maxargs)
     else:
         expected = 'at least %d argument%s' % (spec.minargs, minend)
     if spec.kwargs:
         expected = expected.replace('argument', 'non-keyword argument')
     raise DataError("%s '%s' expected %s, got %d." %
                     (spec.type, spec.name, expected, count))
Beispiel #28
0
 def get_count(self,item1,item2):
     if not hasattr(item1,'count'):
         try:
             item1 = list(item1)
         except:
             raise RuntimeError("Converting '%s' to list failed: %s"
                                %(item1,utils.get_error_message()))
         count = item1.count(item2)
         self.log('Item found from the first item %d time%s'
                  %(count,utils.plural_or_not(count))
                  )
         return count
    def remove_duplicates(self, list_):
        """Returns a list without duplicates based on the given ``list``.

        Creates and returns a new list that contains all items in the given
        list so that one item can appear only once. Order of the items in
        the new list is the same as in the original except for missing
        duplicates. Number of the removed duplicates is logged.
        """
        self._validate_list(list_)
        ret = []
        for item in list_:
            if item not in ret:
                ret.append(item)
        removed = len(list_) - len(ret)
        logger.info('%d duplicate%s removed.' % (removed, plural_or_not(removed)))
        return ret
Beispiel #30
0
    def remove_duplicates(self, list_):
        """Returns a list without duplicates based on the given ``list``.

        Creates and returns a new list that contains all items in the given
        list so that one item can appear only once. Order of the items in
        the new list is the same as in the original except for missing
        duplicates. Number of the removed duplicates is logged.
        """
        self._validate_list(list_)
        ret = []
        for item in list_:
            if item not in ret:
                ret.append(item)
        removed = len(list_) - len(ret)
        logger.info('%d duplicate%s removed.' % (removed, plural_or_not(removed)))
        return ret
Beispiel #31
0
 def _get_counts(self, stat):
     ending = utils.plural_or_not(stat.total)
     return stat.total, ending, stat.passed, stat.failed
Beispiel #32
0
 def _press_keys_normal_keys(self, actions, key):
     self.info("Sending key%s %s" % (plural_or_not(key.converted), key.converted))
     actions.send_keys(key.converted)
 def set_if_removed(self, kw, len_before):
     removed = len_before - len(kw.keywords)
     if removed:
         self.set(kw, self._message % (removed, plural_or_not(removed)))
 def _validate_no_named_only_missing(self, named, spec):
     missing = set(spec.reqkwargs) - set(named)
     if missing:
         raise DataError("%s '%s' missing named-only argument%s %s." %
                         (spec.type, spec.name, plural_or_not(missing),
                          seq2str(sorted(missing))))
Beispiel #35
0
 def _get_msg(self, passed, failed):
     total = passed + failed
     class_ = failed > 0 and ' class="fail"' or ''
     return '%d test%s, %d passed, <span%s>%d failed</span>' \
            % (total, utils.plural_or_not(total), passed, class_, failed)
 def _press_keys_normal_keys(self, actions, element, key):
     self.info('Sending key%s %s' % (plural_or_not(key.converted), key.converted))
     if element:
         actions.send_keys_to_element(element, key.converted)
     else:
         actions.send_keys(key.converted)
Beispiel #37
0
 def _get_counts(self, stat):
     ending = utils.plural_or_not(stat.total)
     return stat.total, ending, stat.passed, stat.failed
Beispiel #38
0
 def _get_counts(self, stat):
     total = stat.passed + stat.failed
     ending = utils.plural_or_not(total)
     return total, ending, stat.passed, stat.failed
Beispiel #39
0
 def _get_counts(self, stat):
     total = stat.passed + stat.failed
     ending = utils.plural_or_not(total)
     return total, ending, stat.passed, stat.failed
 def _get_msg(self, passed, failed):
     total = passed + failed
     class_ = failed > 0 and ' class="fail"' or ''
     return '%d test%s, %d passed, <span%s>%d failed</span>' \
            % (total, utils.plural_or_not(total), passed, class_, failed)
Beispiel #41
0
 def set_if_removed(self, kw, len_before):
     removed = len_before - len(kw.keywords)
     if removed:
         self.set(kw, self._message % (removed, plural_or_not(removed)))