Forum Discussion

LOrban's avatar
LOrban
Occasional Contributor
11 years ago

Best practices for Scripting


Hi All,



Being new with TC scripting technologies (however long time programmer),

I’m trying to clarify the best practice to test web applications with JScripts.



Consequently I would like to compress the long-stretched script converted from KeyWord test into something handy using either:

 - enumeration type variables as described by Gennadiy Alpaev in his book: ‘TestComplete Cookbook’ (Chapter 3 page 62)

 - and/or functions to perform property checks and actions (saw one forum thread with: clickObject(propName, propValue, depthOfSearch)



Not sure if this is the best way to go(!), however I tried something like:



function funUiCheckPageLogin()

{

  //declare page related variables:

  panSplash = Aliases.browser.pageLogOn.panelSplashBackground;

 

  var strObjReference = "";

  var enuFrmSplashObj = ["textnodePleaseLogOn", "labelLeadlabel"];

  var enuFrmSplashPrm = ["contentText",         "contentText"];

  var enuFrmSplashVal = ["Please log on",       "Email/Username:"];



  //Checks:

  try

  {

    for(var i = 0; i < enuFrmSplashObj.length; i++)

    {

   //the below line will fail obviously for the object won't be built up with the enumeration string addition

      var objObjReference = frmSplash.enuFrmSplashObj

      aqObject.CheckProperty(objObjReference, enuFrmSplashPrm, cmpEqual, enuFrmSplashVal);

    }

  }



Since I could not find best scripting practice techniques in otherwise exceptional SmartBear help pages and forums (still foraging through them...), I thought someone might share with me his/her tightly kept secrets regarding these techniques...  :)



Cheers,

Lto


  • Hi László, using a combination of JScript Constructors and the Test Complete Page Object, it is possible to approximate the Selenium Page Object pattern.




    This provides the benefits of:



    1. Single point of contact to Page elements, if an element on a page changes, only a single point in the code needs changing to reflect the change. 


    2. Abstracting Page and Element interaction away from Test Scripts, Test Scripts need only know how to use a Page Object, the detail of addressing a Page element is hidden away making simplifying Test Scripts.


    3. Promotes re-usability



     


    For mine, this is the minimum standard to adhere to when writing automated Test Scripts for Browser applications. In fact, I use similar patterns for testing Windows forms applications.


     


    Regards,


    Phil Baird

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi László, using a combination of JScript Constructors and the Test Complete Page Object, it is possible to approximate the Selenium Page Object pattern.




    This provides the benefits of:



    1. Single point of contact to Page elements, if an element on a page changes, only a single point in the code needs changing to reflect the change. 


    2. Abstracting Page and Element interaction away from Test Scripts, Test Scripts need only know how to use a Page Object, the detail of addressing a Page element is hidden away making simplifying Test Scripts.


    3. Promotes re-usability



     


    For mine, this is the minimum standard to adhere to when writing automated Test Scripts for Browser applications. In fact, I use similar patterns for testing Windows forms applications.


     


    Regards,


    Phil Baird

  • I suppose it could depend on what you are testing but we have Keyword Tests with a few scripts mixed in and I have used TestComplete with straight scripting before and I don't see that there's much difference in keeping it updated as development goes along.  We change stuff all the time.  



    I can think of some instances where search/replace might work better in scripts than it does in Keyword Tests, but otherwise maybe the difference is in the learning curve?  If you are already familiar with scripting then using Keyword Tests can seem a little clunky.  
  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi László, I see what you mean.

     


    We basically use a JScript/Keyword Test hybrid in the following manner:


     


    1. JScript to perform all the donkey work.


    2. Keyword Tests to orchestrate execution of JScript functions in a try/catch/finally pattern that allows us to intercept failures and log results for automatic logging to a JIRA system post Test Execution. 


     


    This also means that Testers that don't have strong development skills can still put together automated Tests.


     


    Regards,


    Phil Baird

  • LOrban's avatar
    LOrban
    Occasional Contributor
    Thanks Phil!



    I set my head back into the proper top-down programming while “grinding” myself through the implementation of web-based testing and I realized what my real question would have been…



    Due to TestComplete’s flexibility I see about 4 major ways of implementing automated testing:



    • Keyword testing:


      • Advantage:  quick to implement


      • Disadvantage:  difficult to maintain with development changes;




    • Keyword with Script testing (“hybrid” mode):


      • Advantage:  easy transition


      • Disadvantage:  even more tedious to keep updated both types during the development changes;




    • Script testing while relying on Stores Objects and NameMappings:


      • Advantage:  easy name referencing


      • Disadvantage:  in spite of nice UI-s updating options, the process is still not quick




    • “bare” Script testing through methods defined at:  (http://support.smartbear.com/viewarticle/62116/ ;   http://support.smartbear.com/viewarticle/56634/)


      • Advantage:  simply program scripting implementation


      • Disadvantage:  less documented?




    By following the forum threads, I guess the last way of testing is used by most of the “deep-drilling” TC users…?



    Note: during our web testing I had to go with the QuerySelector() and QuerySelectorAll() search methods with patterns stored in CSV files, for our web-pages are “heavily” relying on Dojo component that assigns on the fly different ID-s to most of the web-objects.



    Cheers,

    Lto

  • LOrban's avatar
    LOrban
    Occasional Contributor
    Thanks Marsha and Phil, now I see in which way I can widen my view!

    Lto