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 ==============================================================================

Article author: Andrei Olegovich

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 this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: