Forum Discussion

MarcusBe's avatar
MarcusBe
Occasional Contributor
3 days ago

If ... Then issue

Hello !

Backstory:
         Trying to get it to click on a button IF it is set to "off" so use the "onscreen object" and choose the property of the button "ClrFullClassName" which has property "off" and then equals the same. 

Which works fine when the button is actually Off, it will turn on correctly. But if it is already On, it cant find the property and it will fail the test, i just want it to continue if it is already set to ON in the first place.

Shouldnt it be If ... Then, and then else in the end as shown in the image?

 

 

5 Replies

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

    You state "Ive also tried changing the place of Else, in case anyone wonders" but this does not provide accurate code representation. From the picture your else and the block are not positioned correctly.

    The else needs to move to the left and the block needs to move to right under it as described in  https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/else.html 

    It will only work if the object you are checking exist in both conditions and only its value changes, example: "ClrFullClassName"="off" or "ClrFullClassName"="on". To validate use Spy and compare when it's set to on or off.

    Also you might want to reduce such operation timeout to 1 second as when it is not equal to off it will wait using the default 10 seconds before it proceeds https://support.smartbear.com/testcomplete/docs/keyword-testing/basic/custom-timeouts.html#Dialog 

    πŸ‘ Found it helpful? Click Like
    βœ… Issue resolved? Click Mark as Solution

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

      In your case as you want it to continue if it is already set to ON, you only need to if..then you do not need to else. I assume you are looking at the wrong property that do not exist when state changes. In that case you can check for if exist.

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

    It's not clear from your screenshot, but what property value(s) have you used, in your name mapping for your button? And within your if statement, what property value are you checking?

    Should this block of code be within the Else statement?

     

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

    Good morning MarcusBe,  🌀️ (It's 07:44 is the midwestern U.S.)

    It sounds like you need to use a 'propertycheckpoint' and base your If/Then off of the result.  This should work provided the object identification isn't based on this property as well.

    Property Checkpoints
    https://support.smartbear.com/testcomplete/docs/testing-with/checkpoints/property/index.html

    ... If you find my posts helpful drop me a like! πŸ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

  • MarcusBe's avatar
    MarcusBe
    Occasional Contributor

    Ive also tried changing the place of Else, incase anyone wonders :)