Forum Discussion

mithunpal2's avatar
mithunpal2
Contributor
5 years ago
Solved

Script failue as test compete searching for an object in the if statement and didn't find it

function Unit12()
{
if(Aliases.Device.Process_ionicframework_newpnm295021.RootLayout.WebView_orgapachecordovaengineSystem.HomePage.CustomerAccount.CustomerAccountSearch.CustomerAccountSearch.SearchBYIPV4.SearchBYIPV4.VisibleOnScreen)
{
Log.Message(aa)
}
else
{
KeywordTests.TS01_BackButton.Run();
}
}

 

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.. 

  • Yo!

     

    In belowe code example You have twice:

    a) "Aliases.Device.Process_ionicframework_newpnm295021.RootLayout.WebView_orgapachecordovaengineSystem.HomePage.CustomerAccount.CustomerAccountSearch.CustomerAccountSearch.SearchBYIPV4.SearchBYIPV4.VisibleOnScreen"

     

    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.

4 Replies

  • Wamboo's avatar
    Wamboo
    Community Hero

    Yo!

     

    In belowe code example You have twice:

    a) "Aliases.Device.Process_ionicframework_newpnm295021.RootLayout.WebView_orgapachecordovaengineSystem.HomePage.CustomerAccount.CustomerAccountSearch.CustomerAccountSearch.SearchBYIPV4.SearchBYIPV4.VisibleOnScreen"

     

    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.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    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.

     

  • I got this error-

    Unable to find the following object when executing the VisibleOnScreen command:

    Aliases.​Device.​Process_ionicframework_newpnm295021.​RootLayout.​WebView_orgapachecordovaengineSystem.​HomePage.​CustomerAccount.​CustomerAccountSearch.​