Ask a Question

Object functions returning Object, Javascript doesn't understand the type.

tristaanogre
Community Hero

Re: Object functions returning Object, Javascript doesn't understand the type.


@Novari-QA wrote:

Correct that seems to have done it.

My next question, is why isn't other classes able to see these functions? The Code below works. However when exporting the class to another, it doesn't know what UserPrefs is

var Header = undefined;

var Main = {
  UserPrefs: function() { 
    Header.menuMain.HoverMouse(); 
    return Header.menuMain_UserPrefs; 
  }
}

function foo() {
  Header = Aliases.browsers.pageDashboard_PhysOffice;
  Main.UserPrefs().Click();
}


Navigation.cs

 

 

var Menu = require("Menu");

function foo()
{
  Menu.Header = Aliases.browser.pageDashboard_PhysOffice; 
  Menu.Main.UserPrefs().Click();
}


We have a header at the top of almost every page, I am trying to make a common class which all pages can reference when trying to navigate.

Menu.Parent.Child.Click(); is what I am trying to create. Then I would create a single class which handles Navigation.

 


 

It depends upon how you are doing the modules.export and the requires calls.  I have a "toy" project that I use to explore creating custom JavaScript classes and have them called across code units and, when implementing such a thing in TestComplete, there were some "hoops" I needed to jump through to get it to work properly.

 

Could you share the entire code units, complete with the exports calls and such?


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
Novari-QA
Frequent Contributor

Re: Object functions returning Object, Javascript doesn't understand the type.

Certainly
Foo function works, where abc function do not.


image.pngimage.pngimage.png

Novari-QA
Frequent Contributor

Re: Object functions returning Object, Javascript doesn't understand the type.

a

tristaanogre
Community Hero

Re: Object functions returning Object, Javascript doesn't understand the type.

The import functions feature of TestComplete does not do the necessary tasks for JavaScript.  In test, you need to add 

 

module.exports = Test

at the end of the code unit that has the class you want to export.  You can then instantiate and use that class in any unit that has 

 

var Test = requires("Test")

in the beginning.


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
cancel
Showing results for 
Search instead for 
Did you mean: