Robot Framework
robot.model.visitor.SuiteVisitor Class Reference

Interface to ease traversing through a test suite structure. More...

Inheritance diagram for robot.model.visitor.SuiteVisitor:
robot.model.configurer.SuiteConfigurer robot.model.filter.EmptySuiteRemover robot.model.modifier.ModelModifier robot.model.statistics.StatisticsBuilder robot.model.tagsetter.TagSetter robot.model.totalstatistics.TotalStatisticsBuilder robot.output.console.dotted.StatusReporter robot.result.keywordremover.WarningAndErrorFinder robot.result.keywordremover._KeywordRemover robot.result.merger.Merger robot.result.messagefilter.MessageFilter robot.result.resultbuilder.RemoveKeywords robot.result.suiteteardownfailed.SuiteTeardownFailed robot.result.suiteteardownfailed.SuiteTeardownFailureHandler robot.result.visitor.ResultVisitor robot.running.randomizer.Randomizer robot.running.suiterunner.SuiteRunner

Public Member Functions

def end_body_item (self, item)
 Called, by default, when keywords, messages or control structures end. More...
 
def end_break (self, break_)
 Called when a BREAK element ends. More...
 
def end_continue (self, continue_)
 Called when a CONTINUE element ends. More...
 
def end_for (self, for_)
 Called when a FOR loop ends. More...
 
def end_for_iteration (self, iteration)
 Called when a FOR loop iteration ends. More...
 
def end_if (self, if_)
 Called when an IF/ELSE structure ends. More...
 
def end_if_branch (self, branch)
 Called when an IF/ELSE branch ends. More...
 
def end_keyword (self, keyword)
 Called when a keyword ends. More...
 
def end_message (self, msg)
 Called when a message ends. More...
 
def end_return (self, return_)
 Called when a RETURN element ends. More...
 
def end_suite (self, suite)
 Called when a suite ends. More...
 
def end_test (self, test)
 Called when a test ends. More...
 
def end_try (self, try_)
 Called when a TRY/EXCEPT structure ends. More...
 
def end_try_branch (self, branch)
 Called when TRY, EXCEPT, ELSE and FINALLY branches end. More...
 
def end_while (self, while_)
 Called when a WHILE loop ends. More...
 
def end_while_iteration (self, iteration)
 Called when a WHILE loop iteration ends. More...
 
def start_body_item (self, item)
 Called, by default, when keywords, messages or control structures start. More...
 
def start_break (self, break_)
 Called when a BREAK element starts. More...
 
def start_continue (self, continue_)
 Called when a CONTINUE element starts. More...
 
def start_for (self, for_)
 Called when a FOR loop starts. More...
 
def start_for_iteration (self, iteration)
 Called when a FOR loop iteration starts. More...
 
def start_if (self, if_)
 Called when an IF/ELSE structure starts. More...
 
def start_if_branch (self, branch)
 Called when an IF/ELSE branch starts. More...
 
def start_keyword (self, keyword)
 Called when a keyword starts. More...
 
def start_message (self, msg)
 Called when a message starts. More...
 
def start_return (self, return_)
 Called when a RETURN element starts. More...
 
def start_suite (self, suite)
 Called when a suite starts. More...
 
def start_test (self, test)
 Called when a test starts. More...
 
def start_try (self, try_)
 Called when a TRY/EXCEPT structure starts. More...
 
def start_try_branch (self, branch)
 Called when TRY, EXCEPT, ELSE or FINALLY branches start. More...
 
def start_while (self, while_)
 Called when a WHILE loop starts. More...
 
def start_while_iteration (self, iteration)
 Called when a WHILE loop iteration starts. More...
 
def visit_break (self, break_)
 Visits BREAK elements. More...
 
def visit_continue (self, continue_)
 Visits CONTINUE elements. More...
 
def visit_for (self, for_)
 Implements traversing through FOR loops. More...
 
def visit_for_iteration (self, iteration)
 Implements traversing through single FOR loop iteration. More...
 
def visit_if (self, if_)
 Implements traversing through IF/ELSE structures. More...
 
def visit_if_branch (self, branch)
 Implements traversing through single IF/ELSE branch. More...
 
def visit_keyword (self, kw)
 Implements traversing through keywords. More...
 
def visit_message (self, msg)
 Implements visiting messages. More...
 
def visit_return (self, return_)
 Visits a RETURN elements. More...
 
def visit_suite (self, suite)
 Implements traversing through suites. More...
 
def visit_test (self, test)
 Implements traversing through tests. More...
 
def visit_try (self, try_)
 Implements traversing through TRY/EXCEPT structures. More...
 
def visit_try_branch (self, branch)
 Visits individual TRY, EXCEPT, ELSE and FINALLY branches. More...
 
def visit_while (self, while_)
 Implements traversing through WHILE loops. More...
 
def visit_while_iteration (self, iteration)
 Implements traversing through single WHILE loop iteration. More...
 

Detailed Description

Interface to ease traversing through a test suite structure.

Visitors make it easy to modify test suite structures or to collect information from them. They work both with the :mod:executable model <robot.running.model> and the :mod:result model <robot.result.model>, but the objects passed to the visitor methods are slightly different depending on the model they are used with. The main differences are that on the execution side keywords do not have child keywords nor messages, and that only the result objects have status related attributes like :attr:status and :attr:starttime.

This module contains :class:SuiteVisitor that implements the core logic to visit a test suite structure, and the :mod:~robot.result package contains :class:~robot.result.visitor.ResultVisitor that supports visiting the whole test execution result structure. Both of these visitors should be imported via the :mod:robot.api package when used by external code.

Visitor algorithm

All suite, test, keyword and message objects have a :meth:visit method that accepts a visitor instance. These methods will then call the correct visitor method :meth:~SuiteVisitor.visit_suite, :meth:~SuiteVisitor.visit_test, :meth:~SuiteVisitor.visit_keyword or :meth:~SuiteVisitor.visit_message, depending on the instance where the :meth:visit method exists.

The recommended and definitely the easiest way to implement a visitor is extending the :class:SuiteVisitor base class. The default implementation of its :meth:visit_x methods take care of traversing child elements of the object :obj:x recursively. A :meth:visit_x method first calls a corresponding :meth:start_x method (e.g. :meth:visit_suite calls :meth:start_suite), then calls :meth:visit for all child objects of the :obj:x object, and finally calls the corresponding :meth:end_x method. The default implementations of :meth:start_x and :meth:end_x do nothing.

All items that can appear inside tests have their own visit methods. These include :meth:visit_keyword, :meth:visit_message (only applicable with results, not with executable data), :meth:visit_for, :meth:visit_if, and so on, as well as their appropriate start/end methods like :meth:start_keyword and :meth:end_for. If there is a need to visit all these items, it is possible to implement only :meth:start_body_item and :meth:end_body_item methods that are, by default, called by the appropriate start/end methods. These generic methods are new in Robot Framework 5.0.

Visitors extending the :class:SuiteVisitor can stop visiting at a certain level either by overriding suitable :meth:visit_x method or by returning an explicit False from any :meth:start_x method.

Examples

The following example visitor modifies the test suite structure it visits. It could be used, for example, with Robot Framework's --prerunmodifier option to modify test data before execution.

.. literalinclude:: ../../../doc/api/code_examples/SelectEveryXthTest.py :language: python

For more examples it is possible to look at the source code of visitors used internally by Robot Framework itself. Some good examples are :class:~robot.model.tagsetter.TagSetter and :mod:keyword removers <robot.result.keywordremover>.

Abstract class to ease traversing through the suite structure.

See the :mod:`module level <robot.model.visitor>` documentation for more
information and an example.

Definition at line 85 of file visitor.py.

Member Function Documentation

◆ end_body_item()

def robot.model.visitor.SuiteVisitor.end_body_item (   self,
  item 
)

Called, by default, when keywords, messages or control structures end.

    More specific :meth:`end_keyword`, :meth:`end_message`, `:meth:`end_for`,
    etc. can be implemented to visit only keywords, messages or specific control
    structures.

    Default implementation does nothing.

Definition at line 498 of file visitor.py.

◆ end_break()

def robot.model.visitor.SuiteVisitor.end_break (   self,
  break_ 
)

Called when a BREAK element ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 450 of file visitor.py.

◆ end_continue()

def robot.model.visitor.SuiteVisitor.end_continue (   self,
  continue_ 
)

Called when a CONTINUE element ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 427 of file visitor.py.

◆ end_for()

def robot.model.visitor.SuiteVisitor.end_for (   self,
  for_ 
)

Called when a FOR loop ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 192 of file visitor.py.

◆ end_for_iteration()

def robot.model.visitor.SuiteVisitor.end_for_iteration (   self,
  iteration 
)

Called when a FOR loop iteration ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 222 of file visitor.py.

◆ end_if()

def robot.model.visitor.SuiteVisitor.end_if (   self,
  if_ 
)

Called when an IF/ELSE structure ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 251 of file visitor.py.

◆ end_if_branch()

def robot.model.visitor.SuiteVisitor.end_if_branch (   self,
  branch 
)

Called when an IF/ELSE branch ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 277 of file visitor.py.

◆ end_keyword()

def robot.model.visitor.SuiteVisitor.end_keyword (   self,
  keyword 
)

Called when a keyword ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 166 of file visitor.py.

◆ end_message()

def robot.model.visitor.SuiteVisitor.end_message (   self,
  msg 
)

Called when a message ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Definition at line 475 of file visitor.py.

◆ end_return()

def robot.model.visitor.SuiteVisitor.end_return (   self,
  return_ 
)

Called when a RETURN element ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 404 of file visitor.py.

◆ end_suite()

def robot.model.visitor.SuiteVisitor.end_suite (   self,
  suite 
)

◆ end_test()

def robot.model.visitor.SuiteVisitor.end_test (   self,
  test 
)

Called when a test ends.

Default implementation does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 136 of file visitor.py.

◆ end_try()

def robot.model.visitor.SuiteVisitor.end_try (   self,
  try_ 
)

Called when a TRY/EXCEPT structure ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 303 of file visitor.py.

◆ end_try_branch()

def robot.model.visitor.SuiteVisitor.end_try_branch (   self,
  branch 
)

Called when TRY, EXCEPT, ELSE and FINALLY branches end.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 325 of file visitor.py.

◆ end_while()

def robot.model.visitor.SuiteVisitor.end_while (   self,
  while_ 
)

Called when a WHILE loop ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 351 of file visitor.py.

◆ end_while_iteration()

def robot.model.visitor.SuiteVisitor.end_while_iteration (   self,
  iteration 
)

Called when a WHILE loop iteration ends.

    By default, calls :meth:`end_body_item` which, by default, does nothing.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 381 of file visitor.py.

◆ start_body_item()

def robot.model.visitor.SuiteVisitor.start_body_item (   self,
  item 
)

Called, by default, when keywords, messages or control structures start.

    More specific :meth:`start_keyword`, :meth:`start_message`, `:meth:`start_for`,
    etc. can be implemented to visit only keywords, messages or specific control
    structures.

    Can return explicit ``False`` to stop visiting. Default implementation does
    nothing.

Definition at line 487 of file visitor.py.

◆ start_break()

def robot.model.visitor.SuiteVisitor.start_break (   self,
  break_ 
)

Called when a BREAK element starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 443 of file visitor.py.

◆ start_continue()

def robot.model.visitor.SuiteVisitor.start_continue (   self,
  continue_ 
)

Called when a CONTINUE element starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 420 of file visitor.py.

◆ start_for()

def robot.model.visitor.SuiteVisitor.start_for (   self,
  for_ 
)

Called when a FOR loop starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.result.keywordremover.ForLoopItemsRemover, and robot.output.xmllogger.XmlLogger.

Definition at line 185 of file visitor.py.

◆ start_for_iteration()

def robot.model.visitor.SuiteVisitor.start_for_iteration (   self,
  iteration 
)

Called when a FOR loop iteration starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 215 of file visitor.py.

◆ start_if()

def robot.model.visitor.SuiteVisitor.start_if (   self,
  if_ 
)

Called when an IF/ELSE structure starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 244 of file visitor.py.

◆ start_if_branch()

def robot.model.visitor.SuiteVisitor.start_if_branch (   self,
  branch 
)

Called when an IF/ELSE branch starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 270 of file visitor.py.

◆ start_keyword()

def robot.model.visitor.SuiteVisitor.start_keyword (   self,
  keyword 
)

Called when a keyword starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.result.keywordremover.WaitUntilKeywordSucceedsRemover, robot.result.keywordremover.ByTagKeywordRemover, robot.result.keywordremover.ByNameKeywordRemover, robot.output.xmllogger.XmlLogger, robot.result.messagefilter.MessageFilter, and robot.result.keywordremover.WarningAndErrorFinder.

Definition at line 159 of file visitor.py.

◆ start_message()

def robot.model.visitor.SuiteVisitor.start_message (   self,
  msg 
)

Called when a message starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.reporting.outputwriter.OutputWriter.

Definition at line 468 of file visitor.py.

◆ start_return()

def robot.model.visitor.SuiteVisitor.start_return (   self,
  return_ 
)

Called when a RETURN element starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 397 of file visitor.py.

◆ start_suite()

◆ start_test()

def robot.model.visitor.SuiteVisitor.start_test (   self,
  test 
)

Called when a test starts.

Default implementation does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.result.keywordremover.WarningAndErrorFinder, and robot.output.xmllogger.XmlLogger.

Definition at line 132 of file visitor.py.

◆ start_try()

def robot.model.visitor.SuiteVisitor.start_try (   self,
  try_ 
)

Called when a TRY/EXCEPT structure starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 296 of file visitor.py.

◆ start_try_branch()

def robot.model.visitor.SuiteVisitor.start_try_branch (   self,
  branch 
)

Called when TRY, EXCEPT, ELSE or FINALLY branches start.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 318 of file visitor.py.

◆ start_while()

def robot.model.visitor.SuiteVisitor.start_while (   self,
  while_ 
)

Called when a WHILE loop starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.result.keywordremover.WhileLoopItemsRemover, and robot.output.xmllogger.XmlLogger.

Definition at line 344 of file visitor.py.

◆ start_while_iteration()

def robot.model.visitor.SuiteVisitor.start_while_iteration (   self,
  iteration 
)

Called when a WHILE loop iteration starts.

    By default, calls :meth:`start_body_item` which, by default, does nothing.

    Can return explicit ``False`` to stop visiting.

Reimplemented in robot.output.xmllogger.XmlLogger.

Definition at line 374 of file visitor.py.

◆ visit_break()

def robot.model.visitor.SuiteVisitor.visit_break (   self,
  break_ 
)

Visits BREAK elements.

Definition at line 431 of file visitor.py.

◆ visit_continue()

def robot.model.visitor.SuiteVisitor.visit_continue (   self,
  continue_ 
)

Visits CONTINUE elements.

Definition at line 408 of file visitor.py.

◆ visit_for()

def robot.model.visitor.SuiteVisitor.visit_for (   self,
  for_ 
)

Implements traversing through FOR loops.

    Can be overridden to allow modifying the passed in ``for_`` without
    calling :meth:`start_for` or :meth:`end_for` nor visiting body.

Reimplemented in robot.result.keywordremover.AllKeywordsRemover.

Definition at line 174 of file visitor.py.

◆ visit_for_iteration()

def robot.model.visitor.SuiteVisitor.visit_for_iteration (   self,
  iteration 
)

Implements traversing through single FOR loop iteration.

    This is only used with the result side model because on the running side
    there are no iterations.

    Can be overridden to allow modifying the passed in ``iteration`` without
    calling :meth:`start_for_iteration` or :meth:`end_for_iteration` nor visiting
    body.

Definition at line 204 of file visitor.py.

◆ visit_if()

def robot.model.visitor.SuiteVisitor.visit_if (   self,
  if_ 
)

Implements traversing through IF/ELSE structures.

    Notice that ``if_`` does not have any data directly. Actual IF/ELSE branches
    are in its ``body`` and visited using :meth:`visit_if_branch`.

    Can be overridden to allow modifying the passed in ``if_`` without
    calling :meth:`start_if` or :meth:`end_if` nor visiting branches.

Definition at line 233 of file visitor.py.

◆ visit_if_branch()

def robot.model.visitor.SuiteVisitor.visit_if_branch (   self,
  branch 
)

Implements traversing through single IF/ELSE branch.

    Can be overridden to allow modifying the passed in ``branch`` without
    calling :meth:`start_if_branch` or :meth:`end_if_branch` nor visiting body.

Reimplemented in robot.result.keywordremover.AllKeywordsRemover.

Definition at line 259 of file visitor.py.

◆ visit_keyword()

def robot.model.visitor.SuiteVisitor.visit_keyword (   self,
  kw 
)

◆ visit_message()

def robot.model.visitor.SuiteVisitor.visit_message (   self,
  msg 
)

Implements visiting messages.

    Can be overridden to allow modifying the passed in ``msg`` without
    calling :meth:`start_message` or :meth:`end_message`.

Reimplemented in robot.result.keywordremover.WarningAndErrorFinder.

Definition at line 458 of file visitor.py.

◆ visit_return()

def robot.model.visitor.SuiteVisitor.visit_return (   self,
  return_ 
)

Visits a RETURN elements.

Definition at line 385 of file visitor.py.

◆ visit_suite()

def robot.model.visitor.SuiteVisitor.visit_suite (   self,
  suite 
)

Implements traversing through suites.

    Can be overridden to allow modifying the passed in ``suite`` without
    calling :meth:`start_suite` or :meth:`end_suite` nor visiting child
    suites, tests or setup and teardown at all.

Reimplemented in robot.result.configurer.SuiteConfigurer, robot.model.modifier.ModelModifier, and robot.model.configurer.SuiteConfigurer.

Definition at line 93 of file visitor.py.

◆ visit_test()

◆ visit_try()

def robot.model.visitor.SuiteVisitor.visit_try (   self,
  try_ 
)

Implements traversing through TRY/EXCEPT structures.

    This method is used with the TRY/EXCEPT root element. Actual TRY, EXCEPT, ELSE
    and FINALLY branches are visited separately using :meth:`visit_try_branch`.

Definition at line 285 of file visitor.py.

◆ visit_try_branch()

def robot.model.visitor.SuiteVisitor.visit_try_branch (   self,
  branch 
)

Visits individual TRY, EXCEPT, ELSE and FINALLY branches.

Definition at line 307 of file visitor.py.

◆ visit_while()

def robot.model.visitor.SuiteVisitor.visit_while (   self,
  while_ 
)

Implements traversing through WHILE loops.

    Can be overridden to allow modifying the passed in ``while_`` without
    calling :meth:`start_while` or :meth:`end_while` nor visiting body.

Definition at line 333 of file visitor.py.

◆ visit_while_iteration()

def robot.model.visitor.SuiteVisitor.visit_while_iteration (   self,
  iteration 
)

Implements traversing through single WHILE loop iteration.

    This is only used with the result side model because on the running side
    there are no iterations.

    Can be overridden to allow modifying the passed in ``iteration`` without
    calling :meth:`start_while_iteration` or :meth:`end_while_iteration` nor visiting
    body.

Definition at line 363 of file visitor.py.


The documentation for this class was generated from the following file: