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
sonya_m
SmartBear Alumni (Retired)

Thank you for helping Community!

 

@ChandanD have you tried Benoit's latest suggestion? Does it solve you issue? Please shareπŸ™‚


Sonya Mihaljova
Community and Education Specialist

Hello, 

 

I tried but it didn't worked. 

I also observed that when OK button is clicked, the process does not exists so I am trying now to check the process and then check OK button. With this there is one more issue which I am facing. The test case is passed but still it checks one more time and makes the test case fail. 

So sratching my head to find the solution. 

Below is the code I am using temporary. 

try
{
var svnt = Aliases.TortoiseProc
var inprogress = Aliases.TortoiseProc.dlgTrainingsvnCheckoutTortoiseSVN
var name = inprogress.WndCaption
while(svnt.Exists || name=="Checkout Finished!")
{
//if(name="Checkout Finished!")
//{ }
inprogress.btnOK.Click()
}

}
catch(e)
{
Log.Error(e.message)
}

You can check the error message.

 

ChandanD_0-1588834104703.png

 

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");

 

 

 

Un sourire et Γ§a repart

Hi,

 

while(name="Checkout Finished!")

= is assign, so your condition will be ALWAYS true

Somewhere in time I met a book with coding recommendations... One of them was to put a constant in comparisons to the first place.

So the above will be

while ("Checkout Finished!" = name)

It looks a bit unusual at first, but its idea is that this line of code will fail immediately with the error that there is attempt to assign a value to the constant. Quite effective way to prevent typos with one or two equal signs, I would say...

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================

I think i understand the trick but i' not sure.

 

But nevertheless this trick is dangerous because it make antinomic reading of the code (making an underlying condition with assignment) and here i don't see the advantage, or perhaps i didn't really understand the trick  ;^)

 

Txs @AlexKaras to learn me this .. or not .. or perhaps ... lol .. lost in translation i am ...

 

Un sourire et Γ§a repart

@BenoitB :

Well, it was late, so I was not crystal clear... πŸ˜‰

As an example:

while(name="Checkout Finished!")

This is an assignment that will be evaluated to True. Code will execute without any error/exception and one might spend some time in debugger until the typo is noted.

 

> while ("Checkout Finished!" = name)

This fails immediately during runtime with the error like 'attempt to assign a value to a constant'. Code stops and the problem is clearly visible.

For me it was not that difficult to get used to 'reverse' notation. As well as remember a simple rule: 'The constant in comparisons has to be put in the first place'.

 

Hope that now I was more clear πŸ™‚

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================

Ok i got it !

 

The rule is simply writing the constant first because if you make the typo (= instead of ==) you detect it instantly

 

I was looking for something more complex .. don't know why !

 

Txs @AlexKaras  i add it to my writing guidelines.

 

Un sourire et Γ§a repart


@BenoitB wrote:

The rule is simply writing the constant first because if you make the typo (= instead of ==) you detect it instantly


Yes, absolutely correct.

πŸ™‚

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results forΒ 
Search instead forΒ 
Did you mean:Β