Forum Discussion

ashly's avatar
ashly
Champion Level 1
11 days ago

Adding testcase description to test log

In testcomplete, is there an option to create test case descriptions in a way it can be added to the test execution report? 

I am looking for solutions for adding the test case description to the test log details.

Please let me know if you have any idea how to do that.

  • scot1967's avatar
    scot1967
    Frequent Contributor

    I use the test name as my main description but I also wrap tests within Log.AppendFolder("My Description") and Log.PopLogFolder().  I am not sure why the 'Description' field in the Execution Plan does not provide this feature.  SmartBear?

    https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log/methods.html

    I have also used script to change the fonts for the messages using the  LogAttributes Object.

    https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log-attributes/index.html

    Here is some code for various attribute changes you can make.  

    /*#################### Class Attributes ################
      Class Name: Attributes
      Description: Contains methods to format Log messages.
      Arguments: None
      Methods Return: attr object
    #########################################################*/
    
    class Attributes
    {
    
      /*#################### Method CorrectRGBComponent ################
        Method Name: CorrectRGBComponent
        Description: Accepts a component value converts it to an integer and ensures it is >= 0 and <= 255
        Arguments: a single component value
        Methods Return: integer representing an RGB color component between 0-255.
      #########################################################*/  
      
      static correctRGBComponent(component)
      {
        try
        { 
          component = aqConvert.VarToInt(component);
          if (component < 0)
            component = 0;
          else
            if (component > 255)
              component = 255;
          return component;
        }
         catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      } 
    
      /*###################### Method rgb #####################
        Method Name: rgb
        Description: Accepts rgb values and returns color 
        Arguments: r, g, b component values
        Methods Return: color value
      #########################################################*/  
    
      static rgb(r, g, b)
      {
        try
        { 
          r = this.correctRGBComponent(r);
          g = this.correctRGBComponent(g);
          b = this.correctRGBComponent(b);
          return r | (g << 8) | (b << 16);
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      } 
      
      /*################# Method TestCaseFolder ###############
        Method Name: TestCaseFolder
        Description: Returns attributes used for a Test Case Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/  
      
      static caseFolder()
      {
        try
        {   
          let attr = Log.CreateNewAttributes();
          attr.FontColor = this.rgb(1,1,1);
          attr.BackColor = this.rgb(199, 207, 219);
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }
     
      /*################# Method StepFolder ###############
        Method Name: StepFolder
        Description: Returns attributes used for a Step Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static stepFolder()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.FontColor = this.rgb(1,1,1);
          attr.BackColor = this.rgb(230, 231, 237);
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }   
    
      /*################# Method LogFolder ###############
        Method Name: LogFolder
        Description: Returns attributes used for a Log Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static logFolder()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.FontColor = this.rgb(1,1,1);
          attr.BackColor = this.rgb(230, 231, 237);
          attr.Bold = false;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }   
    
      /*################# Method GreenComment ###############
        Method Name: LogFolder
        Description: Returns attributes used for a Log Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static greenComment()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.BackColor = clGreen;
          attr.FontColor = this.rgb(1,1,1);  //clBlack and rgb(0,0,0) changes to white with Dark mode...
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }     
      
      /*################# Method yellowComment ###############
        Method Name: LogFolder
        Description: Returns attributes used for a Log Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static yellowComment()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.BackColor = clYellow;
          attr.FontColor = this.rgb(1,1,1); //clBlack and rgb(0,0,0) changes to white with Dark mode... 
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }
       
      /*################# Method redComment ###############
        Method Name: redComment
        Description: Returns attributes used for a Log Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static redComment()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.BackColor = clRed;
          attr.FontColor = this.rgb(1,1,1); //clBlack and rgb(0,0,0) changes to white with Dark mode... 
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }
      
      /*################# Method boldFont ###############
        Method Name: boldFont
        Description: Returns attributes used for a Log Folder
        Arguments: None
        Methods Return: attributre object
      #########################################################*/    
      
      static boldFont()
      {
        try
        { 
          let attr = Log.CreateNewAttributes();
          attr.Bold = true;
          return attr;
        }
        catch(err)
        {
          Log.Error("Exception:  "+err.message);
        }
      }
    }
    
    module.exports.Attributes = Attributes;

     

    • scot1967's avatar
      scot1967
      Frequent Contributor

      Example Attribute_File use...

      let WWPointOfSale_File = require("WWPointOfSale_File"); 
      let Attributes_File = require("Attributes_File");
      let WWString = require("WWString");
      
      // Script Fragment
      
      function TC7590_VerifyRefNumberAndPaymentType()
      {
        try 
        {
          let attr = new Attributes_File.attributes_File();       
          Log.AppendFolder("TC7590_VerifyRefNumberAndPaymentType")      
            let btnCancel = undefined;      
            Log.AppendFolder("1. Login to Point Of Sale application.","",pmNormal,attr.stepFolder()); 
              let Application = new WWPointOfSale_File.WWPointOfSale_App(); 
              Application.Open_App();
              let frmMain = Application.frmMain();
              frmSale = Application.frmSale();
              frmSaleCurrentObject = frmSale.CurrentObject;
              if(typeof frmSaleCurrentObject == "object"){
                if (frmSaleCurrentObject.Exists == true){
                  btnCancel = frmSale.btnCancel().CurrentObject;
                  btnCancel.Click();
                }
              }
            Log.PopLogFolder();    

       

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Frequent Contributor

    To address such need, I personally utilized a combination of actions to reflect and make execution log readable:
    1-Project Name
    2-Introduce test case specific log entry by using "Log Message"
    3-Introduce log foldering by using "Append Log Folder" with "Pop Log Folder", and "Log Attributes"

  • jrsbr's avatar
    jrsbr
    Contributor

    I use a meanigfull test name plus  we have a convention to add a log message at the start and end of all tests and support procs.  It would be nice  if the description was added the calling side as  well in  the comments, or   even if the comments were included in the log.