Ask a Question

Unable to come out of the While loop.

SOLVED
ChandanD
Contributor

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.

17 REPLIES 17
rajulapati
Contributor

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

Hello,

 

No. it didn't worked. 

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

Wamboo
Community Hero

Hi,

 

In my opinion, you need to refresh mapping info

 

https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/refres...

 

TestComplete caches mapped objects to speed up test runs. The first time a test uses an alias, TestComplete remembers the found object and uses the cached object for all subsequent uses of the alias.

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

 

 

Un sourire et ça repart

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.

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()

}

 

= 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);
}

 

 

Un sourire et ça repart

Hello,

 

I shall explain in detail.

The OK button is not enabled until the download is completed.

It may take 10 min or 15 min or 20 min for OK button to be enabled. So I have to wait till that time frame. 

To check download is completed, it can be done with WndCaption=Checkout Finished!

So I am using while loop to wait for OK button to be enabled as I know the condition is WndCaption. Test complete waits for the time frame whatever it takes for OK button to be enabled. 

It clicks the OK button but it doesn't comes out of loop. It is still in while loop searching for WndCaption and Ok button.

Now with your script I believe it will come out immediately and it will not wait for OK button to enable.

Ok, so just wait for the text and then exit.

But put a watchdog to avoid infinite loop, for example 45mn.

 

var inprogress = Aliases.TortoiseProc.dlgTrainingsvnCheckoutTortoiseSVN;
var stopTime   = Win32API.GetTickCount() + (45*60*1000);
while (inprogress.WndCaption != "Checkout Finished!" ) {
  if (Win32API.GetTickCount() > stopTime)
    throw Error("Still not finished after security timeout, please check manually");
  aqUtils.Delay(30000);
  inprogress.RefreshMappingInfo();
}
inprogress.btnOK.Click();

Un sourire et ça repart

cancel
Showing results for 
Search instead for 
Did you mean: