Forum Discussion

whuang's avatar
whuang
Regular Contributor
5 years ago

how can export single test log file by using Log.SaveResultsAs?

Hi everyone,

Currently I am using Log.SaveResultsAs(FileName, lsMHT, True, lesCurrentTestItem) in each test to export test log file, what Iwant is to export the log file when the test is completed, but when the test is one of a test set/project, it exports the whole project log even through I used "lesCurrentTestItem" for LogScope, but I don't want other test logs mix together. I also tried using value "2" for LogScope, but didn't work either. Does anyone know how I can export log file for the current running test?

 

Thanks in advance!

5 Replies

  • LinoTadros's avatar
    LinoTadros
    Community Hero

    Yeah it is confusing.

    The way the scope works is to report on ALL results UNTIL the current testitem NOT just the test Item

    So....

    function foo()
    {
      Log.Message("Hello");
      
    }
    
    function boo()
    {
      Log.Message("Boo");
      Log.SaveResultsAs("d:\\lino.mht", 2, true, 2);
      
    }
    
    function SaveMyFile()
    {
      Log.Message("Saving");
    }

    if you run these in the project in that order, only Hello () and Boo() will be reported to the mht file.

    If you move Boo() up to be the first funtion to run, than only Boo() will be reported to the MHT

     

    Hope that helps

    Cheers

    -Lino

    • whuang's avatar
      whuang
      Regular Contributor

      Thanks LinoTadros , I see how it works now. Is there anyway I can only export the log for the current running test item? Say I have a test set that has 5 tests, and TC executes the tests one by one from top to bottom, when it finish executing the first test, then export the log file for the first test only, when it finish executing the second test, then export the log file for the second test only, I don't need the log for the first test again, I already have it.

       

      Test Project:

              Test 1  --> Export log for test 1

              Test 2  --> Export log for test 2

              Test 3  --> Export log for test 3

              Test 4  --> Export log for test 4

              Test 5  --> Export log for test 5

      • LinoTadros's avatar
        LinoTadros
        Community Hero

        Unfortunately, there is no way using the current mehanism in TestComplete as of 14.1

        The way I usually do it is to implement the OnLogError event and I can specifically log whatever  I want to any file I want. I don't use the TestComplete Log file as it always runs at the END of the test.  So even if your total test takes 6 hours to run, the MHT file does not get created or touched until the end (6 hours later) even if you use the SaveResultAs(...).  So implementing the event is best as it happens immediately

         

        Hope that helps

        -Lino