Forum Discussion

renfeif's avatar
renfeif
New Contributor
12 years ago

Error writing to the TC log file

I don't understand why the txt can't be written into my customization log file which is created during runtime.

//I can monitor the logfilepath variable is correct from debug mode and it should be appended with new input text..



  var logFilePath;

  var logFile;

  logFilePath=CreateTCLLogFolder();

  logFile=CreateTCLLogFile(logFilePath);

  var emailLogName;



function main()

{



  WriteLog(logFile,"Enter A2 Automation testing2");



}



function CreateTCLLogFolder()

{



  var logFolder;

  NowValue = aqDateTime.Now();

  StringTodayValue=aqConvert.DateTimeToFormatStr(aqDateTime.Today(), '%y_%m_%d')

  StringNowValue = aqConvert.DateTimeToStr(NowValue);

  logFolder="C:\\TestCompleteLogs\\"+"TCL_LOG_"+StringTodayValue;

  if (!aqFileSystem.Exists(logFolder))

    aqFileSystem.CreateFolder(logFolder);

  // Writes string to file

  return logFolder;   



}



function CreateTCLLogFile(LogFolder)

{

    currentLogName=aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%H_%M")+".txt";

    ForReading = 1;

    ForWriting = 2;

    ForAppending = 8;

    TristateFalse = 0;

    //s = LogTxt;

    // Creates a new file object

    fs = new ActiveXObject("Scripting.FileSystemObject")

    if (! fs.FileExists(LogFolder+"\\"+currentLogName))

        f = fs.CreateTextFile(LogFolder+"\\"+currentLogName);

    return LogFolder+"\\"+currentLogName;

}



function WriteLog(logFilePath, logTxt)

{

   fs = new ActiveXObject("Scripting.FileSystemObject")

    timeStamp=aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%H_%M_%S")

    if (!aqFile.Exists(logFilePath))

    {

    Log.Message("Log file doesn't exist, creating a new one");   

    aqFile.Create(logFilePath);



    }

    aqFile.WriteToTextFile(logFilePath, timeStamp+"==>"+ logTxt + "\r\n", aqFile.ctANSI, false); // this won't write!! Bizza!!

   aqFile.WriteToTextFile("c:\\TestCompleteLogs\\TCL_LOG_13_12_09\\17_01.txt", timeStamp+"==>"+ logTxt + "\r\n", aqFile.ctANSI, false);//this works!!!



}

2 Replies

  • jorgesimoes1983's avatar
    jorgesimoes1983
    Regular Contributor
    I suggest that you debug "logFilePath" and compare it with the manual path you use.



    And you can try it with your project path just to see how it goes:



      var Path;

      var file; --> place your file name

      Path = Project.Path;  

      Path += file;

  • Hi Guys,


     


    Let me post here the script provided by the TestComplete Support Team:




      //JScript


      var logFilePath;


      var logFile;


      logFilePath=CreateTCLLogFolder();


      logFile=CreateTCLLogFile(logFilePath);


      var emailLogName;


     


    function main()




      WriteLog(logFile,"Enter A2 Automation testing2");


    }


     


    function CreateTCLLogFolder()


    {


     


      var logFolder;


      StringTodayValue=aqConvert.DateTimeToFormatStr(aqDateTime.Today(), '%y_%m_%d')


      logFolder="C:\\TestCompleteLogs\\"+"TCL_LOG_"+StringTodayValue;


      if (!aqFileSystem.Exists(logFolder))


        aqFileSystem.CreateFolder(logFolder);


      return logFolder;   


     


    }


     


    function CreateTCLLogFile(LogFolder)


    {


        currentLogName=aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%H_%M")+".txt";


        if (!aqFile.Exists(LogFolder+"\\"+currentLogName))


        aqFile.Create(LogFolder+"\\"+currentLogName);


        return LogFolder+"\\"+currentLogName;


    }


     


    function WriteLog(logFilePath, logTxt)


    {


        timeStamp=aqConvert.DateTimeToFormatStr(aqDateTime.Now(),"%H_%M_%S")


        if (!aqFile.Exists(logFilePath)) 


        {


        Log.Message("Log file doesn't exist, creating a new one");   


        aqFile.Create(logFilePath);


        }


        aqFile.WriteToTextFile(logFilePath, timeStamp+"==>"+ logTxt + "\r\n", aqFile.ctUTF8, false);


    }