Forum Discussion

stackpointerex's avatar
stackpointerex
Occasional Contributor
10 years ago

Ignore error logs

I have a script where if an object exists it checks for something, if not it checks for something in another object. But in my test log, when the first object existing checking fails it sends an error, and for my testing it is not an error.



Is there a way that if Exists fails don't send me an error?



It is something like



var page;

if(something.Exists){

    page=something;

  }else{

    page=somethingelse;

  }

checksomething(page);

5 Replies

  • You could try turning the logging off at the top using Log.enabled = false.

    Then at the bottom turn the logging back on using Log.enabled = true.

    If you have an error that you want to log, while the logging is not enabled then use Log.Message.
  • NisHera's avatar
    NisHera
    Valued Contributor
    Hi,

    when you use ...something.exist..., TC would search something object to access it's exists methoed. since in first case "something" is not there, test will give error.



    try using something.WaitProperty("Exists",true,600)
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Pablo,



    Exists should be used only in combination with the WaitNNN methods. For example:



    // If using aliases:

    if (Aliases.WaitAliasChild("notepad").Exists) ...



    // If not using aliases:

    if (Sys.WaitProcess("notepad").Exists) ...



    If an object does not exist (in other words, null), it doesn't have any properties - so the direct check will raise an error in this case. But the wait method will return a wrapper with a correct value for Exists. More info here: Checking Whether an Object Exists From Scripts.

  • You can do this...


     


    function main(){


      Log.Enabled = false; 


      Log.Error("Error");


      Log.Enabled = true; 


    }


     


     


    or test first if 'something' is null.

  • stackpointerex's avatar
    stackpointerex
    Occasional Contributor
    Thanks for the answers. I ended disabling and enabling Log anytime I needed.