Forum Discussion

angief's avatar
11 years ago

JScript Vs. VBScript

My team is beginning to automate our regression suite.  One of my testers is comfortable with JScript, another with VBScript.  I feel that we need to use one or the other for supportablity and to standardize our approach to automation.  Can you help me choose which language to use?  what are the advantages/disadvantages to both languages?  Is there any considerations from a functionality perspective I need to be aware of when using the test complete tool and choosing a language?



5 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert

    Hi Angie, I would chose JScript for the following reasons at the very least:


     


    1. Exception handling, JScript offers full try/catch/finally blocks whereas VBScript offers a barely useful On Error Resume Next


    2. JScript allows you to treat functions as first class citizens, e.g. being able to pass a function to another function as a function parameter, allowing for some wonderfully elegant code. VBScript does not.


    3. VBScript User Classes declared in one Script Unit cannot be instantiated in another, a factory method is required within the declaring Script Unit that is called by other Script Units to create instances. JScript Constructors declared in one Script Unit can quite happily be instantiated in another.


    4. VBScript is ghastly, simply ghastly


     


    Test Complete offers a large number of objects, aqString, aqDateTime, aqFileSystem, ADO, DDT etc for handling a of the functionality required by tests, the scripting language really is just the glue that holds them all together.


     


    I guess it boils down to the experience you have available, and, did I mention, VBScript is ghastly?


     


    Regards,


    Phil Baird

  • jose_pita's avatar
    jose_pita
    Super Contributor
    JScript FTW!!!



    You forgot to mention the use of Javascript Libraries Phill ( I know you use them :) ), there are dozens of javascript libraries you can import into Testcomplete that can save you a lot of time and improve Testcomplete functionality by itself...
  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi nishnatha, a few pointers:

     



    1. Most libraries are written to bind into the Browser so may require tweeking to work within Test Complete.


    2. Libraries that are DOM/GUI specific are not of much use as Test complete has no Browser or DOM objects.


    3. The Wikipedia page somewhat bizarrely fails to mention any json libraries, such as json2.js, which can be very useful for testing Web.


    4. In order to use a JavaScript library, change the extension from js to sj and add to your project as an Existing Item.


    5. Most libraries utilise the JavaScript Closure Module pattern which can cause issues with Exception handling. I recommend writing Script Unit level functions in the Script Unit that contains the JavaScript library that access the functions, wrapped in try catch blocks, of the JavaScript library. It is these functions that are then used to utilise the JavaScript library instead of calling the JavaScript library directly.



     


    Regards,


    Phil Baird

  • sbkeenan's avatar
    sbkeenan
    Frequent Contributor
    Hi all



    Just thought I'd throw something else into the mix.  I've been using TestComplete for a few years now and always used VBScript without any difficulties.  I should say at this stage that we use it to test a Windows based desktop application and not a Web site.



    Since taking on a couple of new testers, we decided to switch to JScript and for the most part it's as easy to learn as VBScript, if somewhat confusing for the traditional OO programmer!!



    Anyway, one small, but I feel, very important aspect, is that currently, TestComplete uses version 3 of the ECMA standard (I think that's right), which means that something like the "use strict" statement doesn't work.  For those of you who don't know what this is, I'll start by describing the "Option Explicit"  statement, as used in VBScript, which does work in TestComplete:



    When creating scripts, it's all too easy to make typos, this can lead to really hard to spot bugs in the script where the typo involves a variable name.  In this instance, the system stops and reports that the variable has not yet been declared, thus making its correction a very simple one.  However, in JScript  rather than crashing out with a 'variable not declared' error, the system simply creates a new global variable and works with that.  



    The "use strict" statement only came into being from version 5 of the ECMA standard, in other words, it has no effect in TestComplete.  I only found this out when trying to explain its use to a colleague, only to find that it didn't work.  Since such errors as described above are easily made, this simple little statement can prove to be invaluable in helping to write stable/structured scripts, but alas, is not yet available in TestComplete.



    I have read many posts previously in relation to getting TestComplete up to date with what is often referred to as 'Modern JavaScript', and am now beginning to understand what all the fuss is about.



    Again, I'm not wishing to influence anyone's choice of scripting language (we now use JScript ourselves), but I have to say that I have never encountered any issues with VBScript and where it does have limitations compared to JScript, I always found that the workarounds are very simple and straight-forward to implement.  I, therefore, disagree that it's ghastly (sorry Paul).  With JScript,  I have to say that I do much prefer the syntax - it looks 'cleaner' than that of VBScript, however, I am not aware of any workaround for the "use strict" issue, except to ensure that you don't make any typos!!



    Regards

    Stephen.