Forum Discussion

bdrummond's avatar
bdrummond
Contributor
8 years ago

Do i put the IF...then & Else statement in the wrong location?

hi there, 

i have issue trying to have my If...Then and Else statement to work with my object in my keyword test project. 

Scenario: 

As you can see from the image- i have an If...Then...Else... statement.. there are two scenarios i am applying to my test. 

First, when opening an old database and IF the Database Upgrade object is Visible (true) THEN go on and update the database - this working as expected (ELSE didnt get touched) 

Secondly, i am repeating the same test, but this time with an already upgraded database. because the databaseUpgrade object shouldn't appear I'd expect to have the keyword-test to skip the pre-determined test and go straight into ELSE statement...but this is not the case. 

Do i put the IF...then & Else statement in the wrong location?? 

or am I doing this in the very bad/wrong way? 

your advise is appreciated. 

Regards, 

  • cunderw's avatar
    cunderw
    8 years ago

    You're still checking the Visible property of an object that doesn't exist which is the cause of the error. 

     

    In you if statement change Aliases.IC.databaseUpgrade.Visible to Aliases.IC.databaseUpgrade.Exists it should fix.

     

     

  • cunderw's avatar
    cunderw
    Community Hero

    You're if statements are correct, but you're getting the error because you're checking for a property on an object that doesn't exist. When an object can't be found in test complete you get a stub object with a single property, Exists=false.

     

    You should first check if the object exists, then check if it's visible. You could even set visible = true in your name mapping conditions and the only have to check for exists and not both for your if statement. 

    • bdrummond's avatar
      bdrummond
      Contributor

      hi cunderw.

       

      thanks for your input. not quite sure on how to do with your suggestion, I have tried this (see image) but still to no avail.

       

      sorry - i am quite new to keyword testing.

       

      regards,

       

      • cunderw's avatar
        cunderw
        Community Hero

        You're still checking the Visible property of an object that doesn't exist which is the cause of the error. 

         

        In you if statement change Aliases.IC.databaseUpgrade.Visible to Aliases.IC.databaseUpgrade.Exists it should fix.