Forum Discussion

Floris's avatar
Floris
Occasional Contributor
6 years ago

Passing a parameter from Azure/devops into TestComplete

Hi, 

 

i am recently start using TestComplete. I wonder how can I use paramters from a VsTest (e.g. Override Parameters) in order to pass a url from the pipeline into TestComplete as a parameter.

 

Looking forward to your help!

  • Ok, I have the answer from:
    Thank you for reaching out to us. Currently, it's not possible to control what parameters TestComplete will be launched with when using the Azure DevOps integration. So, I suggest that you pass the parameter to the agent machine using a scripting task (
    CMD or Powershell). For example, you can create a file and store the URL there or set an environment variable
    that will hold the value. Then, you need to modify the test accordingly so that the URL is ready from the file or obtained from the environment variable.

     

    With this answer from SmartBear self in mind, I created an xml file in the directory:

    <?xml version="1.0"?>

    -<configurations>

    -<settings>

    -<setting>

    <url>#{EnvironmentUrl}#</url>

    </setting>

    </settings>

    </configurations>

    The #{..}# are used to replace the url as token from Azure Pipeline.

     

    Then i wrote this script:

    function RetrieveUrlFromDeployment()
    {
    // Create a COM object
    var configFileXML = Sys.OleObject("Msxml2.DOMDocument.6.0");
    configFileXML.async = false;

    // Load data from a XML file
    configFileXML.load("../Project/ConfigTestComplete.xml");

    // Set error message when failure
    if(configFileXML.parseError.errorCode != 0)
    {
    var errorMessage = "Reason:\t" + configFileXML.parseError.reason + "\n" +
    "Line:\t" + aqConvert.VarToStr(configFileXML.parseError.line) + "\n" +
    "Pos:\t" + aqConvert.VarToStr(configFileXML.parseError.linePos) + "\n" +
    "Source:\t" + configFileXML.parseError.srcText;
    // Post an error to the log and exit
    Log.Error("Cannot parse the document.", errorMessage);
    return;
    }

    // Use an XPath expression to obtain a list of "url" nodes
    var nodes = configFileXML.selectNodes("url");

    // Set Project variable to environment url.
    Project.Variables.url_loginscreen = nodes.context.text;
    }

     

    This will result that TC will be able to get indirectly receive a url from Azure pipeline.

    • Floris's avatar
      Floris
      Occasional Contributor

      Thanks Marsha_R  for your reply. If a read the parent item of this article, it says that using TcItem is or will become obsolete.

       

      I would rather use the Test Adapter, but i still dont know how to pass parameters through from azure. 

      • Floris's avatar
        Floris
        Occasional Contributor

        i found  a solution. 

         

        First, I entered an overriding paramter within the pipeline.

        Then, I found a script to retrieve parameters from the commandline.

         

        function ProcessCommandLine() {
        var i;
        for (i = 1; i <= BuiltIn.ParamCount(); i++) {
        ProcessCommandLineArgument(BuiltIn.ParamStr(i));
        }
        }

        function ProcessCommandLineArgument(arg) {
        var items;
        items = arg.split("=");
        if (items.length != 2) {
        return;
        }
        switch (aqString.ToLower(aqString.Trim(items[0]))) {
        case "env":
        Log.Message("The 'env' argument is found! The value is '" +
        aqString.Trim(items[1]) + "'");
        var url_deployment = items[1];
        Project.Variables.url_loginscreen = url_deployment;
        break;
        }
        }

         

        now my persistent Variable url_loginscreen is changed and ready to be used with the given parameter from the commandline.