Forum Discussion

d4h8a1's avatar
d4h8a1
New Contributor
14 years ago

Conditional if statements do not seem conditional



Hello folks.  I have had only a few weeks time to play with TestComplete, but I am an experienced C programmer with a little java exposure.  



When I test this program I get one of these three dialog boxes randomly.  Currently I am trying to use this code to click whichever button shows up to make the box go away.  When the script runs it gets to the first if statement, gives and error that no object was found, but still tries to click the button like there was a button visible on the screen.  For the life of me I cannot figure out why.






   while(1) {

      if(BtnConfirmOverWriteYes.VisibleOnScreen()) {

         BtnConfirmOverWriteYes.ClickButton();

         break;

      }

      if(BtnConfirmOverWriteSiteOK.VisibleOnScreen()) {

         BtnConfirmOverWriteSiteOK.ClickButton();

         break;

      }

      if(BtnNumberingDifferencesRetreive.VisibleOnScreen()) {

         BtnNumberingDifferencesRetreive.ClickButton();

         break;

      }

   }



I am writing this script in JavaScript.  I think.  



Thanks for the help,

Eric


4 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The problem is that you're checking for the value of a property on an object that may not exist yet.  So, you should be checking for Exists AND VisibleOnScreen.  Additionally, I'm not sure the context of your code, but it looks like you're calling BtnConfirmOverWriteYes and the other buttons without making a call to say what the button is.  For example, I was expecting to see something like (pseudocode)



    Set MyTestApp = Sys.Process('MyApp');

    Set MyTestForm = MyTestApp.MyForm;

    if MyTestForm.BtnConfirmOverWriteYes;





    Without the reference to the parent component, that may also be contributing to the "object not found".



    There are help topics on how to check for the existence of an object in the TC help but essentially, what you'll do is like this (DelphScript... I don't write Java.. yet)






    procedure Test1;



    var

        MyTestApp;

        MyTestForm;

        TestButton;



    begin

          MyTestApp := Sys.Process('MyApp');

          MyTestForm := MyTestApp.MyForm;

          TestButton := MyTestForm.WaitVCLObject('BtnConformOverWriteYes', 10000);

          if TestButton.Exists and TestButton.VisibleOnScreen then

             TestButton.ClickButton;

    end;




    Hope this helps point you in the right direction.
  • d4h8a1's avatar
    d4h8a1
    New Contributor


    Currently I'm doing this:



    BtnRetreiveClose = Aliases["EsiMain"]["wndWindowsForms10Window8app033c0d9d5"]["WindowsForms10Window8app033c0d9d"]["WindowsForms10Window8app033c0d9d"]["btnClose"];



    if (BtnRetreiveClose.VisibleOnScreen()) {

    }



    That crashes.  However, when the code looks like this:



    if (Aliases["EsiMain"]["wndWindowsForms10Window8app033c0d9d5"]["WindowsForms10Window8app033c0d9d"]["WindowsForms10Window8app033c0d9d"]["btnClose"]["Exists"]) {}



    Everything works great.  What is the difference between the two methods and why would it work any different?




  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It has to do with the "exists" check.  I believe that the NameMapping/Aliases does some of the checking to see if the object exists (such as I put in with the WaitVCLObject call) and, if it doesn't returns, it a "stub" object with "Exists" set to false.



    So, I think it still comes down to checking to see if the object exists first.  If it exists, then set your variable to point to that object and call ClickButton.
  • Hi,



    Well, actually, VisibleOnScreen is a property, and you cannot call it like a method. Use obj.VisibleOnScreen instead of obj.VisibleOnScreen().