Forum Discussion

ChandanD's avatar
ChandanD
Contributor
5 years ago

Unable to come out of the While loop.

Hello,

I am scripting using Javascript. The function I am testing is SVN checkout.

The download starts and OK button is disabled. So I have a script to check the OK button is enabled. What is does it it clicks on OK button and then it is still searching for OK button. It doesn't come out of While loop.

 Below is the my script. Ok button is enabled when download is completed so I am checking the name download finished and then OK button is clicked.

function downloadcomplete()
{
try
{
var inprogress = Aliases.TortoiseProc.dlgTrainingsvnCheckoutTortoiseSVN
var name = inprogress.WndCaption
while(name="Checkout Finished!") { inprogress.btnOK.Click() }
}
catch(e)
{
Log.Error(e.message)
}
}

 

Could you let me know why it is doing so and what is the solution to make it come out of the loop once OK button is pressed.

  • BenoitB's avatar
    BenoitB
    5 years ago

    Please use code display to help reading. The avalialble option is visible when you click on ... and then </>

    Please put image in higher size, here we can't read it.

    Please never do test condition with assignment, it is useless as it will be always true (if name = 'blabla')

    Please explain "The test case is passed but still it checks one more time and makes the test case fail.", i don't understand, if test passed then why checking again ?

     

    What is exactly the problem with the previous code i given to you ?

    Have you tried to use breakpoint to better understand how it runs ?

     

    Your code is strange, what i understand is you loop while the process exists or name is equal to finished and in this loop you click every time.

     

    As already said this is bad method:

    - dont click continuously moreover when you told us that it can last 10 to 20 min.

    - the test condition name equal finished is the break condition so here the only effective test is the process exists

     

     

    Perhaps simply loop until the inProgress.btnOK.Enabled is equal to true (and keep a watchdog to protect yourself against infinite loop). Or use WaitProperty method.

    var btn     = inprogress.btnOK;
    var maxTime = 45*60*1000; // 45 mins
    if (btn.WaitProperty("Enabled", true, maxTime))
      btn.Click()
    else
      throw Error("Check out not finished after 45 mins, please check manually");

     

     

     

    • BenoitB's avatar
      BenoitB
      Community Hero

      And perhaps .. the test condition need != or ==, not a single = which is assignation .... 😄

       

       

      • ChandanD's avatar
        ChandanD
        Contributor

        Hello,

         

        I have tested with == before raising to smartbear support. With this it doesn't wait for OK button to enable and the script gets finished in OK button disabled.

    • ChandanD's avatar
      ChandanD
      Contributor

      Hello,

       

      Below is the code which I have written but still it is doing the same. Not coming out of while loop.

       

      var inprogress = Aliases.TortoiseProc.dlgTrainingsvnCheckoutTortoiseSVN
      var name = inprogress.WndCaption
      while(name="Checkout Finished!")
      {
      inprogress.btnOK.Click()
      name = inprogress.WndCaption
      inprogress.RefreshMappingInfo()

      }

      • BenoitB's avatar
        BenoitB
        Community Hero

         

        = is assign, so your condition will be ALWAYS true because you test that the assignation is done, which is always true...

        Moreover, the name variable is useless.

        Then avoid continuous click without delay between to let system act/react.

         

        I'm not sure, you want to wait the text Checkout finished and then click a button  OR you need to click a button till the text Checkout finished appears ?

         

        This click on button until the text Checkout finished appears:

         

        var inprogress = Aliases.TortoiseProc.dlgTrainingsvnCheckoutTortoiseSVN;
        while (inprogress.WndCaption != "Checkout Finished!" ) {
          inprogress.btnOK.Click();
          inprogress.RefreshMappingInfo();
          aqUtils.Delay(500);
        }
        
        

         

         

  • Hi ChandanD ,

     

    I would suggest you to use below code

    var name = inprogress.WndCaption
    while(name="Checkout Finished!")

    {

    inprogress.btnOK.Click()

    name = inprogress.WndCaption

    }

     

    You need to capture the Wndcaption again after you click OK button to make sure if the name of popup has changed or not.

     

    -Ashwin

    Please give a kudo and accept as a solution if it works

    • ChandanD's avatar
      ChandanD
      Contributor

      Hello,

       

      No. it didn't worked. 

      It is still in while loop searching for WndCaption & Ok button.