Forum Discussion

vinodkumar_chau's avatar
vinodkumar_chau
Contributor
10 years ago
Solved

Message is getting printed twice in logs of testcomplete

Hi Team ,

Below mentioned code for my project is creating problem. Log.Message(finalPath); is getting printed twice in the logs. First with correct path and second time with \\..\\..\\undefined in the last . Please help me to correct this problem .

 

 

eval(Include("GlobalConstants.js"));
function Include()
{
var projectPath = Project.Path;
var filePath = projectPath + "Script\\" + arguments[0];
var finalPath = filePath.replace(/\\/g, "\\\\");
Log.Message(finalPath);
var fSO = new ActiveXObject("Scripting.FileSystemObject");
var readFile = fSO.OpenTextFile(finalPath, 1);
while(!readFile.AtEndOfStream){
var readLine = readFile.ReadLine();
}
readFile.Close();
return readLine;
} // End Include()

  • To run the Include() routine, the entire file is first processed.  In this phase, you run the eval() command and define the Include() function.  You are probably trying to run this routine by right-clicking in the routine and selecting "Run current routine", or perhaps you defined a Project Test Item to call the Include() routine and then running the project.  What you are doing is effectively this:

     

     

     

    Include("GlobalConstants.js");
    Include();

     

     

    The second call has no arguments.  Attempting to reference them produces the "undefined".

     

    The Include() routine needs the argument defined.  Rewrite as:

     

    function Runme()
    {
      Include("GlobalConstants.js");
    }
    
    function Include(file)
    {
    ...
    }

     

4 Replies

  • To run the Include() routine, the entire file is first processed.  In this phase, you run the eval() command and define the Include() function.  You are probably trying to run this routine by right-clicking in the routine and selecting "Run current routine", or perhaps you defined a Project Test Item to call the Include() routine and then running the project.  What you are doing is effectively this:

     

     

     

    Include("GlobalConstants.js");
    Include();

     

     

    The second call has no arguments.  Attempting to reference them produces the "undefined".

     

    The Include() routine needs the argument defined.  Rewrite as:

     

    function Runme()
    {
      Include("GlobalConstants.js");
    }
    
    function Include(file)
    {
    ...
    }

     

  • Bobik's avatar
    Bobik
    Frequent Contributor

    I guess you are trying run "Include()" without parameters directly from script. Try add empty function at the end of the script and run it.

    • vinodkumar_chau's avatar
      vinodkumar_chau
      Contributor

      This is only code in my script. So where do i put it. ? Please if you could let me know

      • Bobik's avatar
        Bobik
        Frequent Contributor

        Could you attach entire suite? I want understand how do you start your test. Do you start a function or entire project?
        If this is whole your project's code and you start entire project then I guess "Include" function was used as main by default.