Forum Discussion
- HKosovaSmartBear 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"
- jmcpeekContributor
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!
- HKosovaSmartBear 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.
- jmcpeekContributor
You can check for the process:
if sys.WaitProcess("testcomplete", 0).exists then ...
Related Content
- 12 years ago
- 3 years ago
- 12 years ago
- 7 years ago
Recent Discussions
- 2 days ago