Forum Discussion

kroe761's avatar
kroe761
Contributor
10 years ago
Solved

Can't call functions from other files more than once when returning data- HELP! (Jscript web testing)

I have been running into this problem off and on, but today it became a full on blocker.  Everytime I try to call a function from another file AND I return an object into a variable, I get the error "Object doesn't support this property or method" .  This is driving me INSANE.  I am defining each of the buttions , links, etc that I use in my testing in mapping files and then call those functions and return the object when I need to use that object.  But, it's not working.  I have tried USEUNIT and Runner.CallMethod, they both error.  If I don't return anything into a variable in my test file, then it works with no problems, but when I return an object it craps out.  I have been back and forth with SmartBear tech support for the past few weeks and all I hear is "R&D is looking into this."  They told me to use var before a variable and that would fix it, but it didn't.



 I have attached a sample project.  Simply run the project or the project suite and you'll see what I'm talking about ANY help you can provide would be extremely gratifying.  Thanks so much!

5 Replies

  • Your functions names and variables names are same. Rename functions in the"Mapping" unit. It will help.

    Also don't forget  that all variables created without "var" become global.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    The solution is just as John Smith/SmartBear support said.

    I was able to run your project successfully simply by adding "var" before each of your variable declarations. Also not good practice to define your local variable with the same name as the function you are calling. Essentially you were redefining each function as a global variable, and when your second run came around you were trying to call that variable ex(blogLink()) as a function.

    Reference: http://stackoverflow.com/questions/1470488/what-is-the-function-of-the-var-keyword-and-when-to-use-it-or-omit-it

    See attached revised project.
  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    CollectGarbage() hints to the garbage collector that memory needs to be cleaned.
    Shouldn't be necessary to use, but if you have scripts run long enough you'll likely run into a situation where it has to be called. Seems the GC does not always collect fast enough and there are ways to structure your code so that dead memory is not recognized by the GC. I've never had a problem with calling it unnecessarily so I've just made a habit of calling it where I think it may be necessary. Mostly it seems that Test Complete has some inefficiencies with memory usage and I've found that calling the GC manually helps alleviate the problem.
  • Marsha_R's avatar
    Marsha_R
    Champion Level 3
    Did Tech Support also tell you to upgrade your TestComplete and try it again?  That's my favorite.  :)
  • Thank you so much!  After John Smith replied, I did some playing around and it turns out I have to BOTH add var and change the variable name in the Mapping file.  Thank you (both!) so much!  I come from a QA background and everything I know is self-taught, so some best practices stuff I never learned for whatever reason.  Thanks again!



    Also, in your ammended project, what is CollectGarbage()?  Never seen that.  Thanks!