Forum Discussion

EkremMese1's avatar
EkremMese1
Contributor
3 months ago

The difference between Recording a Script and directly coding

Hello everyone, I am slowly building up my test cases with TestComplete. I realise that I am intuitively using an approach like that: 

1- Using Object Spy and locating Web Elements
2- Passing them into my code to interact, click(), setText() etc

But when I record a script TestComplete using a complete different approach like declaring variables for the WebElements in the code and then using them for interactions 

I'm curios what are the pros and cons of my approach? If I continue like that is it OK or it may cause some possible future problems for me? 

I will quote for the same code from same actions:

My code:

  //click Region dropdown
  NameMapping.Sys.browser.pagaPersonCreate.dropdownRegion.Click();
  
  //choose a value from the dropdown for example:Tbilisi
  NameMapping.Sys.browser.pagePersonCreate.regionTbilisi.Click();

Record Script Code:

 Browsers.Item(btChrome).Navigate("https://**********");
  let browser = Aliases.browser;
  browser.BrowserWindow.Maximize();
  let page = browser.pagePersonCreate;
  let form = page.sectionAddress.formRegion;
  form.label.Click();
  page.regionTbilisi.Click();
  form.label2.Click();
  page.textnodeDidgori.textnodeDidgori2.Click();


 Of course code is more than that but I just quoted that part I believe it is enough to  explain my question. 

Thanks everyone in advance. 

 

 

4 Replies

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If you're scripting (and also keyword testing), in my opinion, it's best to build up the name mappings that you will only interact with, first. Then organise your name mappings into aliases, so that you don't use long names when referring to an object, second.

    The record feature, may end up creating duplicate name mappings, e.g. dropdownRegion, dropdownRegion1, dropdownRegion2 etc - depending on whether the parent object properties have changed (and name mappings haven't been defined first).

    It's good to use the record feature to see how TC creates the script; you can use this to learn scripting, and use it as reference guide too.

    Do what suits you best.

  • Record feature is creating a lot of items in NameMapping and some of them are not even necessary and it sucks with auto-given name to objects. So that's why I proceed with using Object Spy to NameMap the Object that I really need and give understandable names.

    I was curious does my approach harm my TCs in anyway? 

     

      • eykxas's avatar
        eykxas
        Regular Contributor

        Unless there are hundreds of mapped elements (or more), which will slow down execution time.

        That's why my project doesn't rely on NameMapping anymore for my webapp.