Forum Discussion

samantha_chin's avatar
samantha_chin
Occasional Contributor
9 years ago

How to learn to code in TestComplete script?

Hi,

 

I am newbies to TestComplete and still learning/understanding on how to code in script. Do you know where can I find library document to refer to? I tried to find in smartbear online/google, there is some samples but does not really have the info I need. Eg below.. I would like to find click the first Enter link found in a table but I just not sure what is the strong type declaration and syntax.

 

function Click_Enter_Link()
{


var obj = Aliases.browser.pagePageName.Frame("main").EvaluateXPath("//table[@class='tablegrid']//a",true);
if (obj != null)
{
   // Loop all the Atag elements and If obj innertext is 'Enter', click it --> How to code this????
}
else
{
// If the element was not found, post a message to the log
Log["Error"]("The element was not found.");
}
}

 

  • Hi Samantha_chin,

     

    Our TestComplete documentation contains a lot of samples for all supported languages. As you are calling the EvaluateXPath method, I recommend that you review the Finding Web Objects Using XPath Expressions ( http://smartbear.com/viewarticle/71392/ ) article with some samples you may find useful.

     

    In addition to this, TestComplete provides the Recording feature. By using it, you can create tests automatically. Perhaps, it will help you avoid creating tests anew.

     

    One more great support resource is the How To section: https://support.smartbear.com/howto

     

  • Looks like you're using jScript.

     

    So a handy site for reference is the MSDN area for the language.

     

    https://msdn.microsoft.com/en-us/library/t895bwkh(v=vs.100).aspx

     

    (You will also get to the page above if you follow the links in the TestComplete documentation for scripting)

     

    ie.

     

    https://support.smartbear.com/viewarticle/70500/

     

    takes you to:

     

    https://msdn.microsoft.com/en-us/library/ms950396.aspx

     

    ... which then takes you (with a couple more clicks) to my first link above.

     

     

    The above should give you most of what you need in terms of basic reference. Beyond that, google (stack exchange/overflow are usually a good source of answers) or ask on here ....

     

    I'm sure someone can provide you with a code snippet for the above (I don't use jscript myself so it won't be me I'm afraid). But make sure they explain and you understand what they've done. Otherwise, you don't learn much ....

     

     

    • samantha_chin's avatar
      samantha_chin
      Occasional Contributor

      Hi Colin,

       

      Thanks for the information. Ya I hope to get some sample snippet which I failed to find in the google. Even it is not in Jscript, C# is also good enough. Seems like not easy to learn though.. 

      • Colin_McCrae's avatar
        Colin_McCrae
        Community Hero

        I'm using C# Script myself at the moment. (Not my choice, request of the project team I'm working with - never used it before myself but I'm managing OK)

         

        There are some subtle differences.

         

        You probably want to pick a language early and stick with it.

         

        Personally, I think VBScript (where I started) is the simplest to learn. It does have some limitations (as do all languages) but it is also very easy to pick up. Jscript tends to be first choice for most on here. The basic concepts remain the same whichever language you use. But each has it's own strengths and weaknesses.

         

        Although, if I was starting TestComplete again today, I would probably try Python first. Having used it for something else (TestComplete didn't support it when I first started using it) it's a very nice language. Easy to learn, great online support, masses of libraries available, and it handles large amounts of data very well.

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Samantha_chin,

     

    Our TestComplete documentation contains a lot of samples for all supported languages. As you are calling the EvaluateXPath method, I recommend that you review the Finding Web Objects Using XPath Expressions ( http://smartbear.com/viewarticle/71392/ ) article with some samples you may find useful.

     

    In addition to this, TestComplete provides the Recording feature. By using it, you can create tests automatically. Perhaps, it will help you avoid creating tests anew.

     

    One more great support resource is the How To section: https://support.smartbear.com/howto

     

    • Marsha_R's avatar
      Marsha_R
      Moderator

      What we found helpful was to create some keyword tests that we could use and then use the Convert to Script function to see the same thing in a script.