Script failue as test compete searching for an object in the if statement and didn't find it
Can anyone help me to understand - Why my above code is searching the object in the if statement?
during playback I am getting message waiting for the object..Preparing an object recognition hint..
Solved! Go to Solution.
I got this error-
Unable to find the following object when executing the VisibleOnScreen command:
In belowe code example You have twice:
Is this right?
b) "Log.Message(aa)" -> use " " inside "aa"
1) Try to check you NameMapping repository for correct object values "CustomerAccountSearch". do You have it in repository?
2) Do not use "VisibleOnScreen" if you want to check to exist of an object. Use .Exists instead.
To add to what was said by Wamboo:
> Why my above code is searching the object in the if statement?
Because your code references some object and tries to use some its property (.VisibleOnScreen in your case).
In order to get a value of some property, TestComplete must resolve all referenced objects within objects' chain. If some intermediate object is not found, all child objects cannot be resolved as well and an error will be posted to test log.
Considering your line of code as an example:
First, TestComplete will try to connect to a device.
If succeeded, it will try to find there the Process_ionicframework_newpnm295021 process. (I think that it is logical that there is no sense to look for the process if there is no connected device, isn't it?)
If the process is found, then TestComplete will search for the object referenced by the RootLayout alias. Note, that Aliases tree is based on NameMapping one but may be shortened, i.e. some intermediate objects from NameMapping tree may be excluded from Aliases tree for test code simplicity and manageability. Nevertheless, all parent objects (if any) from the NameMapping tree must exist as well while looking for the given Alias.
And only after the final referenced object is found (SearchBYIPV4 in your case), TestComplete will be able to check if it contains required property (VisibleOnScreen) an get its value.
You must use .WaitXXX() methods (.WaitAliasChild() in your case) instead of direct referencing if some given object may not exist at the moment. .Exists property must be checked then to verify if the object was found and only then you may use the found object.
For example, if the process may not be running, your code should be like this:
if (! Aliases.Device.WaitAliasChild("Process_ionicframework_newpnm295021", 0).Exists) // process is not running
// start the process and wait until it is ready
else // process is running
// you may use Aliases.Device.Process_ionicframework_newpnm295021 object in your code
Hope this makes things more clear.
/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.
Was the original issue resolved? Please share the solution you decided to use.
SmartBear Community and Education Manager