Conditional if statements do not seem conditional
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2010
02:43 AM
07-30-2010
02:43 AM
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 4
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2010
04:10 AM
07-30-2010
04:10 AM
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)
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)
Hope this helps point you in the right direction.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
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.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2010
04:35 AM
07-30-2010
04:35 AM
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?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2010
04:39 AM
07-30-2010
04:39 AM
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.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
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.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2010
08:08 PM
08-02-2010
08:08 PM
Hi,
Well, actually, VisibleOnScreen is a property, and you cannot call it like a method. Use obj.VisibleOnScreen instead of obj.VisibleOnScreen().
Well, actually, VisibleOnScreen is a property, and you cannot call it like a method. Use obj.VisibleOnScreen instead of obj.VisibleOnScreen().
------
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Yuri
TestComplete Customer Care Engineer
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
