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:

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

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

test1:
  color: red

test2:
  color: red and size: small

test3:
  shape: square
  or
  color: red and size: small
  or
  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:
device4:
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

Hi,

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’

Br,
Sami

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:
mytests.robot

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

test2
    [Tags]    triangle
    Log Test 2

test3
    [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.:

test3
    [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

Dave.