Skip to main content

Robot Framework State Machine Library

Project description

https://circleci.com/gh/marcinooo/robot-framework-state-machine/tree/main.svg?style=svg

Author:

marcinooo

Tags:

Robot Framework, Python, State Machine, Library

abstract:

Implementation of state machine in robot framework.

Description

Library contains implementation of state machine to control or test software components which can be in many states.

Documentation

It is a very simple library, so the documentation is included here. For the inquisitive I recommend reading the docstrings in file.

First of all import the library:

Library  StateMachineLibrary

Create a state machine:

Create State Machine  name=blink-machine

You can create as many as you want state machines. Each state machine should have a unique name.

Register keywords that should be executed in the given state (Turn On Light) and during its update (On Update Turn On Light):

Add State  state=Turn On Light   on_update=On Update Turn On Light   sm=blink-machine

Both keywords must be defined:

*** Keywords ***
# ...
Turn On Light
    # ...

On Update Turn On Light
    Go To State  state=Turn Off Light  sm=blink-machine

Keywords On Update… should indicate the next state:

Go To State  state=Turn Off Light  sm=blink-machine

Call the same kewyord to enter the first state.

Force transition to a new state:

Update State  sm=blink-machine

You can pass data between states in context (recommended method) or using global variables.

*** Keywords ***
# ...
Turn On Light
    # ...
    &{context_chunk}=    Create Dictionary    led_status=ON
    Update Context    sm=blink-machine    item=${context_chunk}

Turn Off Light
    # ...
    &{context}=    Get Context  sm=blink-machine
    Log To Console    LED is ${context["led_status"]}

Usage

An example of using the library for LED blinking (of course, the library was created for more complex tasks :wink:).

*** Settings ***
Library  StateMachineLibrary

*** Tasks ***
Blink
    [setup]  Task Setup
    Go To State  state=Turn On Light  sm=blink-machine
    Repeat Keyword  100 times  Update State  sm=blink-machine

*** Keywords ***
Task Setup
    Create State Machine  name=blink-machine
    Add State  state=Turn On Light   on_update=On Update Turn On Light   sm=blink-machine
    Add State  state=Turn Off Light  on_update=On Update Turn Off Light  sm=blink-machine

Turn On Light
    Log To Console  Turn On Light...
#    Sleep    0.5s    # if you have real led then you need this ;)

On Update Turn On Light
    Go To State  state=Turn Off Light  sm=blink-machine

Turn Off Light
    Log To Console  Turn Off Light...
#    Sleep    0.5s    # if you have real led then you need this ;)

On Update Turn Off Light
    Go To State  state=Turn On Light   sm=blink-machine

Flow diagram:

Flow diagram for above code

Installation

Install from PyPI:

$ pip install robotframework-statemachinelibrary

Install from github:

$ pip install git+https://github.com/marcinooo/robot-framework-state-machine

License

license (MIT)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework-statemachinelibrary-1.0.2.tar.gz (8.4 kB view details)

Uploaded Source

File details

Details for the file robotframework-statemachinelibrary-1.0.2.tar.gz.

File metadata

File hashes

Hashes for robotframework-statemachinelibrary-1.0.2.tar.gz
Algorithm Hash digest
SHA256 176f425fe30ae970e6c37c437c71add6eda33bd44bc6cf5cf4f70a13b6c5aceb
MD5 6814a4e2538ef3e56f826b2ecd6a6a5f
BLAKE2b-256 775043e8db835c1319cef29b896f9bb8ed38aefbbb4bc8522401917aae1f11ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page