Keyword as a Robot Framework decorator

Introduction

In the robot, you can use Run Keyword to pass one keyword to the arguments of another.

In essence, one keyword will work as a decorator for the second.

Example

Let's write a keyword Find Negative Values In, which will return only negative numbers from the results of another keyword.

*** Settings *** Documentation Keyword as decorator *** Variables *** @{array} ${-4} ${-3} ${-2} ${-1} ${0} ${1} ${2} *** Test Cases *** Negative Even Numbers ${negative_even} Find Negative Values In Fetch Even Numbers From List ${array} Log To Console ${negative_even} *** Keywords *** Find Negative Values In [Arguments] ${keyword} @{args} &{kwargs} ${list} Run Keyword ${keyword} @{args} &{kwargs} ${negative_numbers} Evaluate [i for i in $list if i < 0] RETURN ${negative_numbers} Fetch Even Numbers From List [Arguments] ${list} ${even_numbers} Evaluate [i for i in ${list} if i % 2 == 0] RETURN ${even_numbers}

============================================================================== Demo :: Keyword as decorator ============================================================================== Negative Even Numbers .[-4, -2] Negative Even Numbers | PASS | ------------------------------------------------------------------------------ Demo :: Keyword as decorator | PASS | 1 test, 1 passed, 0 failed ==============================================================================

Related Articles
Robot Framework
Architecture
Logs
__init__.robot
Create custom .py libs
Path to libs and resources
Keyword as decorator
Template
Parametrize
Demo with pywinauto

Search on this site

Subscribe to @aofeed channel for updates

Visit Channel

@aofeed

Feedback and Questions in Telegram

@aofeedchat