Passing Variables to a macro (cmd_var9, DateOfBirth=)

Hi,

I’m just starting out and have a macro that works when I use the UI but fails when I use a Windows command line (all the MANY “parameters” currently hardcoded), I’ll worry about that part later unless someone can hint at a solution for that.

I really can’t believe that I can’t name my own variables (FirstName=, DateOfBirth= etc), but then to find you are limited to 3 only hardcoded ones sounds incredible. If there was a reason these 3 had to be hardcoded (which I doubt) then I’d have expected at least 9 and why not 20+?

the command line. Inside the macro you can access the value with the [internal variables]
(UI Automation Open-Source Selenium IDE plus additional features, iMacros alternative). ${!cmd_var1}, ${!cmd_var2} and ${!cmd_var3}

I assume everyone has to work around this design deficiency so how does one do that (if it matters I have the xfile stuff installed)?

Hi, there are several ways to pass more than 3 values (variables) to the UI.Vision Selenium IDE. I know these options:

1 Like

Thanks, I’ll probably go split() just to avoid the need for another file, I was thinking of creating a file new CSV in the script but I can’t see any way to delete the possibly existing file and the save ini function concatenates to the end (no option to start a new one).

Hopefully the developers will do something about this problem, should take them a very small number of minutes/hours… It would also make everyone’s code more understandable (“FirstName” instead of “s1”, given the lack of reusable code I’m not going to customise this, I’ll just copy & paste standard snippets)

I also wish there was a well written basic getting started guide. I very nearly gave up on this product due to the poor documentation (at least for anyone starting out). Maybe when I know it better I’ll try a simple video…

@ulrich
Thanks for the tip on using split, I didn’t like any of the solutions so here is my generic one that supports up to 9 parameters (“cl1” to “cl9”). See the last commented out commands to see how to execute this macro from another (no need to copy/paste) as well as example command line parameters.

This takes from 0 to 3 parameters (all optional with defaults):

  1. cmd_var1: This is used to pass the command line parameters, packed by the delimiter.

  2. cmd_var2: Specifies the delimiter character(s). This is the backtick (“`”) by default.

  3. cmd_var3: Specifies the value that should be placed into “cl1” to “cl9” if there are not enough supplied. This is an EMPTY string by default.

The following got a bit mangled (backticks removed for starters) so I have attached the source as a file.
GetCommandLineParameters().zip (1.4 KB)

{
      "Name": "GetCommandLineParameters()",
      "CreationDate": "2022-1-27",
      "Commands": [
        {
          "Command": "store",
          "Target": "fast",
          "Value": "!replayspeed",
          "Description": "Set the Replay speed to FAST"
        },
        {
          "Command": "comment",
          "Target": "Dennis Bareis v2022.01.27b #### GET PASSED VARIABLES in 'cmd_var2' (DELIMITED by 'cmd_var1')  ####",
          "Value": "",
          "Description": "[EXAMPLE1]: ...&cmd_var1=821226`Some Name`0618 076 228`(09) 9647-0780`Somebody@gmail.com [EXAMPLE 2]: ...&cmd_var2=**&cmd_var3=NotSetOnCmdLine&cmd_var1=821226**Some Name**0618 076 228**(09) 9647-0780**Somebody@gmail.com"
        },
        {
          "Command": "store",
          "Target": "${!cmd_var1}",
          "Value": "CmdLine",
          "Description": "'!cmd_var2' contains all the parameters, they are split apart by occurances of '!cmd_var1'"
        },
        {
          "Command": "if_v2",
          "Target": "${!cmd_var2} == \"NOT_SET\"",
          "Value": "",
          "Description": "If its unspecified we will default to \"`'"
        },
        {
          "Command": "store",
          "Target": "`",
          "Value": "CmdLineDel",
          "Description": "Set the default delimiter as the caller didn't specify it."
        },
        {
          "Command": "else",
          "Target": "",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "store",
          "Target": "${!cmd_var2}",
          "Value": "CmdLineDel",
          "Description": "Get the delimiter, make this a single 'unlikely' character or as many characters as you wish to ensure it is unique"
        },
        {
          "Command": "end",
          "Target": "",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "if_v2",
          "Target": "${!cmd_var3} == \"NOT_SET\"",
          "Value": "",
          "Description": "If its unspecified we will default to \"\""
        },
        {
          "Command": "store",
          "Target": "",
          "Value": "CmdLineDef",
          "Description": "Set the default value for unspecified command line parameters (defaults to empty string)."
        },
        {
          "Command": "else",
          "Target": "",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "store",
          "Target": "${!cmd_var3}",
          "Value": "CmdLineDef",
          "Description": "Get the default value for unspecified parameters (the user specified it)"
        },
        {
          "Command": "end",
          "Target": "",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "store",
          "Target": "true",
          "Value": "!ErrorIgnore",
          "Description": "Don't stop script if there are not enough parameters from the command line"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl1",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl2",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl3",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl4",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl5",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl6",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl7",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl8",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "store",
          "Target": "${CmdLineDef}",
          "Value": "cl9",
          "Description": "Set default value (empty string by default)"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[0].trim();",
          "Value": "cl1",
          "Description": "SET [cl1]: Command line parameter #1"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[1].trim();",
          "Value": "cl2",
          "Description": "SET [cl2]: Command line parameter #2"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[2].trim();",
          "Value": "cl3",
          "Description": "SET [cl3]: Command line parameter #3"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[3].trim();",
          "Value": "cl4",
          "Description": "SET [cl4]: Command line parameter #4"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[4].trim();",
          "Value": "cl5",
          "Description": "SET [cl5]: Command line parameter #5"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[5].trim();",
          "Value": "cl6",
          "Description": "SET [cl6]: Command line parameter #6"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[6].trim();",
          "Value": "cl7",
          "Description": "SET [cl7]: Command line parameter #7"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[7].trim();",
          "Value": "cl8",
          "Description": "SET [cl8]: Command line parameter #8"
        },
        {
          "Command": "executeScript_Sandbox",
          "Target": "return ${CmdLine}.split(${CmdLineDel})[8].trim();",
          "Value": "cl9",
          "Description": "SET [cl9]: Command line parameter #9"
        },
        {
          "Command": "echo",
          "Target": "CMDLINE: #1=${cl1}, #2=${cl2}, #3=${cl3}, #4=${cl4}, #5=${cl5}, #6=${cl6}, #7=${cl7}, #8=${cl9}, #9=${cl9} [DEL=${CmdLineDel}, DEFAULT-EMPTY=${CmdLineDef}]",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "store",
          "Target": "false",
          "Value": "!ErrorIgnore",
          "Description": "Back to normal state, STOP SCRIPT ON ERROR"
        },
        {
          "Command": "store",
          "Target": "true",
          "Value": "!STATUSOK",
          "Description": "We don't care about any previous errors"
        },
        {
          "Command": "comment",
          "Target": "pause // ",
          "Value": "",
          "Description": ""
        },
        {
          "Command": "comment",
          "Target": "run // GetCommandLineParameters()",
          "Value": "",
          "Description": "### HOW TO CALL THIS #### Get Command Line Parameters into cl1 ~ cl9"
        }
      ]
    }