Forum Discussion

Vaccanoll's avatar
Vaccanoll
New Contributor
8 years ago

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?

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

     

    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:


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

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

     

    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:


    • charleshb's avatar
      charleshb
      Occasional Contributor

      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.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        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.