Forum Discussion

Kate's avatar
Kate
Contributor
9 years ago

Disable automatic posting to log - default TC errors

I need to disable TestComplete errors logging or make it 'smarter'.

 

Case 1.

In some cases I need to perform different steps that depends on whether an object exists or not.

Let's say, the flow is:

1. Click button1

2. If button2.Exists:

        button2.click()

    else:
        pass

3. Click button3

 

I expect that for some users button2 should not exist. For some users it should. And that is fine. But I get an error to my log if the button does not exist.

 

Case 2.

WaitNNN methods did not work for me so I implemented a while loop that checks if a view is shown. 

wait_time = 2
 while Sys.Process("app").Find('AutomationId', '123', 100, True).Visible:
    if wait_time > 6:
      Log.Error('123 screen is displayed for too long')
      break
    else:
      wait(wait_time)
      wait_time += 2

On the final check, when my screen has gone, I get an error to the log that expected screen not found. But that is fine! I am waiting for the screen to go.

 

So the question is - is it possible to disable TestComplete posting errors the the log. They do not provide me with expected information, but make all my test results RED due to these intermediate 'errors' while the tests pass.

I want only my custom errors and messaged to get to the log.

7 Replies

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

    I'm going to suggest that you don't take the errors out.  You may miss other failures by doing that.

     

    In your case 1, if Button 2 doesn't exist but it was supposed to be there for that user, you wouldn't get notified.

     

    For case 1, I would use If Object Exists and possibly Last Operation Result to find the button.  

    https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

    https://support.smartbear.com/testcomplete/docs/keyword-testing/basic/result.html

     

    I would also wonder what happens if you execute these steps one at a time.  If this works, perhaps you're actually having a timing issue in the test that's causing the failure.

     

     

     

    In your case 2, it looks like you are combining waiting for the window in order to test it and waiting for the window to go away.  Here I suggest that you use the wait to do just the current test.   So, wait for Window1 to appear then do the test.  Next, if you want to actually check that Window1 is gone, do another wait for that.  Otherwise, go on to waiting for Window2 to appear and do its tests.

     

    Hope that helps.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      The best way to do what you are looking for is, as Marsha_R, not to avoid getting errors logged, but to do a better job of detecting object existance.  That's what the WaitNNN methods are for.  And, if those methods aren't working, then Find, FindChild, FindAllChildren, etc., are a close second. 

       

      So, on your first example, what are you doing to check for existance of button2?  Are you using a WaitNNN or a Find call?  Could you post the code your using? For that matter, you say WaitNNN isn't working for you... could you post what you tried when you used that? Perhaps you're missing something obvious.

       

      On your second example, instead of waiting for "Visible", wait for "Exists". The "Find" function returns an empty stub which has VERY little in the way of properties.  One it DOES have is "Exists" and it's set to False.  From the help:

      If no object matching the search criteria was found, the Find method returns a stub object that only contains the Exists property equal to False. So, you can check the Exists property value of the returned object to determine whether the search was successful.


      Visible would work if the removal of the screen is simply a matter of removing visibility.  But if the object actually "disappears" from the object browser, Exists is a better check.  So, change that second code to

       

      wait_time = 2
       while Sys.Process("app").Find('AutomationId', '123', 100, True).Exists:
          if wait_time > 6:
            Log.Error('123 screen is displayed for too long')
            break
          else:
            wait(wait_time)
            wait_time += 2

       

      Now, concerning WaitNNN not working... if you are using WaitNNN and checking "Visible", that could be your problem as well.  Like the Find function, if the WaitNNN method times out, what is returned is an empty stub with "Exists" set to False. 

    • Kate's avatar
      Kate
      Contributor

      Marsha_R wrote:

      I'm going to suggest that you don't take the errors out.  You may miss other failures by doing that.

       

      In your case 1, if Button 2 doesn't exist but it was supposed to be there for that user, you wouldn't get notified.

       

      For case 1, I would use If Object Exists and possibly Last Operation Result to find the button.  

      https://support.smartbear.com/testcomplete/docs/app-objects/common-tasks/checking-existence.html

      https://support.smartbear.com/testcomplete/docs/keyword-testing/basic/result.html

       

      I would also wonder what happens if you execute these steps one at a time.  If this works, perhaps you're actually having a timing issue in the test that's causing the failure.

       

       

       

      In your case 2, it looks like you are combining waiting for the window in order to test it and waiting for the window to go away.  Here I suggest that you use the wait to do just the current test.   So, wait for Window1 to appear then do the test.  Next, if you want to actually check that Window1 is gone, do another wait for that.  Otherwise, go on to waiting for Window2 to appear and do its tests.

       

      Hope that helps.


      Thank you for your reply.

      In my situations it is not as straightforward as you described. I will add some clarification. 

       

      As per case 1.

      That case is not about the button2 - it is about applicatoion flow.

      All buttons are verified in specific tests.

      This case is about verification of the screen after clicking button 3. No matter how I get there, but I need to be there.

      That particular issue is about signing out. I start all my tests with running the app and signing out to make sure user is not signed in - just in case when signing out from previous test failed (I called the function sign_out_if_needed). I have 2 groups of users - 1 of them will see and click button2, another will not. I don't want to check the button2. My function is expected to handle ALL users to sign out. So I do not want to be notified about button2. It's all about the screen after button3.

       

      As per case 2.

      That is the event that happens before each test. I run the app and I see the 'loading' screen. After that there are several different flows - different screens may appear. So before my test starts I cannot and I do not want to wait for a particular second screen (my event should fit any test). I want this loading screen to go (sometimes it takes 2 seconds, sometimes more than 10....)

       

      I will try If Object Exists

       

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Kate wrote:
        Thank you for your reply.

        In my situations it is not as straightforward as you described. I will add some clarification. 

         

        As per case 1.

        That case is not about the button2 - it is about applicatoion flow.

        All buttons are verified in specific tests.

        This case is about verification of the screen after clicking button 3. No matter how I get there, but I need to be there.

        That particular issue is about signing out. I start all my tests with running the app and signing out to make sure user is not signed in - just in case when signing out from previous test failed (I called the function sign_out_if_needed). I have 2 groups of users - 1 of them will see and click button2, another will not. I don't want to check the button2. My function is expected to handle ALL users to sign out. So I do not want to be notified about button2. It's all about the screen after button3.

         

        As per case 2.

        That is the event that happens before each test. I run the app and I see the 'loading' screen. After that there are several different flows - different screens may appear. So before my test starts I cannot and I do not want to wait for a particular second screen (my event should fit any test). I want this loading screen to go (sometimes it takes 2 seconds, sometimes more than 10....)

         

        I will try If Object Exists

         

         


        On case 1 - If you are using the "Exists" check and you're still getting an error, that's where a "Wait" method or a "Find" method would best come into play... some pseudo-JavaScript for you:

         

        //Using Aliases and WaitAliasChild
        Aliases.myApp.myForm.button1.Click();
        if (Aliases.myApp.myForm.WaitAliasChild('button2', 5000).Exists) {
            Aliases.myApp.myForm.button2.Click();
        }
        Aliases.myApp.myForm.button3.Click();
        
        //No namemapping/Aliases, the code isn't much different for Waitchild
        //Using VCLObject as an example, you're might be different
        var myApp = Sys.Process('myApp');
        var myForm = myApp.VCLObject('myForm');
        myForm.VCLObject('button1').Click();
        if (myForm.WaitChild('button2', 5000).Exists) {
            myForm.VCLObject('button2').Click();
        }
        myForm.button3.Click();
        
        //If you want to use FindChild, demonstrating with Aliases but works the same for non NameMapping
        Aliases.myApp.myForm.button1.Click();
        if (Aliases.myApp.myForm.FindChild(['ObjectType','Name'], ['Button', 'button2'], 2, true).Exists) {
            Aliases.myApp.myForm.button2.Click();
        }
        Aliases.myApp.myForm.button3.Click();
        

        As for your second case... let us know how using "Exists" works for you.

  • m_essaid's avatar
    m_essaid
    Valued Contributor

    Hi Kate,

     

    I like to use aliases. I check for a certain time a certain amount of passes if the alias exists.

    Note that you could use the property you want, or use several, or put loops into loops to use them in cascade.

     

    check this :

     

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      m_essaid wrote:

      Hi Kate,

       

      I like to use aliases. I check for a certain time a certain amount of passes if the alias exists.

      Note that you could use the property you want, or use several, or put loops into loops to use them in cascade.

       

      check this :

       


      Neat little function... however, you are basically reproducing the WaitAliasChild method. :)  Might get better performance using the native method.

      • m_essaid's avatar
        m_essaid
        Valued Contributor

        tristaanogre yes it seems to be similar to the WaitAlias function but this one could be adapted to any property... (I use it for the enabled, disabled, visible, not visible, exists, etc etc)