コード例 #1
0
ファイル: Telnet.py プロジェクト: laxmanCT/robotframework
    def read_until_regexp(self, *expected):
        """Reads from the current output, until a match to a regexp in expected.

        Expected is a list of regular expression patterns as strings,
        or compiled regular expressions. The keyword returns the text
        up to and including the first match to any of the regular
        expressions.

        If the last argument in `*expected` is a valid log level, it
        is used as `loglevel` in the keyword `Read`.

        Examples:
        | Read Until Regexp | (#|$) |
        | Read Until Regexp | first_regexp | second_regexp |
        | Read Until Regexp | some regexp  | DEBUG |
        """
        expected = list(expected)
        if self._is_valid_log_level(expected[-1]):
            loglevel = expected[-1]
            expected = expected[:-1]
        else:
            loglevel = 'INFO'
        try:
            index, _, ret = self.expect(expected, self._timeout)
        except TypeError:
            index, ret = -1, ''
        ret = ret.decode('ASCII', 'ignore')
        self._log(ret, loglevel)
        if index == -1:
            expected = [ exp if isinstance(exp, basestring) else exp.pattern
                         for exp in expected ]
            raise AssertionError("No match found for %s in %s"
                                 % (utils.seq2str(expected, lastsep=' or '),
                                    utils.secs_to_timestr(self._timeout)))
        return ret
コード例 #2
0
ファイル: Telnet.py プロジェクト: IlfirinPL/RIDE
    def read_until_regexp(self, *expected):
        """Reads from the current output, until a match to a regexp in expected.

        Expected is a list of regular expression patterns as strings,
        or compiled regular expressions. The keyword returns the text
        up to and including the first match to any of the regular
        expressions.

        If the last argument in `*expected` is a valid log level, it
        is used as `loglevel` in the keyword `Read`.

        Examples:
        | Read Until Regexp | (#|$) |
        | Read Until Regexp | first_regexp | second_regexp |
        | Read Until Regexp | some regexp  | DEBUG |
        """
        expected = list(expected)
        if self._is_valid_log_level(expected[-1]):
            loglevel = expected[-1]
            expected = expected[:-1]
        else:
            loglevel = 'INFO'
        try:
            index, _, ret = self.expect(expected, self._timeout)
        except TypeError:
            index, ret = -1, ''
        ret = ret.decode('ASCII', 'ignore')
        self._log(ret, loglevel)
        if index == -1:
            expected = [ exp if isinstance(exp, basestring) else exp.pattern
                         for exp in expected ]
            raise AssertionError("No match found for %s in %s"
                                 % (utils.seq2str(expected, lastsep=' or '),
                                    utils.secs_to_timestr(self._timeout)))
        return ret
コード例 #3
0
 def _wait_until(self, timeout, error, function, *args):
     timeout = self._get_timeout(timeout)
     error = error % {'TIMEOUT': utils.secs_to_timestr(timeout)}
     maxtime = time.time() + timeout
     while not function(*args):
         if time.time() > maxtime:
             raise AssertionError(error)
         time.sleep(0.2)
コード例 #4
0
ファイル: BuiltIn.py プロジェクト: zbzzbd/rbot_srcCode_copy
 def sleep(self,time_,reason=None):
     seconds = utils.timestr_to_secs(time_)
     if seconds <0:
         seconds =0
     self._sleep_in_parts(seconds)
     self.log('Slept %s' %utils.secs_to_timestr(seconds))
     if reason:
         self.log(reason)
コード例 #5
0
 def _wait_until_keyword_returns_true(self, timeout, retry_interval, name, *args):
     """Helper method for wait_until_page_contains"""
     timeout = timestr_to_secs(timeout)
     retry_interval = timestr_to_secs(retry_interval)
     starttime = time.time()
     while time.time() - starttime < timeout:
         try:
             self._info("Waiting %s for condition '%s' to be true." 
                 % (secs_to_timestr(timestr_to_secs(retry_interval)), args[0]))  
             if not BuiltIn.run_keyword(BuiltIn(), name, *args):
                 time.sleep(retry_interval)
             else:
                 self._info("Return True in '%s' " % (secs_to_timestr(time.time() - timestr_to_secs(starttime))))
                 return True              
         except Exception:
             time.sleep(retry_interval)
     raise AssertionError("did not become true")
コード例 #6
0
 def _get_timeout(self, timeout):
     if timeout is None:
         return ''
     try:
         tout = secs_to_timestr(timestr_to_secs(timeout))
     except ValueError:
         tout = timeout
     return tout
コード例 #7
0
 def _get_timeout(self, timeout):
     try:
         tout = utils.secs_to_timestr(utils.timestr_to_secs(timeout.string))
     except ValueError:
         tout = timeout.string
     if timeout.message:
         tout += ' :: ' + timeout.message
     return tout
コード例 #8
0
ファイル: testdoc.py プロジェクト: EnochManohar/RIDE
 def _get_timeout(self, timeout):
     try:
         tout = utils.secs_to_timestr(utils.timestr_to_secs(timeout.string))
     except ValueError:
         tout = timeout.string
     if timeout.message:
         tout += ' :: ' + timeout.message
     return tout
コード例 #9
0
 def _wait_until(self, timeout, error, function, *args):
     timeout = self._get_timeout(timeout)
     error = error.replace('<TIMEOUT>', utils.secs_to_timestr(timeout))
     maxtime = time.time() + timeout
     while not function(*args):
         if time.time() > maxtime:
             raise AssertionError(error)
         time.sleep(0.2)
コード例 #10
0
ファイル: Process.py プロジェクト: micken42/robot-demo
    def wait_for_process(self,
                         handle=None,
                         timeout=None,
                         on_timeout='continue'):
        """Waits for the process to complete or to reach the given timeout.

        The process to wait for must have been started earlier with
        `Start Process`. If ``handle`` is not given, uses the current
        `active process`.

        ``timeout`` defines the maximum time to wait for the process. It can be
        given in
        [http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format|
        various time formats] supported by Robot Framework, for example, ``42``,
        ``42 s``, or ``1 minute 30 seconds``.

        ``on_timeout`` defines what to do if the timeout occurs. Possible values
        and corresponding actions are explained in the table below. Notice
        that reaching the timeout never fails the test.

        | = Value = |               = Action =               |
        | continue  | The process is left running (default). |
        | terminate | The process is gracefully terminated.  |
        | kill      | The process is forcefully stopped.     |

        See `Terminate Process` keyword for more details how processes are
        terminated and killed.

        If the process ends before the timeout or it is terminated or killed,
        this keyword returns a `result object` containing information about
        the execution. If the process is left running, Python ``None`` is
        returned instead.

        Examples:
        | # Process ends cleanly      |                  |                  |
        | ${result} =                 | Wait For Process | example          |
        | Process Should Be Stopped   | example          |                  |
        | Should Be Equal As Integers | ${result.rc}     | 0                |
        | # Process does not end      |                  |                  |
        | ${result} =                 | Wait For Process | timeout=42 secs  |
        | Process Should Be Running   |                  |                  |
        | Should Be Equal             | ${result}        | ${NONE}          |
        | # Kill non-ending process   |                  |                  |
        | ${result} =                 | Wait For Process | timeout=1min 30s | on_timeout=kill |
        | Process Should Be Stopped   |                  |                  |
        | Should Be Equal As Integers | ${result.rc}     | -9               |

        ``timeout`` and ``on_timeout`` are new in Robot Framework 2.8.2.
        """
        process = self._processes[handle]
        logger.info('Waiting for process to complete.')
        if timeout:
            timeout = timestr_to_secs(timeout)
            if not self._process_is_stopped(process, timeout):
                logger.info('Process did not complete in %s.' %
                            secs_to_timestr(timeout))
                return self._manage_process_timeout(handle, on_timeout.lower())
        return self._wait(process)
コード例 #11
0
 def set_testability_timeout(self: "SeleniumTestability", timeout: str) -> str:
     """
     Sets the global timeout value for waiting testability ready. Overrides the defaults set from plugin parameters.
     Parameters:
     - ``timeout`` Amount of time to wait until giving up for testability to be ready. Robot framework timestring
     """
     current = self.timeout
     self.timeout = timeout  # type: ignore
     return secs_to_timestr(current)
コード例 #12
0
ファイル: dotted.py プロジェクト: micken42/robot-demo
 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)
コード例 #13
0
ファイル: dotted.py プロジェクト: JMassapina/robotframework
 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)
コード例 #14
0
ファイル: Process.py プロジェクト: yamateh/robotframework
    def wait_for_process(self, handle=None, timeout=None, on_timeout='continue'):
        """Waits for the process to complete or to reach the given timeout.

        The process to wait for must have been started earlier with
        `Start Process`. If `handle` is not given, uses the current
        `active process`.

        `timeout` defines the maximum time to wait for the process. It is
        interpreted according to Robot Framework User Guide Appendix
        `Time Format`, for example, '42', '42 s', or '1 minute 30 seconds'.

        `on_timeout` defines what to do if the timeout occurs. Possible values
        and corresponding actions are explained in the table below. Notice
        that reaching the timeout never fails the test.

        |  = Value =  |               = Action =               |
        | `continue`  | The process is left running (default). |
        | `terminate` | The process is gracefully terminated.  |
        | `kill`      | The process is forcefully stopped.     |

        See `Terminate Process` keyword for more details how processes are
        terminated and killed.

        If the process ends before the timeout or it is terminated or killed,
        this keyword returns a `result object` containing information about
        the execution. If the process is left running, Python `None` is
        returned instead.

        Examples:
        | # Process ends cleanly      |                  |                  |
        | ${result} =                 | Wait For Process | example          |
        | Process Should Be Stopped   | example          |                  |
        | Should Be Equal As Integers | ${result.rc}     | 0                |
        | # Process does not end      |                  |                  |
        | ${result} =                 | Wait For Process | timeout=42 secs  |
        | Process Should Be Running   |                  |                  |
        | Should Be Equal             | ${result}        | ${NONE}          |
        | # Kill non-ending process   |                  |                  |
        | ${result} =                 | Wait For Process | timeout=1min 30s | on_timeout=kill |
        | Process Should Be Stopped   |                  |                  |
        | Should Be Equal As Integers | ${result.rc}     | -9               |

        `timeout` and `on_timeout` are new in Robot Framework 2.8.2.
        """
        process = self._processes[handle]
        result = self._results[process]
        logger.info('Waiting for process to complete.')
        if timeout:
            timeout = timestr_to_secs(timeout)
            if not self._process_is_stopped(process, timeout):
                logger.info('Process did not complete in %s.'
                            % secs_to_timestr(timeout))
                return self._manage_process_timeout(handle, on_timeout.lower())
        result.rc = process.wait() or 0
        logger.info('Process completed.')
        return result
コード例 #15
0
ファイル: ssh.py プロジェクト: EricJH/python_repository
    def set_pausetime(self, pause):
        """Sets the timeout used in read socket response, e.g. "120 sec".

        The read operations will for this time before starting to read from
        the output. To run operations that take a long time to generate their
        complete output, this timeout must be set accordingly.
        """
        old = secs_to_timestr(self._pausetime)
        self._pausetime = float(timestr_to_secs(pause))
        return old
コード例 #16
0
ファイル: telnet_connection.py プロジェクト: jufei/BtsShell
    def set_timeout(self, timeout):
        """Sets the timeout used in read operations to given value represented as timestr, e.g. "120 sec".

        The read operations will for this time before starting to read from
        the output. To run operations that take a long time to generate their
        complete output, this timeout must be set accordingly.
        """
        old = utils.secs_to_timestr(self._timeout)
        self._timeout = float(utils.timestr_to_secs(timeout))
        return old
コード例 #17
0
ファイル: telnet_connection.py プロジェクト: jufei/BtsShell
    def set_pause(self, pause):
        """Sets the timeout used in read socket response, e.g. "120 sec".

        The read operations will for this time before starting to read from
        the output. To run operations that take a long time to generate their
        complete output, this timeout must be set accordingly.
        """
        old = utils.secs_to_timestr(self._pause)
        self._pause = float(utils.timestr_to_secs(pause))
        return old
コード例 #18
0
 def _get_timeout(self, timeout):
     if timeout is None:
         return ''
     try:
         tout = secs_to_timestr(timestr_to_secs(timeout.value))
     except ValueError:
         tout = timeout.value
     if timeout.message:
         tout += ' :: ' + timeout.message
     return tout
コード例 #19
0
ファイル: testdoc.py プロジェクト: agalitz/robotframework
 def _get_timeout(self, timeout):
     if timeout is None:
         return ''
     try:
         tout = utils.secs_to_timestr(utils.timestr_to_secs(timeout.value))
     except ValueError:
         tout = timeout.value
     if timeout.message:
         tout += ' :: ' + timeout.message
     return tout
コード例 #20
0
ファイル: Process.py プロジェクト: azam-a/robotframework
    def wait_for_process(self, handle=None, timeout=None, on_timeout='continue'):
        """Waits for the process to complete or to reach the given timeout.

        The process to wait for must have been started earlier with
        `Start Process`. If ``handle`` is not given, uses the current
        `active process`.

        ``timeout`` defines the maximum time to wait for the process. It can be
        given in
        [http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#time-format|
        various time formats] supported by Robot Framework, for example, ``42``,
        ``42 s``, or ``1 minute 30 seconds``.

        ``on_timeout`` defines what to do if the timeout occurs. Possible values
        and corresponding actions are explained in the table below. Notice
        that reaching the timeout never fails the test.

        | = Value = |               = Action =               |
        | continue  | The process is left running (default). |
        | terminate | The process is gracefully terminated.  |
        | kill      | The process is forcefully stopped.     |

        See `Terminate Process` keyword for more details how processes are
        terminated and killed.

        If the process ends before the timeout or it is terminated or killed,
        this keyword returns a `result object` containing information about
        the execution. If the process is left running, Python ``None`` is
        returned instead.

        Examples:
        | # Process ends cleanly      |                  |                  |
        | ${result} =                 | Wait For Process | example          |
        | Process Should Be Stopped   | example          |                  |
        | Should Be Equal As Integers | ${result.rc}     | 0                |
        | # Process does not end      |                  |                  |
        | ${result} =                 | Wait For Process | timeout=42 secs  |
        | Process Should Be Running   |                  |                  |
        | Should Be Equal             | ${result}        | ${NONE}          |
        | # Kill non-ending process   |                  |                  |
        | ${result} =                 | Wait For Process | timeout=1min 30s | on_timeout=kill |
        | Process Should Be Stopped   |                  |                  |
        | Should Be Equal As Integers | ${result.rc}     | -9               |

        ``timeout`` and ``on_timeout`` are new in Robot Framework 2.8.2.
        """
        process = self._processes[handle]
        logger.info('Waiting for process to complete.')
        if timeout:
            timeout = timestr_to_secs(timeout)
            if not self._process_is_stopped(process, timeout):
                logger.info('Process did not complete in %s.'
                            % secs_to_timestr(timeout))
                return self._manage_process_timeout(handle, on_timeout.lower())
        return self._wait(process)
コード例 #21
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self.string or self.string.upper() == 'NONE':
             return
         self.secs = utils.timestr_to_secs(self.string)
         self.string = utils.secs_to_timestr(self.secs)
         self.message = variables.replace_string(self.message)
     except (DataError, ValueError), err:
         self.secs = 0.000001 # to make timeout active
         self.error = 'Setting %s failed: %s' % (self.type.lower(), unicode(err))
コード例 #22
0
ファイル: testdoc.py プロジェクト: gdw2/robot-framework
 def _write_test_metadata(self, test):
     self._start_suite_or_test_metadata(test)
     if test.timeout.secs < 0:
         tout = ''
     else:
         tout = utils.secs_to_timestr(test.timeout.secs)
         if test.timeout.message:
             tout += ' | ' + test.timeout.message
     self._write_metadata_row('Timeout', tout)
     self._write_metadata_row('Tags', ', '.join(test.tags))
     self._writer.end('table')
コード例 #23
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self:
             return
         self.secs = timestr_to_secs(self.string)
         self.string = secs_to_timestr(self.secs)
     except (DataError, ValueError) as err:
         self.secs = 0.000001  # to make timeout active
         self.error = (u'Setting %s timeout failed: %s' %
                       (self.type.lower(), err))
コード例 #24
0
ファイル: ssh.py プロジェクト: EricJH/python_repository
    def set_timeout(self, timeout):
        """Sets the timeout used in read operations to given value represented as timestr, e.g. "120 sec".

        The read operations will for this time before starting to read from
        the output. To run operations that take a long time to generate their
        complete output, this timeout must be set accordingly.
        """
        old = secs_to_timestr(self._timeout)
        self._timeout = float(timestr_to_secs(timeout))
        # self.channel.settimeout(self._timeout)
        return old
コード例 #25
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self:
             return
         self.secs = timestr_to_secs(self.string)
         self.string = secs_to_timestr(self.secs)
         self.message = variables.replace_string(self.message)
     except (DataError, ValueError) as err:
         self.secs = 0.000001  # to make timeout active
         self.error = (u'Setting %s timeout failed: %s'
                       % (self.type.lower(), err))
コード例 #26
0
 def wait_until_page_contains_element(self, locator, timeout):
     """
     Waits until `element` appears on current page or `timeout` expires.
     """
     try:
         self._wait_until_keyword_returns_true(timeout, timestr_to_secs(timeout)/10, "is_element_present", locator)               
     except Exception, err:
         if not 'did not become true' in str(err):
             raise
         timestr = secs_to_timestr(timestr_to_secs(timeout))
         raise AssertionError("Element '%s' did not appear in '%s'" 
                               % (locator, timestr))
コード例 #27
0
 def wait_until_element_visible(self, locator, timeout):
     """
     Waits until the element is visble. Can be used to wait for ajax calls. 
     """
     try:
         self._wait_until_keyword_returns_true(timeout, timestr_to_secs(timeout)/10, "is_visible", locator)               
     except Exception, err:
         if not 'did not become true' in str(err):
             raise
         timestr = secs_to_timestr(timestr_to_secs(timeout))
         raise AssertionError("Element '%s' did not appear in '%s'" 
                               % (locator, timestr))
コード例 #28
0
ファイル: dotted.py プロジェクト: xylix/robotframework
 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)
コード例 #29
0
 def replace_variables(self, variables):
     try:
         self.string = variables.replace_string(self.string)
         if not self:
             return
         self.secs = utils.timestr_to_secs(self.string)
         self.string = utils.secs_to_timestr(self.secs)
         self.message = variables.replace_string(self.message)
     except (DataError, ValueError) as err:
         self.secs = 0.000001  # to make timeout active
         self.error = 'Setting %s timeout failed: %s' \
                 % (self.type.lower(), unicode(err))
コード例 #30
0
    def set_selenium_speed(self, seconds):
        """Sets the delay that is waited after each Selenium command.

        This is useful mainly in slowing down the test execution to be able to
        view the execution.  `seconds` may be given in Robot Framework time
        format.  Returns the previous speed value.

        Example:
        | Set Selenium Speed | 2 seconds |
        """
        old = self._selenium.get_speed()
        seconds = str(int(utils.timestr_to_secs(seconds)*1000))
        self._selenium.set_speed(seconds)
        return utils.secs_to_timestr(float(old)/1000)
コード例 #31
0
    def set_selenium_speed(self, seconds):
        """Sets the delay that is waited after each Selenium command.

        This is useful mainly in slowing down the test execution to be able to
        view the execution.  `seconds` may be given in Robot Framework time
        format.  Returns the previous speed value.

        Example:
        | Set Selenium Speed | 2 seconds |
        """
        old = self._selenium.get_speed()
        seconds = str(int(utils.timestr_to_secs(seconds)*1000))
        self._selenium.set_speed(seconds)
        return utils.secs_to_timestr(float(old)/1000)
コード例 #32
0
 def wait_until_page_contains(self, text, timeout):
     """Waits until `text` appears on current page or `timeout` expires.
     Over-rided the Robot Framework built-in keyword to make it work with IE.
     """
     try:
         #if not('*iexplore' in self._selenium.browserStartCommand or '*iehta' in self._selenium.browserStartCommand):
         #    JavaScript.wait_until_page_contains(self, text, timeout)
         #else:
         self._wait_until_keyword_returns_true(timeout, timestr_to_secs(timeout)/10, "is_text_present", text)               
     except Exception, err:
         if not 'did not become true' in str(err):
             raise
         timestr = secs_to_timestr(timestr_to_secs(timeout))
         raise AssertionError("Text '%s' did not appear in '%s'" 
                               % (text, timestr))
コード例 #33
0
    def wait_until_test_status_is(self, status):
        status = find_dimi_test_status(status)
        test = self._cp['selected_dimi_test']
        start_time = time.time()
        while time.time() < start_time + self._timeout:
            _status = test.status()[0]
            self._debug('Current test status is %s' %
                    dimi_test_status_str(_status))
            if _status == status:
                return
            time.sleep(self._poll_interval)

        raise AssertionError('Test status %s not reached in %s.'
                % (dimi_test_status_str(status),
                    secs_to_timestr(self._timeout)))
コード例 #34
0
ファイル: Telnet.py プロジェクト: laxmanCT/robotframework
    def read_until(self, expected, loglevel=None):
        """Reads from the current output, until expected is encountered.

        Text up to and including the match is returned. If no match is
        found, the keyword fails.

        See `Read` for more information on `loglevel`.
        """
        ret = telnetlib.Telnet.read_until(self, expected,
                                          self._timeout).decode('ASCII', 'ignore')
        self._log(ret, loglevel)
        if not ret.endswith(expected):
            raise AssertionError("No match found for '%s' in %s"
                                 % (expected, utils.secs_to_timestr(self._timeout)))
        return ret
コード例 #35
0
ファイル: Telnet.py プロジェクト: IlfirinPL/RIDE
    def read_until(self, expected, loglevel=None):
        """Reads from the current output, until expected is encountered.

        Text up to and including the match is returned. If no match is
        found, the keyword fails.

        See `Read` for more information on `loglevel`.
        """
        ret = telnetlib.Telnet.read_until(self, expected,
                                          self._timeout).decode('ASCII', 'ignore')
        self._log(ret, loglevel)
        if not ret.endswith(expected):
            raise AssertionError("No match found for '%s' in %s"
                                 % (expected, utils.secs_to_timestr(self._timeout)))
        return ret
コード例 #36
0
    def wait_until_application_has_stopped(self, name, timeout):  # pylint:disable=no-self-use
        """Waits until no process with the given name exists.

        `name` is the name of the process

        `timeout` is the maximum time to wait as a Robot time string.

        Example:
        | Wait Until Application Has Stopped | calc | # waits until calc.exe process does not exist |
        """
        timeout = timestr_to_secs(timeout)
        Wait.until_true(
            lambda: not Process.GetProcessesByName(name), timeout,
            "Application '{}' did not exit within {}".format(
                name, secs_to_timestr(timeout)))
コード例 #37
0
    def set_timeout(self, timeout):
        """Sets the timeout used in `Wait Until X` keywords to the given value.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.

        The old timeout is returned and can be used to restore it later.

        Example.
        | ${tout}= | Set Timeout | 2 minute 30 seconds |
        | Do Something |
        | Set Timeout | ${tout} |
        """

        old = getattr(self, '_timeout', 3.0)
        self._timeout = timestr_to_secs(timeout)
        return secs_to_timestr(old)
コード例 #38
0
    def wait_until_sensor_reading_is(self, name, value):
        """Wait until a sensor reaches the given value.

        `name` is the sensor ID string. See also `Get Sensor Reading`.
        """

        value = float(value)

        start_time = time.time()
        while time.time() < start_time + self._timeout:
            current_reading = self.get_sensor_reading(name)
            if current_reading == value:
                self._info('waited %s seconds until value "%s" was reached'
                        % (time.time()-start_time, value))
                return
            time.sleep(self._poll_interval)

        raise AssertionError('Sensor "%s" did not reach the value "%s" in %s.'
                % (name, value, utils.secs_to_timestr(self._timeout)))
コード例 #39
0
    def wait_until_sensor_state_is(self, name, state, mask=0x7fff):
        """Wait until a sensor reaches the given state.

        `name` is the sensor ID string. See also `Get Sensor Reading`.
        """

        state = int_any_base(state)
        mask = int_any_base(mask)

        start_time = time.time()
        while time.time() < start_time + self._timeout:
            current_state = self.get_sensor_state(name)
            if current_state & mask == state & mask:
                self._info('waited %s seconds until state "%s" was reached'
                        % (time.time()-start_time, state))
                return
            time.sleep(self._poll_interval)

        raise AssertionError('Sensor "%s" did not reach the state "%s" in %s.'
                % (name, state, utils.secs_to_timestr(self._timeout)))
コード例 #40
0
    def write_until_expected_output(self,
                                    text,
                                    expected,
                                    timeout,
                                    retry_interval,
                                    loglevel=None):
        """Writes the given text repeatedly, until `expected` appears in the output.

        `text` is written without appending a
        newline. `retry_interval` defines the time waited before
        writing `text` again. `text` is consumed from the output
        before `expected` is tried to be read.

        If `expected` does not appear in the output within `timeout`,
        this keyword fails.

        See `Read` for more information on `loglevel`.

        Example:
        | Write Until Expected Output | ps -ef| grep myprocess\\n | myprocess |
        | ...                         | 5s                        | 0.5s      |

        This writes the 'ps -ef | grep myprocess\\n', until
        'myprocess' appears on the output. The command is written
        every 0.5 seconds and the keyword ,fails if 'myprocess' does
        not appear in the output in 5 seconds.
        """
        timeout = utils.timestr_to_secs(timeout)
        retry_interval = utils.timestr_to_secs(retry_interval)
        starttime = time.time()
        while time.time() - starttime < timeout:
            self.write_bare(text)
            self.read_until(text, loglevel)
            ret = telnetlib.Telnet.read_until(self, expected,
                                              retry_interval).decode(
                                                  'ASCII', 'ignore')
            self._log(ret, loglevel)
            if ret.endswith(expected):
                return ret
        raise AssertionError("No match found for '%s' in %s" %
                             (expected, utils.secs_to_timestr(timeout)))
コード例 #41
0
    def wait_until_sel_contains_x_times_sensor_number(self, count, number):
        """Waits until the specified sensor number appears at least `count`
        times within the SEL.

        Note: this keyword invalidates the prefetched SEL records. You have to
        rerun the `Prefetch SEL` keyword.
        """
        number = find_sensor_type(number)
        count = int(count)

        self._invalidate_prefetched_sel_records()
        start_time = time.time()
        while time.time() < start_time + self._timeout:
            records = self._find_sel_records_by_sensor_number(number)
            if len(records) >= count:
                self._selected_sel_record = records[0]
                return
            time.sleep(self._poll_interval)

        raise AssertionError('No match found for SEL record from num  "%d" in %s.'
                % (number, utils.secs_to_timestr(self._timeout)))
コード例 #42
0
ファイル: Telnet.py プロジェクト: IlfirinPL/RIDE
    def set_timeout(self, timeout):
        """Sets the timeout used in read operations to the given value.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.

        Read operations that expect some output to appear (`Read
        Until`, `Read Until Regexp`, `Read Until Prompt`) use this
        timeout and fail if the expected output has not appeared when
        this timeout expires.

        The old timeout is returned and can be used to restore it later.

        Example:
        | ${tout} = | Set Timeout | 2 minute 30 seconds |
        | Do Something |
        | Set Timeout | ${tout} |
        """
        old = getattr(self, '_timeout', 3.0)
        self._timeout = utils.timestr_to_secs(timeout)
        return utils.secs_to_timestr(old)
コード例 #43
0
    def wait_until_sel_contains_x_times_sensor_number(self, count, number):
        """Waits until the specified sensor number appears at least `count`
        times within the SEL.

        Note: this keyword invalidates the prefetched SEL records. You have to
        rerun the `Prefetch SEL` keyword.
        """
        number = find_sensor_type(number)
        count = int(count)

        self._invalidate_prefetched_sel_records()
        start_time = time.time()
        while time.time() < start_time + self._timeout:
            records = self._find_sel_records_by_sensor_number(number)
            if len(records) >= count:
                self._selected_sel_record = records[0]
                return
            time.sleep(self._poll_interval)

        raise AssertionError('No match found for SEL record from num  "%d" in %s.'
                % (number, utils.secs_to_timestr(self._timeout)))
コード例 #44
0
    def set_timeout(self, timeout):
        """Sets the timeout used in read operations to the given value.

        `timeout` is given in Robot Framework's time format
        (e.g. 1 minute 20 seconds) that is explained in the User Guide.

        Read operations that expect some output to appear (`Read
        Until`, `Read Until Regexp`, `Read Until Prompt`) use this
        timeout and fail if the expected output has not appeared when
        this timeout expires.

        The old timeout is returned and can be used to restore it later.

        Example:
        | ${tout} = | Set Timeout | 2 minute 30 seconds |
        | Do Something |
        | Set Timeout | ${tout} |
        """
        old = getattr(self, '_timeout', 3.0)
        self._timeout = utils.timestr_to_secs(timeout)
        return utils.secs_to_timestr(old)
コード例 #45
0
ファイル: Telnet.py プロジェクト: waldenner/robotframework
    def read_until_prompt(self, loglevel=None):
        """Reads output until the prompt is encountered.

        This keyword requires the prompt to be [#Configuration|configured]
        either in `importing` or with `Open Connection` or `Set Prompt` keyword.

        Text up to and including the prompt is returned and logged. If no prompt
        is found, this keyword fails. How much to wait for the output depends
        on the [#Configuration|configured timeout].

        See `Logging` section for more information about log levels.
        """
        if not self._prompt_is_set():
            raise RuntimeError('Prompt is not set.')
        success, output = self._read_until_prompt()
        self._log(output, loglevel)
        if not success:
            prompt, regexp = self._prompt
            raise AssertionError("Prompt '%s' not found in %s."
                    % (prompt if not regexp else prompt.pattern,
                       utils.secs_to_timestr(self._timeout)))
        return output
コード例 #46
0
ファイル: Telnet.py プロジェクト: agalitz/robotframework
    def read_until_prompt(self, loglevel=None):
        """Reads output until the prompt is encountered.

        This keyword requires the prompt to be [#Configuration|configured]
        either in `importing` or with `Open Connection` or `Set Prompt` keyword.

        Text up to and including the prompt is returned and logged. If no prompt
        is found, this keyword fails. How much to wait for the output depends
        on the [#Configuration|configured timeout].

        See `Logging` section for more information about log levels.
        """
        if not self._prompt_is_set():
            raise RuntimeError('Prompt is not set.')
        success, output = self._read_until_prompt()
        self._log(output, loglevel)
        if not success:
            prompt, regexp = self._prompt
            raise AssertionError("Prompt '%s' not found in %s."
                    % (prompt if not regexp else prompt.pattern,
                       utils.secs_to_timestr(self._timeout)))
        return output
コード例 #47
0
ファイル: Telnet.py プロジェクト: agalitz/robotframework
    def set_timeout(self, timeout):
        """Sets the timeout used for waiting output in the current connection.

        Read operations that expect some output to appear (`Read Until`, `Read
        Until Regexp`, `Read Until Prompt`, `Login`) use this timeout and fail
        if the expected output does not appear before this timeout expires.

        The `timeout` must be given in `time string format`. The old timeout is
        returned and can be used to restore the timeout later.

        Example:
        | ${old} =       | `Set Timeout` | 2 minute 30 seconds |
        | `Do Something` |
        | `Set Timeout`  | ${old}  |

        See `Configuration` section for more information about global and
        connection specific configuration.
        """
        self._verify_connection()
        old = self._timeout
        self._set_timeout(timeout)
        return utils.secs_to_timestr(old)
コード例 #48
0
    def wait_until_upgrade_state_is(self, state, may_fail=False):
        state = find_fumi_upgrade_state(state)
        bank = self._selected_fumi_bank()
        start_time = time.time()
        while time.time() < start_time + self._timeout:
            try:
                _state = bank.status()
            except SaHpiError:
                if may_fail:
                    time.sleep(self._poll_interval)
                    continue
                else:
                    raise
            self._debug('Current upgrade state is %s' %
                    fumi_upgrade_status_str(_state))
            if _state == state:
                return
            time.sleep(self._poll_interval)

        raise AssertionError('Upgrade state %s not reached %s.'
                % (fumi_upgrade_status_str(state),
                    secs_to_timestr(self._timeout)))
コード例 #49
0
ファイル: Telnet.py プロジェクト: waldenner/robotframework
    def set_timeout(self, timeout):
        """Sets the timeout used for waiting output in the current connection.

        Read operations that expect some output to appear (`Read Until`, `Read
        Until Regexp`, `Read Until Prompt`, `Login`) use this timeout and fail
        if the expected output does not appear before this timeout expires.

        The `timeout` must be given in `time string format`. The old timeout is
        returned and can be used to restore the timeout later.

        Example:
        | ${old} =       | `Set Timeout` | 2 minute 30 seconds |
        | `Do Something` |
        | `Set Timeout`  | ${old}  |

        See `Configuration` section for more information about global and
        connection specific configuration.
        """
        self._verify_connection()
        old = self._timeout
        self._set_timeout(timeout)
        return utils.secs_to_timestr(old)
コード例 #50
0
    def set_selenium_timeout(self, seconds):
        """Sets the timeout used by various keywords.

        Keywords that expect a page load to happen will fail if the page
        is not loaded within the timeout specified with `seconds`.
        Starting from SeleniumLibrary 2.6, this timeout is also the default
        timeout with various `Wait ...` keywords. See `introduction` for
        more information about timeouts and handling page loads.

        The previous timeout value is returned by this keyword and can
        be used to set the old value back later. The default timeout
        is 5 seconds, but it can be altered in `importing`.

        Example:
        | ${orig timeout} = | Set Selenium Timeout | 15 seconds |
        | Open page that loads slowly |
        | Set Selenium Timeout | ${orig timeout} |
        """
        timeout = utils.timestr_to_secs(seconds)
        old = getattr(self, '_timeout', timeout)
        self._timeout = timeout
        self._selenium.set_timeout(timeout * 1000)
        return utils.secs_to_timestr(old)
コード例 #51
0
    def set_selenium_timeout(self, seconds):
        """Sets the timeout used by various keywords.

        Keywords that expect a page load to happen will fail if the page
        is not loaded within the timeout specified with `seconds`.
        Starting from SeleniumLibrary 2.6, this timeout is also the default
        timeout with various `Wait ...` keywords. See `introduction` for
        more information about timeouts and handling page loads.

        The previous timeout value is returned by this keyword and can
        be used to set the old value back later. The default timeout
        is 5 seconds, but it can be altered in `importing`.

        Example:
        | ${orig timeout} = | Set Selenium Timeout | 15 seconds |
        | Open page that loads slowly |
        | Set Selenium Timeout | ${orig timeout} |
        """
        timeout = utils.timestr_to_secs(seconds)
        old = getattr(self, '_timeout', timeout)
        self._timeout = timeout
        self._selenium.set_timeout(timeout * 1000)
        return utils.secs_to_timestr(old)
コード例 #52
0
ファイル: Telnet.py プロジェクト: IlfirinPL/RIDE
    def write_until_expected_output(self, text, expected, timeout,
                                    retry_interval, loglevel=None):
        """Writes the given text repeatedly, until `expected` appears in the output.

        `text` is written without appending a
        newline. `retry_interval` defines the time waited before
        writing `text` again. `text` is consumed from the output
        before `expected` is tried to be read.

        If `expected` does not appear in the output within `timeout`,
        this keyword fails.

        See `Read` for more information on `loglevel`.

        Example:
        | Write Until Expected Output | ps -ef| grep myprocess\\n | myprocess |
        | ...                         | 5s                        | 0.5s      |

        This writes the 'ps -ef | grep myprocess\\n', until
        'myprocess' appears on the output. The command is written
        every 0.5 seconds and the keyword ,fails if 'myprocess' does
        not appear in the output in 5 seconds.
        """
        timeout = utils.timestr_to_secs(timeout)
        retry_interval = utils.timestr_to_secs(retry_interval)
        starttime = time.time()
        while time.time() - starttime < timeout:
            self.write_bare(text)
            self.read_until(text, loglevel)
            ret = telnetlib.Telnet.read_until(self, expected,
                                              retry_interval).decode('ASCII', 'ignore')
            self._log(ret, loglevel)
            if ret.endswith(expected):
                return ret
        raise AssertionError("No match found for '%s' in %s"
                             % (expected, utils.secs_to_timestr(timeout)))
コード例 #53
0
ファイル: BuiltIn.py プロジェクト: zbzzbd/rbot_srcCode_copy
 def wait_until_keyword_succeeds(self,timeout,retry_interval,name,*args):
     """
     waits until the specitied keyword succeeds or the given timeout expiress
     'name' and 'args' define the keyword that is executed
     similarly as with 'run keyword'.if the specified keyword does not succeed within 'timeout'
     this keyword fails. 'retry_interval' is the time to ait before trying to run the keyword
     again after the previous run has failed
     """
     timeout = utils.timestr_to_secs(timeout)
     retry_interval = utils.timestr_to_secs(retry_interval)
     maxtime = time.time() + timeout
     error = None
     while not error
         try:
             return self.run_keyword(name,*args)
         except ExecutionFailed, err:
             if err.dont_continue:
                 raise
             if time.time() >maxtime:
                 error = unicode(err)
             else:
                 time.sleep(retry_interval)
             raise AssertionError("timeout %s exceeded. The last error was : %s"
                                  %(utils.secs_to_timestr(timeout),error))
コード例 #54
0
ファイル: DateTime.py プロジェクト: shiyeling/robotframework
 def _convert_to_compact(self, seconds, millis=True):
     return secs_to_timestr(seconds, compact=True)