Forum Discussion

msalvador's avatar
msalvador
Frequent Contributor
5 years ago

TestExectute run configuring project variable

Hi to all, In my project I have defined a variable(in section temporary variable), I use it to change enviroment, from production to quality. I want to run with testexecute configuring my var. My ...
  • tristaanogre's avatar
    5 years ago

    Correct... because TestExecute does not recognize the commandline switch "Environment".... there are commandline switches it does recognize but anything beyond those you need to write you're own code for.

     

    Two ways to do what you want, and I've done both with high success:

     

    1) Utilize Storages.INI object and methods to read values from an INI file into the desired variable or variables.  This allows you to alter the file as needed on different machines, etc., to create different unique run configurations.

     

    2) Write code to read the commandline of TestExecute and parse out commandline switches.   This is a little more complicated so here's the code I use for it, in JScript.

     

    function getCommandLineParameter(parameterString) {
        
        var string;
        var parameterListLength;
        var foundParameter;
        try {
            if (Sys.WaitProcess('TestExecute').Exists) {
                string = Sys.Process('TestExecute').CommandLine;
            }
            else {
                string = Sys.Process('TestComplete').CommandLine;
            }
            //Setting the list separator to grab a parameter     
            aqString.ListSeparator = '/';
            parameterListLength = aqString.GetListLength(string);
            for (var i = 1; i < parameterListLength; i ++) {
                if (aqString.Find(aqString.ToUpper(aqString.GetListItem(string, i)), aqString.ToUpper(parameterString)) != -1) {
                    foundParameter = aqString.GetListItem(string, i);
                    break;
                }    
            }
            if (foundParameter == undefined) {
                aqString.ListSeparator = '|';
                return -1;
            }
            //Resetting list separator back to default
            aqString.ListSeparator = '|';
            return aqString.SubString(foundParameter, aqString.Find(foundParameter, '=') + 1, foundParameter.length);
        }
        catch (exception){
            Log.Error('An error occurred getting the commandline parameter: ' + exception.message);
            return -1;
        } 
    }