Modifying the Settings section programaticly

Hello guys,

I ran into a problem with combining the console parameters and test suite parameters.

What I want to do is to automatically insert key:value pairs to the Settings section of a test suite and turn these pairs into suite Metadata.
After that I will start a dry run and collect all the metadata from the output.xml using ExecutionResults.
What I am struggling with is the modification of the test suite.
Is there an easy way to do it? E.g. using the SuiteVisitor & pre-run modifier? I was experimenting with that but could not make it work.

Hope you’re having a great time!
David

Hi David,

You can add metadata in when you run the robot using:

 -M --metadata name:value *  Set metadata of the top level suite. Value can
                          contain formatting and be read from a file similarly
                          as --doc. Example: --metadata Version:1.2

The -M option can be added many times

There is also the -v option for variables:

 -v --variable name:value *  Set variables in the test data. Only scalar
                          variables with string value are supported and name is
                          given without `${}`. See --variablefile for a more
                          powerful variable setting mechanism.
                          Examples:
                          --variable name:Robot  =>  ${name} = `Robot`
                          -v "hello:Hello world" =>  ${hello} = `Hello world`
                          -v x: -v y:42          =>  ${x} = ``, ${y} = `42`

This can also be added many times, but would need post processing to add as metadata.

combining those 2 keywords with a Suite setup might be what you’re after

Hopefully that helps,

Dave.

Hi Dave,

Thank you for your answer.
I was trying to avoid adding the metadata using the console parameter --metadata as the number of metadata to be added can vary and it would lead to quite a messy inside of a subprocess.run which is used to trigger the dry-run … or I might just not be skilled enough not to make it messy.

So far my solution is following:

  1. Dry-run execution without any special parameters.
  2. Extraction of all the metadata from the dry-run output.xml into a dictionary using ExecutionResults.
  3. Extraction of all the metadata from the string containing variable number of console metadata to another dictionary.
  4. Updating the first dictionary with the latter to ensure that the suite metadata are overwritten with the console ones.

What I have so far works quite well, but being able to change the suite settings directly would help in seeing all the metadata in one place (excluding the log/output)

David

Hi David,

subprocess.run, I’m guessing that the python subprocess module? if so it takes a list as it’s first argument. the first item in the list is the command (robot) and the remaining are the command line options, so if you have a list of metadata you want to add, it would be quite easy to loop over them and in the loop forst append a -M and then append the metadata to the robot command list.

Something like this:

mymetadata = "key1:value1,key2:value2,key3:value3".split(',')
robotcmd = ["robot"]
for metadata in mymetadata:
    robotcmd.append("-M")
    robotcmd.append(metadata)

robotcmd.append("mytests.robot")
subprocess.run(robotcmd)

Obviously I just typed this without testing, so it may need tuning but should give you the idea,

I do something similar to this in RFSwarm with a dynamic list of metadata and variables.

Dave.

1 Like

Hi Dave,

You guessed that right and your example is exactly what I was looking for.
It looks so simple but somehow the idea was avoiding me :see_no_evil:

Thank you very much for the advice!
David

1 Like