Forum Discussion

Fredrik's avatar
Fredrik
Occasional Contributor
8 years ago
Solved

Several log paths when exporting logs from test execute command line.

Hi,

When executing tests from test execute I can see that there is an parameter to export the logs to a given location in the mht file format. However, is it possible to define two paths? I'm interested in separating the failed and passed test cases with two folders.  

 

Br

Fredrik 

  • The Log.SaveResultsAs method, which you are referencing, doesn't distinguish between passed and failed within the method itself.  You'll need to do a bit more work.

    Just thinking over what you want, basically, you want an export of the log for a particular test case (say a project test item) and, depending upon whether or not it is passed or failed, redirect that export to a different folder.

    At the start, you would need to put some or event handler in your "OnStopTest" event to check the test case and see if it is passed or failed.  There are various ways this can be done, not limited to having a project variable that would store the status of the last test case and going all the way up to event handlers on the OnLogError or OnLogWarning events to update that variable or some such thing.  Then, in your OnStopTest handler, based upon how you determine if a case is passed or failed, you could call Log.SaveResultsAs with the LogScope parameter set to lesCurrentTestItem.

    This is assuming that, in your project architecture, a test case = a test item.  If they don't, then you're not going to be able to do that kind of separation as easily.  You may need to resort to writing your own logging functions to write things out to file.

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    The Log.SaveResultsAs method, which you are referencing, doesn't distinguish between passed and failed within the method itself.  You'll need to do a bit more work.

    Just thinking over what you want, basically, you want an export of the log for a particular test case (say a project test item) and, depending upon whether or not it is passed or failed, redirect that export to a different folder.

    At the start, you would need to put some or event handler in your "OnStopTest" event to check the test case and see if it is passed or failed.  There are various ways this can be done, not limited to having a project variable that would store the status of the last test case and going all the way up to event handlers on the OnLogError or OnLogWarning events to update that variable or some such thing.  Then, in your OnStopTest handler, based upon how you determine if a case is passed or failed, you could call Log.SaveResultsAs with the LogScope parameter set to lesCurrentTestItem.

    This is assuming that, in your project architecture, a test case = a test item.  If they don't, then you're not going to be able to do that kind of separation as easily.  You may need to resort to writing your own logging functions to write things out to file.

    • Fredrik's avatar
      Fredrik
      Occasional Contributor

      Hi, thanks for the reply! 

       

      To give some more info. 

       

      If the test case is executed the log is saved with the save as method as been mentioned in the comments. The problem is that sometimes the test is timed out due to the parameter timeout. If this occurs there is no logs to fetch due to that the save as has not been executed. Therefore I was wondering if there was a way to separate the export path directly from the command line. 

       

      Br

      Fredrik 

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        That's where using the "OnStopTest" event handler comes to play... no matter what the case for the TestItem being stopped, when the test stops, that event handler fires. If you put your export into the event handler, you will ALWAYS get the export out.

  • bbi's avatar
    bbi
    Contributor

     

     

    Use the Log.SaveResultsAs method in a tear down method for your test suite:

     

    var outPath = ResultIsOK ? 'passed' : 'failed';
    Log.SaveResultsAs(qa.variables.getLogFilePath() + "\\" + outPath + \\" + qa.variables.getTestSuiteName() + ".mht", lsMHT)

    (qa.variables.getLogFilePath and qa.variables.getTesteSuiteName must be replaced by your own variables)

     

     

     

    But imho would be better to use a test management sofware (a good free one is Testlink).