Forum Discussion

Mia's avatar
Mia
Contributor
11 years ago

Record&Playback versus creating scripts manually: What is better?

Hi,





I have a little experience with creating testing scripts manually with some conventions of mapping and naming objects and I also created a few test scripts using TestComplete Record Script functionality. I've been trying the compare whether it's better to do it myself or let TestComplete generate script which is really hard to read and to edit. Of course, creating those scripts manually is definitely more time consuming but on the other hand, easily editable, easily readable...



I'd rather use the Record script functionality with some modifying after (there are a lot of things that cannot be tested without writing some special methods), because it is faster and it works pretty reliably with WPF.  But here's the thing with the editaion of such unreadable code which Test Complete generates (see below).



Aliases.My_Client.FerdaMain.MdiClient.TechnologyOverview.host.HwndSource_AdornerDecorator.AdornerDecorator.AvalonAdapter.TechnologyOverviewView.MainGrid.MyDock.MyDockPanel.ScrollViewer.SwimContainer.Border.SwimLine.Grid.ItemsListBox.ListBoxItem2.Border.Grid.ButtonDegree.ClickButton();

Aliases.My_Client.Dimension_Map.host.HwndSource_AdornerDecorator.AdornerDecorator.AvalonAdapter.DimensionMapView.Grid.MainGrid.GroupedDataGrid.GroupItem.DataGridRow.DataGridCell3.ContentPresenter.ComboBox.ClickItem(1);

Aliases.My_Client.Dimension_Map.host.HwndSource_AdornerDecorator.AdornerDecorator.AvalonAdapter.DimensionMapView.Grid.MainGrid.GroupedDataGrid.GroupItem.DataGridRow.DataGridCell4.ContentPresenter.Grid.Grid.Button.ClickButton();





My first question is, if you have some way to make the generated code more readable (I know that I can order TestComplete to generate the variables, but sorry - that's much worse in case of our application. I was thinking about creating an easy application which clears the code and puts the recurrent parts into variables. I was also thinking about using Keyword tests instead, but I need to use my own functions to control our application, so it's not suitable for me.

But I wonder if there is some another way?



And my second question is, should I rather consider creating the scripts on my own even if it takes longer to create the tests? Is there anyone who uses Record and Playback tests for application which is constantly beeing developed. I simply do not know how to keep the awful generated code fresh.

4 Replies

  • You can try mapping your objects first and then recording your script for slightly cleaner code. That being said, you will always have to go back and clean up the code it generates anyway.



    Normally we try to create a name mapping structure that simplifies the items we want to access before we write/record a script.



    For example, if there is a page with a table for entering customer details we would normally create an aliases for the page, ie Aliasses.CustomerDetails and then we would reorganize the name mapping file to have the controls we want to have access to right at that root level. ie txtPhoneNumber, txtFirstName, etc



    Then to set the text for a field, it is clean by using Aliasses.CustomerDetails.txtFirstName.SetText("Robert");



    In your case, you could likely clean up your name mapping/aliases to make it a bit cleaner but not knowing your application its tough to give specifics. For example:



    Aliases.TechnologyOverview.ButtonDegree.ClickButton();

    Aliases.DimensionMapView.Grid.ComboBox.ClickItem(1);

    Aliases.DimensionMapView.Grid.Button.ClickButton();



    You would have to give the mapped items meaningful names to make it easy to read as well. IE, if the Button in the third line is for saving name it that: SaveNewRecord



    I would also look at using the Find method to locate the object on the page instead of mapping if the structure of the page is dynamic.



    Being a developer originally I find it much easier and quicker to simply write the script from the start.
  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3
    I wouldn't recommend using strictly record/playback, for the reasons you've already noted.  Scripting or keyword tests are much more precise. 



    You can certainly mix keyword tests and scripts as needed, if that suits your needs.  At the moment we are using mostly keyword tests, with some code and scripts mixed in where they are useful.  



    We use recording occasionally to help find object properties, but not as an integral part of a test.  





  • NisHera's avatar
    NisHera
    Valued Contributor
    Hi,

    Me too started with recording and came across same problems you have.

    As stated above reply you can shorten the code by proper manged name mapping.

    I named mapp with meaning full names (to me)and by pass unnessary middle object drag and droping.

    after that I create a kind of framework ie ..to have functions commonly used. eg data entering of most used window, navigating through application..etc. which took some time.

    Finally now I can quickly produce tests needed.



    for you senario, I think better to have manageble name mapping structure, recording and changing or writing manually depend on set of skills and convinionce(I do both depending situation). Also think about library of most used functions/or classes.



  • Mia's avatar
    Mia
    Contributor
    Hello,



    Thanks to all of you for sharing your experience.

    I tried to edit NameMaping, but the editing of our application would be really time consuming. Also, after I changed the NameMapping and I tried to record script, the code was generated in the old (not edited)  ugly format anyway... Maybe I did something wrong, but nevermind. I eventually tried to combine Keyword tests with scripts and I think that's perfect. I didn't know this combination is possible in TestComplete. So I decided we use the Keyword testing for now. I hope it will not be problem in future :)

    Thank you again.



    Miriam.