DEV Community

Cover image for Robot Framework: Pass Boolean variables from command line
Laura Ojala
Laura Ojala

Posted on • Edited on

2 2

Robot Framework: Pass Boolean variables from command line

I am often googling how to pass Boolean Command Line arguments in the Robot Framework when starting tests. The answer is: True and False work (case is important here as this is Python).

In some earlier releases, 0 and 1 were seen as Boolean but that does not apply in the newer Robot Framework versions.

Example, passing CLI (Command Line Interface) variables

Below is an example that tests that variable MY_BOOLEAN is Boolean type (so tests pass both with True and False).

I wanted to play with the new Python Inline Evaluation (see User Guide here) so the example has another test that uses that (both tests test exactly the same thing, the only difference is the syntax):

*** Settings ***
Documentation Evaluates if variable passed from command line is Boolean type
... Requires Robot Framework version 3.2 or newer
... Arguments are passed for a test like this:
... robot --variable MY_BOOLEAN:False path/to/this/file
... Tests pass both for "True" and "False" and should fail for any other inputs.
*** Variables ***
${MY_BOOLEAN} not boolean - tests fail with this
*** Test Cases ***
Variable Type Should Be Boolean
${is_boolean} Evaluate type(${MY_BOOLEAN}) == bool
Should Be True ${is_boolean}
Variable Type Should Be Boolean - Python Inline Evaluation
[Documentation] Uses Python Inline Evaluation
... Testing same thing as "Variable Should Be True"
Should Be True ${{ type(${MY_BOOLEAN}) == bool }}

And to start that test, MY_BOOLEAN is given using --variable notation:

robot --variable MY_BOOLEAN:False path/to/tests/
Enter fullscreen mode Exit fullscreen mode

Or, in a shorter form using -v:

robot -v MY_BOOLEAN:True path/to/tests/
Enter fullscreen mode Exit fullscreen mode

Closing words

Next time when I google "robot framework how to pass boolean command line arguments" I hopefully pop into this blog post 🤓. Maybe this post might also help with the concept of passing Robot Framework variables from the command line.

ps. Passing multiple arguments is done by adding multiple -v "blocks":

robot -v MY_VARIABLE:cat -v SOME_OTHER_VARIABLE:dog path/to/tests/
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
ozyalhan profile image
Ozgur Alhan

It's good point to start, thanks

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay