Forum Discussion

jromie's avatar
jromie
New Contributor
9 years ago
Solved

determine whether testexecute is running or testexecute

Is it possible through JScript to determine whether a test is run via TestExecute vs TestComplete? It would be nice if I can turn some settings off for one and have them turned on for the other.

  • You can check for the process:

     

    if sys.WaitProcess("testcomplete", 0).exists then
    ...

4 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    The correct way is to check BuiltIn.ParamStr(0) - it returns the test runner path (TestComplete path or TestExecute path).

     

    WaitProcess("TestComplete") can theoretically cause a false positive if both TestComplete and TestExecute are running at the same time (as of v.11.20 they cannot, but it might change in the future).

     

    var testrunner_path = BuiltIn.ParamStr(0); // Example: "C:\Program Files\...\TestComplete.exe"
    var testrunner = aqFileSystem.GetFileNameWithoutExtension(testrunner_path);
    switch (testrunner)
    {
      case "TestComplete":
        // ...
        break;
      case "TestExecute":
        // ...
        break;
      default:
        // This shouldn't happen
        Log.Error("Unknown test runner: " + testrunner_path)
    }

     

    UPD: Here's another way that will work correctly:

     

    var testrunner = Sys.FindId(Win32API.GetCurrentProcessId()).ProcessName;
    // "TestComplete" or "TestExecute"
    • jmcpeek's avatar
      jmcpeek
      Contributor

      For the paramstr option, it's my understanding that builtin.paramcount is 0 unless it's being executed via command line. So if you execute tests manually and via command line, that code would only work when run via command line. That's how I'm determining whether the run is an automated run vs. a manually executed run.

       

      getcurrentprocessid is a a better way than my proposal to check for the process, I wasn't aware of this method.

       

      Thanks!

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        jmcpeek wrote:

        For the paramstr option, it's my understanding that builtin.paramcount is 0 unless it's being executed via command line. So if you execute tests manually and via command line, that code would only work when run via command line. That's how I'm determining whether the run is an automated run vs. a manually executed run.


        The command line of a process contains the executable path and arguments, for example:

         

        C:\TestComplete\Bin\TestComplete.exe
        C:\TestComplete\Bin\TestComplete.exe C:\MyProject.pjs /r /e

         

        BuiltIn.ParamCount ignores the TestComplete/TestExecute exe path and counts everything else -- project path, custom arguments, and so on. So when you launch TestComplete manually, ParamCount is 0.

         

        But in BuiltIn.ParamStr(0), 0 refers to the TestComplete/TestExecute exe path. This value always exists. Other arguments start with index 1. In the 2nd example above, ParamStr(1) is "C:\MyProject.pjs", ParamStr(2) is "/r", and so on.

  • You can check for the process:

     

    if sys.WaitProcess("testcomplete", 0).exists then
    ...