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 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.1.tar.gz (8.3 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for robotframework-statemachinelibrary-1.0.1.tar.gz
Algorithm Hash digest
SHA256 95a5c405d8bf0d374c7f5864c63e06cad4cc69e695aab5637cf5f85e979f5b08
MD5 a8057d105e5a270024d245f037ef092d
BLAKE2b-256 32deb515e79c5caffa28e8196b00022adb78a699d95a3cc0a08fd33cc0e79eae

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