Forum Discussion

sd's avatar
sd
Occasional Contributor
7 years ago

If..then and else statements

Hello,

 

 I am trying to automate using keyword driven test and when I select if..then and else statement, when the condition is not true it does not go to else loop. It still falls under if...then loop and fails the test. I am trying to test web application where one window only appears onto certain condition. I wan to use if..then loop when that window exist and I want my test to go to else loop when that window does not exist. I have made sure that the if..then and else is on the same level of hierarchy.. Any suggestions would be appreciated?

8 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    It's entirely possible that the object exists... but is not visible.  This happens in a web app that I'm working with.  so, you might want to add a Visible check to see if that helps.

  • sd's avatar
    sd
    Occasional Contributor

    Hi Martin,

     

    Thanks for the quick reply. My problem is even the object is not on screen my test always goes into if..then loop and fails the test. It does not recognize that the object on screen does not exist and does not execute statements from the else loop. I also try to use visible method but it still shows the same error.

     

     

    • cunderw's avatar
      cunderw
      Community Hero

      Like tristaanogre mentioned it might not be visible on screen, but still exists in the DOM so checking both is good practice. 

       

      Something I did notice in your screnshot though is that your else clause doesn't have any children, the steps right after you else statement aren't actually in the else statement. You will want to have those be a child of it, not on the same level. 

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Question... why do you have an "if...then" and then an "if...object"?  Whats' the condition in the first if..then?  We can't see that in your screenshot.... it could be that the initial condition in that if...then is not as you think it is.  Please give us a view of what's in there.

  • sd's avatar
    sd
    Occasional Contributor

    Oh. I think I just wanted to double check for that additional screen during the test so I used if ..then statement and then I also used if object as well. Those both are for the same screen. Today I removed if object statement and it still worked the way I wanted.

     

    Do you know how I can add visible check in my test? Any suggestions please.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Actually, I would have kept the if-object and removed the if-then... and then change the if-object to check for Visible.

  • sd's avatar
    sd
    Occasional Contributor

    Thanks for your suggestion and I tried that out but it still does not work for me.  I removed if--then and else and just added if object statement with visible option and added child operation. But when I try to run when the object is not on screen, it still falls under if..object loop and look for that additional screen. Any other suggestions?

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Then what's happening is that TestComplete is apparently seeing the object as Visible.  This is also possible.   An object can Exist AND be Visible without necessarily being actually discernable by a human... if the code written for the object does so.  For example, I've seen modal forms in web applications that, in TestComplete's object browser, show up with Visible = true... but I still can't see it... the reason being is that the developer, being a bit lazy, rather than setting the "Visible" attribute of the item, actual just sets it's height and width to 0... it's still there, just has no size.

       

      Please take the time to investigate the object you are trying to detect... use TestComplete's Object Browser to look at your application under test when the application is in that particular state and see what properties are on the object you are attempting to detect.  Using those properties and values, build your if logic to detect a condition which has the object on screen and usable.   Beyond that, I can't help with any more specifics because I don't have your application in front of me to do this investigation.  You can post screenshots of the properties of the object here in which case we will attempt to help you, but essentially, that's what we'll be doing... trying to determine what the state of the object is so we can determine whether or not you can interact with it.