Skip to content Skip to sidebar Skip to footer

How To Pass A List As Command Line Argument In Robot Framework.?

I am trying to pass a list as a command line argument to a robot script using -v option. Since this is not directly supported i am trying some workaround like, robot -v list_arg:a_

Solution 1:

Although I don't like it much, I was able to iterate through the list created by Split String from String library.

*** Settings ***
Library    String

*** Test Cases ***
List Of Variables From CLI
    @{list_of_vars}    Split String    ${my_vars}
    :FOR    ${var}    IN    @{list_of_vars}
    \    Log    ${var}    WARN

robot -v my_vars:1_2 -E space:_ -t "List Of Variables From CLI" .

Solution 2:

When passing data structures to Robot Framework using Variable Files would probably be a better option considering you're already converting one structure into a command line compatible one. Adding a variable file uses the -V c:/path/to/file.ext syntax.

There are roughly two approaches:

  1. Static: this is a text file containing the variable structures you seek. This can be in two formats:

    • Python: declare the variable structures using regular Python syntax variable syntax
    • YAML: using the YAML syntax it is possble to create Robot Framwork lists, dictionaries and strings.
  2. Dynamic: in this scenario the Robot variables are generated and returned by Python code:

    • Simple Python Function: using the get_variables(arg)function is the simplest way of returning a dynamic number of variables or a dynamic structure of data.
    • Dynamic Python Class: using a variable class it's possible to hide certain variables, have a fixed set of variables that are complemented by init() based on given input or have all of them generated dynamically.

In most cases the yaml structure is a good way of providing clean way of writing and maintaining an input file:

string:Hello,world!integer:42list:-one-twodict:one:yksitwo:kaksioriginal:&orgitem1:fooitem2:barreferenceorg:*org

Post a Comment for "How To Pass A List As Command Line Argument In Robot Framework.?"