Template

class aiviro.modules.template.BaseScenario(config: YAMLConfig, logging_enabled: bool = True)

Base object to inherit from for scenario initialization. It helps to create robots and other basic objects based on the provided yaml-config file.

Parameters:
  • config – configuration file containing all necessary parameters

  • logging_enabled – if True then logging will be initialized

Example:

>>> import aiviro
>>> from aiviro.modules.config import YAMLConfig
>>>
>>> class Story01(aiviro.BaseScenario):
...     def _before_run(self):
...         # some logic before scenario run
...         pass
...
...     def _after_run(self):
...         # some logic after scenario run
...         pass
...
...     def _run(self):
...         r = self.robot("rdp")
...         r.click(aiviro.Button("Start"))
...         # additional logic of the scenario
>>>
>>> if __name__ == "__main__":
...     # initialize and merge configs
...     main_config = YAMLConfig("main_config.yaml")
...     story_config = YAMLConfig("story01.yaml")
...
...     # initialize scenario with merged config
...     story = Story01(main_config | story_config)
...     story.start()
...     story.close()
property config: YAMLConfig

Returns configuration object.

property logger: CustomLoggerAdapter

Returns main logger of the scenario.

property error_handler: ErrorHandler

Returns error handler object.

>>> import aiviro
>>> class Story01(aiviro.BaseScenario):
...     def _run(self):
...         r = self.robot("rdp")
...         r.click(aiviro.Button("Start"))
...         try:
...             r.click(aiviro.Button("Stop"))
...         except aiviro.SearchObjectError as e:
...             self.error_handler.collect(e)
robot(robot_name: str) DesktopRobot | WebRobot | RDPRobot

Returns robot by its name. Supported robots are DesktopRobot RDPRobot WebRobot. Name and type of the variables must correspond to the arguments of create_*_robot methods, see Create Robot section.

Parameters:

robot_name – name of the robot

robot:
  bender:
    type: rdp
    remote_address: 10.128.32.51
    username: robot-username
    password: secret-password
    domain: company
    auto_reconnect: True
    shared_folder: /home/robot/shared
  anicka:
    type: rdp
    remote_address: 10.128.32.42
    username: robot-username-2
    password: secret-password-2
    domain: company
email_client() EmailClient

Returns email client instance. Arguments and auth key of the SMTP or IMAP authorization method must correspond to the following methods:

email:
  client:
    smtp:
      auth: basic_auth
      server: smtp-mail.outlook.com
      username: robot
      password: password
      sender_name: Aiviro Robot
      email_address: robot@aiviro.com
    imap:
      auth: outlook_oauth2_confidential
      username: user@name.com
      client_id: 1234567890
      authority_url: https://login.microsoftonline.com/directory-id
      secret: 1234-asdf-5678-zxcv-9012
set_email_extractor_params(attachment_conditions: List[BaseCondition]) None

Sets additional parameters for email extractor.

Parameters:

attachment_conditions – argument passed to email-extractor constructor

email_extractor() EmailExtractor

Returns email extractor instance. Name and type of the variables must correspond to the constructor arguments of EmailExtractor class. For setting additional parameters, use set_email_extractor_params() method.

email:
  extractor:
    source_dir: robot/invoices
    processed_dir: robot/processed
    unprocessed_dir: robot/unprocessed
    max_valid_emails: 10
email_notifier() EmailNotifier

Returns email notifier instance. Name and type of the variables must correspond to the constructor arguments of EmailNotifier class.

email:
  notifier:
    report_title: My Super Title
    recipients:
      - r1@cmp.com
      - r2@cmp.com
      - r3@cmp.com
start()

Starts the scenario. First calls _before_run(), then _run() and finally _after_run().

_before_run()

Method called before the scenario is started. Called before _run() method.

_after_run()

Method called after the scenario is finished. Called after _run() method.

Note

This method is called even if the _run() raise an exception. The exception is raised after this method is called.

abstract _run()

Contains the main logic of the scenario.

_on_error(exp: Exception | None = None) None

Method called when the scenario, specifically _run() method fails with an unhandled exception.

Parameters:

exp – exception that was raised

close()

Closes all initialized objects.