Adding Command Line Variables with RobotCode

I am looking for a way to be able to easily pass a command line variable to a test… on some executions.

Currently I know how to edit the Robotcode extension settings and add an item in the Robot:Variables section. But it would be great if I could run the test by right clicking beside the Test Case name and have an option there to select running with or without the variable specified.

There is an option for “Execute using profile” underneath the “Run” and “Debug” but information on setting up profiles is sparse.

I’m open to other alternatives that are more convenient, I could create the variable directly in the code and comment it out as needed but I’m hoping for something more elegant than that.

Thanks!

In principle, something like this is possible, albeit with a new function of RobotCode that is not yet fully finished and has not been publicly announced. I plan to present it to a larger audience for the first time at RoboCon 2024 in February. But I still need a few testers who are willing to try it out beforehand and check the documentation that is still to be created. Do you have time and possibly interest?

2 Likes

Hi Daniel, thanks for the quick response. I’d definitely be willing to try it out and provide some feedback. Thanks!

ok, then let me activate the feature in the code and publish a new package and I’ll write a short guide here. I think I’ll be able to do that this weekend.

1 Like

Sounds good!

ok, there is a new version of robotcode, you need to update to at least 0.64.1.

Now you can create a launch.config if you don’t already have one.

Open your launch.config, now you can create a new “RobotCode: Test Profile” configuration.

It should look like this:

{
    "name": "RobotCode: Test Profile",
    "type": "robotcode",
    "request": "launch",
    "presentation": {
        "hidden": true
    },
    "purpose": "test-profile"
},

The important thing is the purpose property, which defines what this configuration is for. This must be test-profile. If your VSCode is already set for your normal execution, you can now overwrite certain settings. For example, the robot global variables or the environment variables:

Here are a few examples:

 {
    "name": "No Headless",
    "type": "robotcode",
    "request": "launch",
    "presentation": {
        "hidden": true
    },
    "purpose": "test-profile",
    "variables": {
        "HEADLESS": "False"
    }
  },
  {
    "name": "Test Env",
    "type": "robotcode",
    "request": "launch",
    "presentation": {
        "hidden": true
    },
    "purpose": "test-profile",
    "variables": {
        "URL": "https://test.app.com",
        "USER": "test_user"
    }
  },
  {
    "name": "Prod Env",
    "type": "robotcode",
    "request": "launch",
    "presentation": {
        "hidden": true
    },
    "purpose": "test-profile",
    "variables": {
        "URL": "https://prod.app.com",
        "USER": "prod_user"
    },
    "exclude": ["wip"]
  },

You can now select these profiles in the Test Explorer using the Run or Debug button. But also in the context menu of a test case or suite in the Explorer, but also on the Play button next to the test case in the Editor, via the “Execute Using Profile” entry,

You can also select the default profiles at the top of the Test Explorer, in the menu of the Run or Debug button. Please only select one profile at a time, otherwise the test will run 2 or 3 or 4 times at the same time. But this is a feature of VSCode, you just have to know it :wink:

Hope that fits, if you find bugs or have any suggestions, it is easiest if you put an entry on github: Issues · d-biehl/robotcode · GitHub

And thanks in advance for trying out!!!

Hi Daniel. I will download this and give it a try as soon as I can (hopefully tomorrow).

Tried it on 64.1 and upgraded to 66.0 this morning. It worked seamlessly on 66. No issues with attached pydebug config. I was able to run tests by default without the added variable config (but with the variables specified in Robot:Variables in setting) and as well run using the execute using profile to get the profile specific variables. This is perfect as I can setup variables for default test execution in the settings and profile specific variables for alternate execution (where both sets of variables will be introduced).

This will save me considerable annoyance. You, sir, are a prince among men. You have my gratitude.

2 Likes

thank you!!!

Hi Daniel. I see here the syntax to add variables and tags to a profile. And it works fine.
What would be the syntax to add --argumentfile Arguments.txt to the profile in launch.json
Thanks.

Sorry for the late answer,

try something like:

"args": [
   "--argumentfile", "Arguments.txt"
]