Forum Discussion

gus's avatar
gus
Contributor
10 years ago

Message posted to wrong log folder

Hi,

 

I'm completely clueless what this strange behavior is posted by: I append a log folder to the one on the top of the folder stack, but TC only posts entries to this appended folder only when explicitly specifying its ID, otherwise it posts to the top level.

 

Here's the code producing the issue:

 

 

function ReadGlobalConfig() {
  DumpCommandLineParams();
  
  var logId;
  
  Log.PushLogFolder(GetInfrastructuralLogID());
  logId = Log.AppendFolder("Reading project suite configuration settings");
  
  // Method 1
  ProjectSuite.Variables.BaseTestDataPath = GetSetting("Environment", "BaseTestDataPath", ProjectSuite.Variables.BaseTestDataPath);
  Log.Message("Base path for master copies of test data: " + ProjectSuite.Variables.BaseTestDataPath, null, pmLowest);

  // Method 2  
  ProjectSuite.Variables.BaseTempPath = GetSetting("Environment", "BaseTempPath", ProjectSuite.Variables.BaseTempPath);
  Log.Message("Temporary folder base path: " + ProjectSuite.Variables.BaseTempPath, "", pmLowest, null, null, logId);
  
  // Method 1
  ProjectSuite.Variables.BaseResultsPath = GetSetting("Environment", "BaseResultsPath", ProjectSuite.Variables.BaseResultsPath);
  Log.Message("Base path of results: " + ProjectSuite.Variables.BaseResultsPath, null, pmLowest);
  
  Log.PopLogFolder();  
  Log.PopLogFolder(); // Infra log
}

 

I maintain two top-level log folders, one for events occured during the core steps of the tests, and an infrastructural log for log entries which are likely coupled with test configuration or errors. I also use this infrastructural log folder to document command-line parameters and configuration settings.

 

The method in the sample above:

  1. Pushes the infrastructural log to the top of the folder stack. The method GetInfrastructuralLogID() returns the ID of the infrastructural log golder.
  2. Appends a folder for the subsequent messages.
  3. Logs messages using two different methods, for testing.
  4. Pops the folder appended in step 2.
  5. Pops the folder pushed to top in step 1.

Now the weird result is that the entry posted using Method 2 appears in the correct subfolder appended. But if I do not specify the log folder ID, the entries are posted to the topmost level folder of the entire test run (that is, out of the complete infra log folder), as trying to show here:

 

+ Test Log
    - Entry
    + Subfolder
	- Enntry
+ Infrastructural log
    - Entry
    + Reading project suite configuration settings
	- The second entry posted using method 2
- The first entry posted using method 1
- The third entry posted using method 1

 

 

I've never faced such strange situation, but I miss something trivial. Do you have any idea?

 

  • A simple test shows that calling Log.PushFolder() on the same folder twice does actually push that folder twice onto the stack.  Popping it off twice is appropriate.  (attached the foldertest that I used)

     

    I can reproduce your problem only if I push an invalid folder ID:

     

    function ReadGlobalConfig()
    {
      var GetInfrastructuralLogID = Log.CreateFolder("GetInfrastructuralLog", null, pmLowest);
      Log.PushLogFolder(GetInfrastructuralLogID);
      
      var logId = Log.AppendFolder("Reading project suite configuration settings");
    var invalidID = 5;
    Log.PushLogFolder(invalidID);
      
      Log.Message("Method 1", null, pmLowest);
      Log.Message("Method 2", "", pmLowest, null, null, logId);
      Log.Message("Method 1", null, pmLowest);
      
      Log.PopLogFolder();
      Log.PopLogFolder(); // Infra log
    }

     

    Other than that, I've got nothing.

  • I can't reproduce it.  Post a self-contained example and an image of the resulting log file.  Which version of TestComplete are you using?

    • gus's avatar
      gus
      Contributor

      Hi Joseph,

       

      I'm afraid I cannot post a self-contained example, since my test project consists of thousands of Jscript code across many scripts, which, apart from being confidential, are too complex to get familiar with just for the sake of this issue.

       

      However, I have a guess, and please confirm if this can cause a problem.

       

      Say you have the following log folders (using folder IDs for identification):

       

      - 0
        - 2
          - 6
        - 3
      - 1
        - 4
        - 5

       

      Assume folder 2 is on the top of the stack, so the stack is like this: 0, 2.

       

      QUESTION: What happens if I push folder 2 to the top? Will the stack be 0, 2, 2, or will it remain 0,2?

       

      If it remains 0, 2, than the issue may be caused by the fact that I push the infrstructural log folder to the top of the stack, and I also pop it from the stack at the end of my routine, but if the folder was alread at the top of the stack, I finally remove more items from the stack:

      1. Two push ops at the beginning add only one folder to the stack if the first was already on the top
      2. The two pop ops remove two folders regardless of how many was added.

      Please confirm which is the way TC works. I came to this potential answer by realizing that another test using this same shared portion of code did not produce the same problem, and I also realized the difference between the tests was that the folder pushed in the Log.PushLogFolder(GetInfrastructuralLogID()); was already the top folder in one and was not in the other.

      • A simple test shows that calling Log.PushFolder() on the same folder twice does actually push that folder twice onto the stack.  Popping it off twice is appropriate.  (attached the foldertest that I used)

         

        I can reproduce your problem only if I push an invalid folder ID:

         

        function ReadGlobalConfig()
        {
          var GetInfrastructuralLogID = Log.CreateFolder("GetInfrastructuralLog", null, pmLowest);
          Log.PushLogFolder(GetInfrastructuralLogID);
          
          var logId = Log.AppendFolder("Reading project suite configuration settings");
        var invalidID = 5;
        Log.PushLogFolder(invalidID);
          
          Log.Message("Method 1", null, pmLowest);
          Log.Message("Method 2", "", pmLowest, null, null, logId);
          Log.Message("Method 1", null, pmLowest);
          
          Log.PopLogFolder();
          Log.PopLogFolder(); // Infra log
        }

         

        Other than that, I've got nothing.