cancel
Showing results for 
Search instead for 
Did you mean: 

Classes in Javascript

SOLVED
Highlighted
New Contributor

Classes in Javascript

I can't tell what version of Javascript is currently supported by TestComplete, but I am really hoping it supports classes of somekind.  (Bascially EcmaScript 2015) 

 

I tried searching for it, but all the hits I found were 5+ years old.  I am hoping things have improved in the last 5 years.  (But I have tried playing around with it, and I can't seem to make it work.)

 

Here is an ES2105 style Javascript class I would like to be able to use:

 

 

export class CoolStuff{    

    constructor(){
          this.coolness="this is cool";
    }

    function runCoolness(addedCoolness){

          Log.Message("Executing Coolness: " + this.coolness + " along with: " + addedCoolness);

         // Other Stuff here
    }
}

// In another file...

let coolStuff = new CoolStuff();

coolStuff.runCoolness("more and more cool");

 

Is there a way to pull that kind of thing off with TestComplete?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Classes in Javascript

From the help at https://support.smartbear.com/testcomplete/docs/general-info/version-history/features-added-to-ver-1...

 

TestComplete 12 adds JavaScript (ECMAScript 6) as a new scripting language for writing automated tests. You can record, write, run, and debug tests written in JavaScript.

JavaScript in TestComplete is powered by the V8 engine – the same engine that is used in Google Chrome and Node.js. For the usage specifics, see JavaScript - Specifics of Usage.

 

As an example.... see, this past Friday was Hobbit Day (yes, I'm that much of a nerd) and I have this bit of PseudoCode hanging on my wall of my cubicle:

import gandalf;
import balrog;
import bridge_of_khazad-dum;
public class GandalfvsBalrog extends Moria
{
Wizard Gandalf; //declare variables
Balrog misterSparkles;
main()
{
Gandalf.print("You Shall NOT PASS!!!);
misterSparkles.print("RARARARRRRARR!!!!);
Gandalf.HitGroundWithStaff_MakeBridgeFall;
if(misterSparkles.isFallingWayDown)
{
misterSparkles.whipGandalf_bringHisButtDownToo;
}
while(Gandalf.isFallingWayDown)
{
Gandalf.GrabSword_KickButtandYellAlot;
}
return One_Smoted_Balrog;
}
}

So.... For Hobbit Day, I converted this into a JavaScript automation.  I've attached the code units as an example... the result looks like:


bridgeLog.png


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

View solution in original post

3 REPLIES 3
Highlighted
Community Hero

Re: Classes in Javascript

From the help at https://support.smartbear.com/testcomplete/docs/general-info/version-history/features-added-to-ver-1...

 

TestComplete 12 adds JavaScript (ECMAScript 6) as a new scripting language for writing automated tests. You can record, write, run, and debug tests written in JavaScript.

JavaScript in TestComplete is powered by the V8 engine – the same engine that is used in Google Chrome and Node.js. For the usage specifics, see JavaScript - Specifics of Usage.

 

As an example.... see, this past Friday was Hobbit Day (yes, I'm that much of a nerd) and I have this bit of PseudoCode hanging on my wall of my cubicle:

import gandalf;
import balrog;
import bridge_of_khazad-dum;
public class GandalfvsBalrog extends Moria
{
Wizard Gandalf; //declare variables
Balrog misterSparkles;
main()
{
Gandalf.print("You Shall NOT PASS!!!);
misterSparkles.print("RARARARRRRARR!!!!);
Gandalf.HitGroundWithStaff_MakeBridgeFall;
if(misterSparkles.isFallingWayDown)
{
misterSparkles.whipGandalf_bringHisButtDownToo;
}
while(Gandalf.isFallingWayDown)
{
Gandalf.GrabSword_KickButtandYellAlot;
}
return One_Smoted_Balrog;
}
}

So.... For Hobbit Day, I converted this into a JavaScript automation.  I've attached the code units as an example... the result looks like:


bridgeLog.png


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

View solution in original post

Highlighted
Occasional Contributor

Re: Classes in Javascript

How did you get the import to work? For me it just shows "Unexpected token import" syntax error in the importing script unit.

 

Edit: OK, I see the code attached and it does not use "import" - it just uses require("...") followed by instance creation.

So, not good for me. It seems we cannot use the "import" keyword.

Tags (2)
Highlighted
Community Hero

Re: Classes in Javascript


@charleshb wrote:

How did you get the import to work? For me it just shows "Unexpected token import" syntax error in the importing script unit.

 

Edit: OK, I see the code attached and it does not use "import" - it just uses require("...") followed by instance creation.

So, not good for me. It seems we cannot use the "import" keyword.


See my reply in your other thread.  You are correct "import" is not supported in TestComplete.  While JavaScript is supported as ECMAScript 6, it is not quite the same as doing a straight JavaScript set of code.  TestComplete utilizes the engine but you still need to follow TestComplete conventions of usage.


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
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors