cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to handle the error using the script: "Unable to find the object"

SOLVED
SJ1
Occasional Contributor

Unable to handle the error using the script: "Unable to find the object"

Hi, I am trying to automate oracle forms application.

 

The script I have written searches for the window object. If its found, it logs "window found" else it should say "not found". Btw, i am storing the objects in XML as strings and using eval to convert to object,

 

The script works fine when it finds the window object. In negative scenario, where the window object is not available, it abruptly terminates the execution flow with the message written to log: "Unable to find the object AWTObject("FWindow", "No Results Found", 0). See Additional Information for details." 

 

Instead I would expect the script to handle this error and get into the else part to display the message. [Note: I have not enabled Stop on Error in project properties]

 

Can you please help me with the code to handle this object not found error which is thrown during the script execution?

 

Please find the script below:

 

function Window_NoResultsFound()
{
var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
if(noResultsFoundAlert.VisibleOnScreen)
{
Log.Message("window displayed")
}
else
{
Log.Error("window not displayed");
}
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
shankar_r
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

Below approach is not recommended by many users but based on the flow this will work.

 

function Window_NoResultsFound() {
    var noResultsFoundAlert = null;
    try{
        noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
    }catch(ex){
        //if you want you can Log.erro here too
    }
    if (noResultsFoundAlert == null) {
        Log.Checkpoint("Window is not displayed as expected.")    
    } else {
        if (noResultsFoundAlert.Exists) {
            Log.Error("Windows is displayed");
        } else {
            Log.Checkpoint("Window is not displayed as expected.");
        }
    }
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

View solution in original post

10 REPLIES 10
AlexKaras
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

Hi,

 

Most probably, the reasons are:

1) You have 'Stop On Error' option turned on in the runtime properties of your project;

2) As a part of the string used in eval() you are having something like AWTObject(...). AWTObject must be replaced with its WaitXXX version: WaitAWTObject(...) - see documentation for the list of function parameters.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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 Heroes]
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 Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
shankar_r
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

I would recommend checking Exists before checking any other properties.

Like below,

function Window_NoResultsFound() {
    var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
    if (noResultsFoundAlert.Exists) {
        if (noResultsFoundAlert.VisibleOnScreen) {
            Log.Message("window displayed")
        } else {
            Log.Error("window not displayed");
        }
    } else {
        Log.Error("window not displayed");
    }
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

SJ1
Occasional Contributor

Re: Unable to handle the error using the script: "Unable to find the object"

Thank you AlexKaras and Shankar for your time.

Unfortunately these options doesn't seem to work.

1. Stop On Error: Is not turned on
2. WaitAWTObject: didn't work
3. Exists : doesn't seem to work

 

Looks like the script fails even before using these commands, where TestComplete tries to look for the object once its defined, once it hits the below line:
var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);

 

I have also tried declaring the object directly in the script and not in xml. That doesn't seem to work as well.
var noResultsFoundAlert = Aliases.jp2launcher.SwingObject("......");

 

The moment the object is declared, TestComplete tries to look for it and fails it straight away in runtime before moving onto the next statements/conditions.

 

Any other solutions would be much appreciated.

shankar_r
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

One thing you have to keep in mind,


var noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);

OR

var noResultsFoundAlert = Aliases.jp2launcher.SwingObject("......");


The object should be available when the script comes to above line(s), If object not found then it will immediately throw an error.

You have to wait until the object became exists using WaitProperty.


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

SJ1
Occasional Contributor

Re: Unable to handle the error using the script: "Unable to find the object"

Being a newbie, trying to do few things. Please let me know if there are better ways to do it.

 

 

I need to log the Test case as Pass or Fail based on the window object being displayed or not. 

 

If object is available, then no issues, test case gets marked as Pass.

 

But when the object/window is not available (and is not going to be displayed at all, so will not be able to use Wait), then it should log the result as "Fail" but now it throws runtime error. Is it possible to handle it?

shankar_r
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

Below approach is not recommended by many users but based on the flow this will work.

 

function Window_NoResultsFound() {
    var noResultsFoundAlert = null;
    try{
        noResultsFoundAlert = eval(ReadObjectsFromXML.noResultsFoundAlert);
    }catch(ex){
        //if you want you can Log.erro here too
    }
    if (noResultsFoundAlert == null) {
        Log.Checkpoint("Window is not displayed as expected.")    
    } else {
        if (noResultsFoundAlert.Exists) {
            Log.Error("Windows is displayed");
        } else {
            Log.Checkpoint("Window is not displayed as expected.");
        }
    }
}

Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

View solution in original post

SJ1
Occasional Contributor

Re: Unable to handle the error using the script: "Unable to find the object"

Hi Shankar, That worked! Thanks for your time.

shankar_r
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

Glad, it worked for you!


Thanks
Shankar R

LinkedIn | CG-VAK Software | Bitbucket | shankarr.75@gmail.com

“You must expect great things from you, before you can do them”

Extension Available

AlexKaras
Community Hero

Re: Unable to handle the error using the script: "Unable to find the object"

@SJ1:

 

Hi,

 

First of all: if solution suggested by @shankar_r works for you then it's fine.

Technically it must work, though there is one peculiarity that was already mentioned before but not explained in detail.

Preface:

TestComplete addresses objects in two modes. I call them explicit and implicit ones.

Explicit mode is when you address some object by its exact path within objects hierarchy. E.g. Aliases.jp2launcher.SwingObject("..."). In this case it is assumed that all objects along the hierarchy (jp2launcher and other intermediate objects that are skipped in the Aliases tree but are present in the NameMapping one) and the final object itself (SwingObject("...")) must exist. If some object along the hierarchy cannot be found, then this is considered as a problem and reported as an error to the test log.

Implicit mode is when objects are addressed not directly, but via their complimentary .WaitXXX() methods. This mode must be used when either you don't know if the given object exists at the moment or when it is OK if the object does not exist. Example of implicit addressing: Aliases.WaitChild('jp2launcher').WaitSwingObject("..."). If WaitXXX() method cannot find the sought for object, then an empty stub is returned with the only .Exists property set to False, so that you can check whether or not the object was found. Note, that if the object was not found, the returned stub will not contain .WaitXXX() method and 'chained' search for subsequent object will fail with the 'Method not found' error posted to the log. Thus you must check search result on the object-by-object base.

 

Now back to your case:

Eval() function does not return any information if some problem occurs within the code executed as its argument. Thus, if your parameter string is 'Aliases.jp2launcher.SwingObject("...")' and the search for jp2launcher fails within eval(), you will not obtain any useful information back but will just get an empty stub (or exception).

Likewise, even if you have parameter string as 'Aliases.WaitChild('jp2launcher').WaitSwingObject("...")' and jp2launcher object does not exist, you still will get an empty stub and still will not be able to figure out the real reason - whether this happened because the sought for object was not found (SwingObject("...")) or because some object along the search path did not exist and thus there was even no attempt to search for the final target object.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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 Heroes]
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 Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors