Forum Discussion

TestQA1's avatar
TestQA1
Frequent Contributor
4 years ago
Solved

Updating Log.ErrCount value

Hi folks,

 

I have a requirement to fail the gherkin scenario in the Then statement, if the scenario has any Log.Error posted to the test log. I tried using Log.ErrCount, but the problem is that it counts errors from the all scenarios in the feature. While, I am looking for a way to count errors just within each individual scenario. If I can somehow update the value of Log.ErrCount to 0 after each scenario run, it will fulfil the requirement as every scenario will then start Log.ErrCount from the scratch, by not considering the past scenarios errors count.

 

Any help please!

 

function ErrCount()
{
var ErrCount = Log.ErrCount;

if ( ErrCount > 0 ){
Log.Message("There is(are) " + ErrCount + " error(s) in the scenario.")
Log.Error("Scenario failed with some errors.");
}
else
Log.Checkpoint("Scenario passed without any errors.");
}

 

Thanks in advance,

2 Replies

  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3

    Unfortunately it's a read only value.

    https://support.smartbear.com/testcomplete/docs/reference/project-objects/test-log/log/errcount.html

     

    You can calculate it though with something like this

    at the top of all your tests 

    set currenterrors = 0

     

    in your if

     

    if log.errcount - currenterrors > 0  then  /* you now have more errors than before 

      error stuff goes here

      set currenterrors = log.errcount

    else 

      passed stuff goes here

     

     

     

     

     

    • TestQA1's avatar
      TestQA1
      Frequent Contributor

      Thanks Marsha. I will try this. I was also thinking to use closure, but this looks more simple.