Forum Discussion

nicklott's avatar
nicklott
Occasional Contributor
7 years ago

How To Use Parameters To Change The URL

We have a suite of tests that we kick off using a PowerShell script every time there's a product deploy. We have 2 environments where the tests run: A QA environment and a "live" environment. Currently, when we want to run the tests in one of the environments, we go to the project suite variables tab and change the URL variable for the project suite to the URL that we want to run the tests on right before we deploy to that environment.

 

What we're trying to do now is set the tests up in a way so that every time there's a deploy to our QA environment or the "live" environment, the tests will automatically kick off in the environment that we deployed to without someone manually having to go into the project suite variables and changing the URL. I'm thinking that the best way to go about that is to pass in that project variable as a parameter somehow, but I have no idea how to go about doing that.

 

I did a Google search and came across this video on the TestComplete support site, but the video never loaded or played for me: https://community.smartbear.com/t5/TestComplete-General-Discussions/Running-Test-Execute-file-from-powershell/td-p/126056

 

Any other ideas or suggestions on how we can get the tests to automatically run in the correct environment would be greatly appreciated.

16 Replies

  • We use a Windows Environment variable and matching TestComplete ProjectSuite level variable on our Virtual Machines that are kicked off via Jenkins. Jenkins sets the Windows Environment variable on the VM and we have a TestComplete script that pulls that value down and sets it as the server URL value.

     

    Then we can add new test environments completely in Jenkins and let TestComplete use the same script at the beginning of each test run. This approach cuts down on our initial overhead and maintenance.

     

    Currently we have about 15 different URLs we use for our live and test environments and about 12 different TestComplete projects that we can kick off individually or in tandem.

    • nicklott's avatar
      nicklott
      Occasional Contributor

      Thanks for responding! We use Octo as opposed to Jenkins. I know there's a place in Octo where you can set the environment that you want to deploy to. What we're trying to do is capture the environment from Octo, and set the environment variable in the ProjectSuite to be whatever that Octo environment is, so that the tests kick off when we deploy. It's virtually the same thing that you're describing, except we're trying to use Octo to do it instead of Jenkins.

       

      Could you share an example of the TestComplete script that you guys are using to pull the environment value down from Jenkins?

      • bo_roop's avatar
        bo_roop
        Contributor

        Sample Code:

         

        ServerURL = aqEnvironment["GetEnvironmentVariable"]("TC_ServerURL")
          // Set the TestComplete variable if the value isn't blank.
          if(ServerURL != "")
          {
            Log["Message"]("The Windows TC_ServerURL Environment Variable = " + ServerURL);
            // Save the URL to the projectSuite variable ServerURL
            ProjectSuite["Variables"]["ServerURL"] = ServerURL
          }
          else
          {
            Log["Warning"]("The ServerURL environment variable is blank. We'll use whatever is there currently.")
          }

        Enjoy!

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    What I've done in the past to configure things to run differently on different machines is created an INI file in some directory for the machine in question.  I would then make my setting changes in that INI file and let it remain permanently on that machine.  At the beginning of a test run, I had code that would read that INI file and then update Project variables to the values in the INI.  This would then set up the environment for the test run.

     

    Another option you have is to use a custom commandline parameter.  In order to do so, you need to write code to be able to read that command line parameter and utilize it within you tests.  I created a script extension not too long ago that contains this code.

    https://bitbucket.org/privateteamogre/scriptextensions/downloads/OgreUtilities.tcx

     

    If you have any questions on how to use that utility, let me know via PM.

    • nicklott's avatar
      nicklott
      Occasional Contributor

      Thanks for the reply!

       

      I'm thinking the INI route may be the better way to go. Could you provide an example (or offer any additional insight) in the INI file? Specifically, the code that I would need to have in place to read the INI file and update the URL variable to the value in the INI file. Thanks!

    • nicklott's avatar
      nicklott
      Occasional Contributor

      Question about the custom command line parameter script extension that you referenced: the getTCCommandLineParam. What do I need to do to get that parameter and use it in my TestComplete script? Here's an example of what I'm thinking:

       

      Powershell script:

      $testexecute = "C:\Program Files (x86)\SmartBear\TestExecute 12\Bin\TestExecute.exe"

      $p = Start-Process -filepath $testexecute "`"X:\QA\Automated Testing\Vortex\Vortex.pjs`"", /environment qa, /run, /exit

       

      TestComplete Script:

      function environment()
      {
       //Set environment and browser variables based on parameter
       ProjectSuite.Variables.Environment = getTCCommandLineParam(environment);

      }

       

      That TestComplete script will be the first thing that runs after the Powershell script runs and opens up TestExecute to run all of the tests in that Vortex project suite. Am I on the right track, or would I need to do something different to get that parameter and then use it in the TestComplete script?

       

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You'll need to reference the object so the code should look something like:

         

         

        function environment()
        {
         //Set environment and browser variables based on parameter
         ProjectSuite.Variables.Environment = ogreUtils.getTCCommandLineParam(environment);
        }

         

         

        That should retrieve the value of the environment command line switch.  However, the code as I've written it uses the equal sign in the parameter... so your powershell should look something like the following where the environment is set to equal qa.:

        $testexecute = "C:\Program Files (x86)\SmartBear\TestExecute 12\Bin\TestExecute.exe"
        $p = Start-Process -filepath $testexecute "`"X:\QA\Automated Testing\Vortex\Vortex.pjs`"", /environment=qa, /run, /exit

        Let me know if this works for you or if you have additional questions.