Forum Discussion
11 Replies
- tristaanogreEsteemed ContributorThe label itself does not break from a loop. Instead, you use the label to indicate that, if a condition is met, to go to a particular line designated by the label.
so, for example, if you have a for loop that you're iterating through a list of items or records and you find a particular record, you can use the Go To Label operation http://smartbear.com/support/viewarticle/17269/ to then go to a particular line of code.
Personally, when I was taught programming, I was told to avoid whenever possible any Go To code. While it's helpful for certain things, I'd prefer that, if a condition is met, I execute another keyword test or another script test instead of going to a line of code in the existing test. - OfervSuper Contributori'll tell you what i need to deal with.
the script run and installation and when the installation ends it run an uninstall now, sometimes the install get stuck on the screen where the progress bar is (because somehow installshield runs 3 msiexec.exe processes in the task bar) so, what i want to do is when you see that the finish button (that suppose to appear on the screen right after the progress bar finish and the installation ended) exists click it and if it doesn't appear for let say 20 secs breakthis loop of install/uninstall close the msiexec.exe processes (i have routine that does that) and start the next loop iteration.
her's the code part i'm using:
if(!Aliases["MSIEXEC"]["BaseWindow"]["FinishScreenFinishButton"]["WaitProperty"]("Exists",true,15000))
{
//Log installation stack
Log["Warning"]("Installation didn't end properly,installation abroted")
//Log a Picture of the object
Log["Picture"](Aliases["MSIEXEC"]["BaseWindow"], "Installation Progress Screen")
break;
}
else
{
Keep on with the installation
}
do you have any smarter solution?
thanks - OfervSuper Contributorby the way under the link you sent there is no code example and therefore it's hard to understand how to do that.
can you be more specified - tristaanogreEsteemed ContributorHard to do a "code sample" for a keyword test that is a visual test. The "Label" statement and "Go To Label" statements are for creating keyword tests, not for script code.
As for the code you have, that looks like the best thing. You're looking to see if the form exists. If it does, log a warning, and break out of the loop.
As a suggestion, I'd change your if statement to, instead of WaitProperty, do something likeif(!Aliases["MSIEXEC"]["BaseWindow"]["WaitAliasChild"]("FinishScreenFinishButton", 15000).Exists)
The reason being is that if FinishScreenFinishButton doesn't exist, it doesn't make any sense to check properties on a non-existent object. - OfervSuper Contributoryes thanks,
but tc tells me that it can't use break out of a loop because my loop is in my Main routine
function Main()
{
for(i=1;i<1000;i++)
{
Log["Message"]("Iteration " + i + " Started")
//Install
KillRunningProcess()
CheckIfInstallationFileExists()
RunInstallation()
ValidateInstallationScreens()
//Uninstall
KillRunningProcess()
CheckIfInstallationFileExists()
RunInstallation()
RunUninstall()
}
}
and the break i'm using is part of the function RunInstallation() how can i solve this problem?
Thanks - tristaanogreEsteemed ContributorInstead of break, I'd then use a "return false" for your error condition and a "return true" in your else statement. That way, in your loop, you can check the result of your "RunInstallation" function. If it returns false, then break, if it returns true, continue.
- YMinaev
Staff
Hi,
Instructions which control the loop flow (break and continue) must be located in the scope of the loop. If they're located in other routines, they're out of scope, and they actually do nothing.
Robert's suggestion is the only way to do what you need. - OfervSuper Contributorcool i ran the test over night for 3000 loops and it got stack at 7 (:-)).i guess that the advice with the return was working but,it's not exactly what i expected it to happen. what i wanted is that the moment it get to the windows where it stack it will break the for but will move on to the next for loop iteration and what it did is actually break the whole test.
does break does stop the whole for loop or it suppose to move on to the next for iteration?and if so what should i do in order to make it just move to the next for iteration.
Thanks for the support - OfervSuper Contributor:-)) o.k i got it i'm using continue. the only thing that is weird is that TC insist that i'll put ; after the continue.
by the way i saw that it is not essential to put ; at the end of a code line or is it? - OfervSuper Contributorwell i have another problem.
that's the main function:
function Main()
{
for(i=1;i<30000;i++)
{
Log["AppendFolder"]("Iteration " + i + " Started")
//Install
KillRunningProcess()
CheckIfInstallationFileExists()
RunInstallation()
Results = ValidateInstallationScreens()
if(!Results)
continue;
//Uninstall
KillRunningProcess()
CheckIfInstallationFileExists()
RunInstallation()
RunUninstall()
Log["PopLogFolder"]()
}
}
and it's working fine except from the fact that the Log["AppendFolder"]("Iteration " + i + " Started") is written in the same level of the iteration itself failed before means that my log file looks like that:
iteration 1
iteration 2
iteration 3
iteration 4
failed iteration
iteration 5
iteration 6
...
...
and so on the Log["AppendFolder"]("Iteration " + i + " Started") doesn't return to the same level it was when the test begin.
is there a way to fix it?
thanks