Forum Discussion

Vaccanoll's avatar
Vaccanoll
New Contributor
8 years ago

Can't run custom JQuery

I am looking for ways around Named Mapping.  I thought maybe I can get the elements I need to interact with via JQuery.

 

At first I did this, to make sure that scripts are working:

 

page.contentDocument.Script.eval("alert('testing')");

 

That runs fine (and shows the alert).  I then tried: 


var originCode = page.contentDocument.Script.Eval("$('#OriginCode')");

 

Hoping to get the element I am looking for.  But that gave me an error (very unhelpful error that says: Error 0x80020101 and file and line number to the line above).

 

So then I tried this:

 

var originCode = page.contentDocument.Script.$("#OriginCode");

 

From that I get a pop up error in Test Complete.  It says:

 

JavaScript runtime error.

TypeError
page.contentDocument.Script.$ is not a function

 

But if I go to the console of my application and run $('#OriginCode') I get the JQuery object as a response.

 

Any ideas of what I can do to get JQuery to work?  

 

Or any other ideas to work around Named Mapping?  (If you want I can give a rant about how named mapping makes tests brittle and causes tons of work every time a slight change is made to the UI, but I will pass on that for now.)

 

 

  • If you want to get around using NameMapping, I guess JQuery is one way although I don't have any particular experience with it within TestComplete.  Keep in mind that TestComplete's editor is not a web page... it utilizes the JavaScript engine on your workstation to execute the JavaScript code, but that does not mean that everything you can do within a development environment for developing web pages will execute.  What I'm trying to say is that there's no guarentee that JQuery will work within the context of TestComplete.

     

    There are ways around NameMapping.  Look up the methods of "Find" or "FindChild" or "NativeWebObject.Find" or other such things.  I personally use a hybrid where some segments of my application undertest are mapped but for a variety of situtations I opt to use the "Find" methods to find the child objects and return them to my script code.  I know some folks build out their own fully fledged POM style structure where NOTHING is mapped and everything is referenced dynamically in the automation code.  

     

    If you check out the answer I gave to your other post (https://community.smartbear.com/t5/TestComplete-Functional-Web/Make-Named-Mapping-not-care-about-the-quot-Path-quot/m-p/150019) there is a solution to your particular problem with NameMapping.  The key, as mentioned, is understanding how NameMapping actually works... it searches the children of a parent object for a match based upon properties and it does that chaining down a whole tree.  Extended Find allows you to "compress" the tree to allow for variability in the inconsequential "DIV" panels that developers add and is a really powerful way of making your namemapping more robust.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    If you want to get around using NameMapping, I guess JQuery is one way although I don't have any particular experience with it within TestComplete.  Keep in mind that TestComplete's editor is not a web page... it utilizes the JavaScript engine on your workstation to execute the JavaScript code, but that does not mean that everything you can do within a development environment for developing web pages will execute.  What I'm trying to say is that there's no guarentee that JQuery will work within the context of TestComplete.

     

    There are ways around NameMapping.  Look up the methods of "Find" or "FindChild" or "NativeWebObject.Find" or other such things.  I personally use a hybrid where some segments of my application undertest are mapped but for a variety of situtations I opt to use the "Find" methods to find the child objects and return them to my script code.  I know some folks build out their own fully fledged POM style structure where NOTHING is mapped and everything is referenced dynamically in the automation code.  

     

    If you check out the answer I gave to your other post (https://community.smartbear.com/t5/TestComplete-Functional-Web/Make-Named-Mapping-not-care-about-the-quot-Path-quot/m-p/150019) there is a solution to your particular problem with NameMapping.  The key, as mentioned, is understanding how NameMapping actually works... it searches the children of a parent object for a match based upon properties and it does that chaining down a whole tree.  Extended Find allows you to "compress" the tree to allow for variability in the inconsequential "DIV" panels that developers add and is a really powerful way of making your namemapping more robust.