Ask a Question

How to automatically copy and rename the MHT log generated by TestExecute?

pvidal
Contributor

How to automatically copy and rename the MHT log generated by TestExecute?

Hello,



When TestExecute finished running a test it shows the MHT log in Internet Explorer. This MHT log is somewhere in some temp directory and has a generic name like tcResult#.mht. We need to archive that file.



Is there a way to get a copy and rename that file besides going to that temp folder in Windows Explorer and manually copying and renaming it?  Can I do it from a script or event handler so that it is automatically done after running the test cases?



Thank you,

Patricio.


5 REPLIES 5
weiwongfaye
Occasional Contributor

RE: How to automatically copy and rename the MHT log generated by TestExecute?

Hello Patricio,



Hope this can help you



Sub Main()



Dim objShell,strLog


Set objShell = CreateObject("WScript.Shell")

strLog=objShell.ExpandEnvironmentStrings("%temp%")

Call aqFileSystem.CopyFile(strLog&"\tcResult1.mht", "C:\AfterChange.mht")



End Sub


 

pvidal
Contributor

RE: How to automatically copy and rename the MHT log generated by TestExecute?

Thank you Jack. The problem I see is that the file name changes every time. Also I would like to run this script automatically after the tests are executed.



Regards,

Patricio.

RE: How to automatically copy and rename the MHT log generated by TestExecute?

Hi Patricio,


I suggest that you use a *.js file that would launch your "main" project suite and copy the generated file.


    //test.js

    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // The line below will remove all of the .mht files, so, after running the test.js file, you will always get the tcResults1.mht file.

    fso.DeleteFile("C:\\Users\\UserName\\AppData\\Local\\Temp\\tcResults*") // specify your temp folder here

    var te = new ActiveXObject("TestExecute.TestExecuteApplication");

    var IObject = te.Integration;

    IObject.OpenProjectSuite("C:\\ProjectSuite14\\ProjectSuite14.pjs");  // here should be the path to your "main" project suite file

    IObject.RunProjectSuite();

    while(IObject.isRunning())

    {

        WScript.Sleep(100);

    }

    IObject.CloseProjectSuite();

    WScript.Sleep(1000);

    fso.CopyFile ("C:\\Users\\UserName\\AppData\\Local\\Temp\\tcResults1.mht", "c:\\results.mht"); // as the first parameter, specify your temp folder here


Run TestExecute and execute this file. The .mht file you need will be located in the "C:\" folder.


Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Madhi
Contributor

RE: How to automatically copy and rename the MHT log generated by TestExecute?

I use the function log.saveresultsas(path,2) to store the result as mht

In the path you can give a desired filename to store as well.
ChrisH
Occasional Contributor

RE: How to automatically copy and rename the MHT log generated by TestExecute?

I use the same method which Madhi has suggested:





JScript:



function GeneralEvents_OnStopTest(Sender)

{

  var logFolder = "C:\\Logs\\";

  var mhtName = "log.mht";

 

  if (!aqFileSystem.Exists(logFolder))

  {

    aqFileSystem.CreateFolder(logFolder);

  }

 

  var currentdateTime = aqDateTime.Now();

 

  var dateTimeFolder = aqDateTime.GetYear(currentdateTime) + "_"

    + aqDateTime.GetMonth(currentdateTime) + "_"

    + aqDateTime.GetDay(currentdateTime) + "_"

    + aqDateTime.GetHours(currentdateTime) + "_"

    + aqDateTime.GetMinutes(currentdateTime) + "_"

    + aqDateTime.GetSeconds(currentdateTime);

 

  Log.SaveResultsAs(logFolder + dateTimeFolder + "\\" + mhtName, lsMHT);

}





(On a different note, how do you post code in a sensible block when you reply?)
cancel
Showing results for 
Search instead for 
Did you mean: