Advice on how to use tags for my use-case

Hello all. I need advice on how to leverage tags or another function/service in robot framework to properly map devices to tags.

Let’s say you have the following:

  color: red
  size: large
  shape: circle
  color: blue
  size: large
  share: square
  color: red
  size: small
  shape: triangle

Now let’s say you have the following tests and requirements for what devices can/should run them:

  color: red

  color: red and size: small

  shape: square
  color: red and size: small
  color: green

Based upon this:
test1 → device1, device3
test2 → device3
test3 → device2, device3

How can I leverage tags (or another builtin function of Robot) to achieve this?

I need it such that if I add a new device4 with the following attributes:
color: green
shape: square
size: small

It will automatically get assigned test3 and skip test 1 and 2. Device 4 match the size requirement on test2, but not the color requirement so it’s skipped.

1 Like


One solution would be to use Skip or Skip If keywords in test setups. Skip the test case if the device attributes don’t match the test requirements.
E.g. Setup for test 1 could be something like this:
Skip If not ‘${COLOR}’==‘red’


Hi Nick,

Robot framework doesn’t have anything builtin to do what you’re asking, but it would be easy enough to do with a simple pre-processor script.

Consider this matrix:

test 1 test 2 test 3
device 1 x
colour: red x
size: large
shape: circle
device 2 x
colour: blue
size: large
shape: square x
device 3 x x x
colour: red x
size: small
shape: triangle x x
  • Test 1 has the colour red in common, so apply the tag red for test 1
  • Test 2 only applied to device 3 and it has a colour and a size in common with the other devices so we should use shape triangle for the tag on test 2
  • Test 3 applies to both device 2 and 3, these devices have nothing in common but they have a colour or a size in common with device 1, so we should use the shape tags triangle and square on test 3

Now you build your pre-processor script to read the properties for the device and generate an -- include sequence to add to the robot command (see Tag patterns) as an example for device 1 this could be either

  • --include red --include large --include circle
  • --include redORlargeORcircle

Then you tag your test cases as shown in Tagging test cases

So putting it all together, your robot file would look something like:

*** Test Cases ***
    [Tags]    red
    Log Test 1

    [Tags]    triangle
    Log Test 2

    [Tags]    triangle    square
    Log Test 3

And the command line your pre-processor would generate would look something like

$ robot --include red --include large --include circle mytests.robot

You can also have the tag format proertyname:value e.g.:

    [Tags]    shape:triangle    shape:square
    Log Test 3

Some final notes:

  • Remember spaces are difficult to deal with when generating a command line so best avoid spaces in your tags
  • If you want to use the OR / AND / NOT logic operator style the tags need to be in lower case so it’s a good idea to avoid upper case letters in your tags as well.

I hope that helps