Evaluate in Robot Framework

Introduction

Evaluate allows you to run Python code in Robot Framework

Remainder of division

Let us use Evaluate to print the numbers that are divisible by 3 without a remainder.

The file print_multiple_of_3.robot contains code that prints all the numbers divisible by three in the range from 1 to 20.

*** Settings *** *** Test Cases *** Mod X ${x}= Set Variable ${0} FOR ${x} IN RANGE 1 20 ${x}= Evaluate ${x} + 1 ${mod_x}= Evaluate ${x}%3 Run Keyword If ${mod_x}==0 Log To Console ${x} END

robot print_multiple_of_3.robot

============================================================================== Print Multiple Of 3 ============================================================================== Mod X .3 6 9 12 15 18 Mod X | PASS | ------------------------------------------------------------------------------ Print Multiple Of 3 | PASS | 1 test, 1 passed, 0 failed ============================================================================== Output: /opt/robot/src/tests/output.xml Log: /opt/robot/src/tests/log.html Report: /opt/robot/src/tests/report.html

Article author: Andrei Olegovich