Test Management Blog


Often when you start out with TestComplete you’ll find yourself bewildered by the complexity of identifying and naming the objects in the application you’re testing. TestComplete has a lot of powerful features to help with identifying objects in applications but when you’re starting out you’ll want to get to grips with the basics. The next few posts look at good approaches for mastering Name Mapping in TestComplete.

If you want to understand ‘why’ we have name mapping then this into article is a good place to start. If you want to understand ‘what’ name mapping is then read on. Or if you just want to find out ‘how’ to get started then we’ve got another post coming up soon.

What Is Name Mapping?

When we start out we’ve got a system that looks like this to TestComplete:

Test Complete Object Browser

What we need is a view or perspective on this that focuses on what we’re interested in for our tests. Something like this would be much easier to work with:

TestComplete Alias View

The Object browser

What’s in the Object Browser is exactly what TestComplete sees it at the system level. If you really wanted to you could even use the full system names to identify the objects in your tests. So for example if you use the object spy to identify an object you can see the full system name for the object.

You can then select the ‘Show in Object Browser’ button and you’ll see the object in the objects list in TestComplete. It’s this “Sys.*” name that you can then use in your test steps if you want to:

Sys.Browser("iexplore").Page("https://www.zoho.com/crm/lp/login.html").Panel(0).Frame("zohoiam").Table("outertable").Cell(1, 0).Panel("loginform").Form("login").Table("inntbl").Cell(0, 0).Table(0).Cell(2, 1).EmailInput("lid")

It’s not normally wise to use this though. The problem with the full system name is that it changes. It’s also difficult to understand because it’s so long. There are much better ways of identifying objects too.

Just bear in mind that this is where it all starts. It’s the foundation that the Name Map is built on. Think of the Object browser as the lowest layer. Then think of the TestComplete Name map and mapped objects as a layer on top of the Object Browser. When the Name Map is laid over the Object Browser it hides a lot of the chafe and complexity that you’re not interested in.

Mapped Objects

When you’re writing automated tests all you want to focus on are the objects in your application that you’re interacting with. So that you can focus on just the objects you’re interested in, the Name Map ‘Mapped Objects’ are picked out of system Object map. What you see then in a cut down list of mapped objects which are the objects you’re interested in for your testing.

So for example when you record a test, TestComplete will populate the name map with all the objects that you’ve interacted with during that recording. All the other objects on the system are ignored. Thus you get a clearer, more focused list of objects that you’re testing with.

That’s not to say TestComplete will give you a completely clear and focused list. TestComplete takes it’s best guess to identify the objects you interact with and map them. It’s not a mind reader though. It will map absolutely everything you interact with not just the objects you’re really interested in. TestComplete will also record the full paths to these objects which can be a little unwieldy. For example:

NameMapping.Sys.browser.pageSignInToYourZohoCrmAccount.
frameZohoiam.formLogin.buttonSignIn

Not exactly easy to type if you have to refer to this object many times in your scripts. Having said that it’s a big improvement over the “Sys.*” object name. In fact TestComplete has taken some steps to reduce the complexity of the naming by removing some of the container references which helps a bit too (e.g. levels like Table(”inntbl”) have been removed).

Where does this leave us? Well we started out with this….

Sys.Browser("iexplore").Page("https://www.zoho.com/crm/lp/login.html").Panel(0).Frame("zohoiam").Table("outertable").Cell(1, 0).Panel("loginform").Form("login").Table("inntbl").Cell(0, 0).Table(0).Cell(7, 1).Button("submit_but")

And now we’re down to this…

NameMapping.Sys.browser.pageSignInToYourZohoCrmAccount.
frameZohoiam.formLogin.buttonSignIn

Notice also that the reference starts out with the string “NameMapping.*”. Mapped objects start with “Sys.*”. The “NameMapping.*” naming convention can be used now in your scripts to identify that you’re refering to objects that are listed in the Name Map.

To make our lives even easier, and to avoid these long “Sys.*” and “NameMapping.*” naming conventions you can also make use of Aliases.

Aliases

Aliases allow us to put another layer on top of the Object Map and the Name Map. So this final layer on top simplifies things even further.

This simplifies things for 3 reasons….

1. You can change the name of objects to make them more meaningful

So for example you can take the name “emailinputLid” that your developers used in the application and change it to “EmailTextBox”.

2. You can manually remove layers of the heirarchy/path to simplify the path name.

So for example you might have a long path in the Name map and then modify this in the aliases to shorten it to something more logical. So you’d go from …..

Aliases.browser.pageSignInToYourZohoCrmAccount.frameZohoiam.
formLogin.EmailTextBox

to

Aliases.browser.pageSignInToYourZohoCrmAccount.EmailTextBox

3. You can rename items in the hierarchy/path

So these parts of the path that are left still look a little unweidly. So we can manually go in and rename parts of the path. At this point we’ll take this..

Aliases.browser.pageSignInToYourZohoCrmAccount.EmailTextBox

and rename to give us

Aliases.browser.SignInPage.EmailTextBox

Far more readable and meaningful when used throughout out keyword and scripted test cases.

Summary

We’ve set out with a system name of….

Sys.Browser("iexplore").Page("https://www.zoho.com/crm/lp/login.html").Panel(0).Frame("zohoiam").Table("outertable").Cell(1, 0).Panel("loginform").Form("login").Table("inntbl").Cell(0, 0).Table(0).Cell(7, 1).emailinputLid

Then we’ve reduced it down with Name Mapping and Aliasing to end up with..

Aliases.browser.SignInPage.EmailTextBox

It’s not difficult to see just how much easier it will be to write and read our tests with the Alias naming convention rather than the full System naming convetion.

Up next: Using the name map properties pane to identify the objects reliably.

NameMapping – Conditional Mode

October 7th, 2013 by admin

We’ve mentioned in previous posts about Name Mapping in our software test automation tool TestComplete. Whilst creating a Mapped name for an object we select a few properties which we use to identify that object. This is the ‘Basic Mode’ of Name Mapping. In some cases though, the value of the selected property may differ. Perhaps in a different environment the properties are different.

For example, a window may have different class name in different OS. Sometimes you may want to give the value of the property within some range or with some condition. For example, Childcount > 34, or Name should start with the string “save”. To create name mapping with these conditions we have to use the Conditional Mode of Name Mapping.

By default, while creating a Mapped name for an object, TestComplete opens the Object Name Mapping window in Basic mode.

ObjectNameMappingwindow

However, you can switch to conditional mode. You just need to click the Conditional Mode button at the bottom of the window. The conditional mode window will then look like this.

object-name-mapping

From this you can see that you can give combinations of properties with extended conditions.

Let us say there is a log-in window in a windows application. This window has a different class name in each OS as shown below.

OS
Class Name
windows 2003 windClass3
windows 2008 class8Wind
windows XP claswindXP
Windows Vista claswindvis
Windows 7 claswind7wind

So we might be working on XP and while creating the Mapped name for this window we select the following properties.

wndClass claswindXP
wndCaption New User

selected-properties-in-windows-xp

You may also use the following script to refer to this log-in window.

mapped-name-of-login-window

After developing the script for XP, if you try to execute the same code in Windows 7 it will not recognize the window object. TestComplete will log an error message “Object does not exist”. This is because in Windows 7 this window has the wndClass value as claswind7wind. This values is not equal to the value selected in Name Map. So by default our software test automation tool fails at this point of object identification.

To avoid this issue you could create multiple mapped names for this object on each OS. However, you would end up with a very long name map object tree. With conditional mode in NameMapping, you can simplify this and mention all the class names in a single mapped name (as shown below).

conditional-mode-of-NameMapping

If we provide the conditions above then name mapping will work in any OS. So, the above mentioned script will then work in all the operating systems. The following section explains how to name map for this login window in conditional mode.

Steps to Create NameMapping in conditional mode:

  1. Open the Object Name Mapping window of that object. Click on Conditional Mode button.
  2. ObjectNameMapping-1-1

  3. The Object Name Mapping window will be displayed in conditional mode as in the image below, with the selected properties.
  4. property-selected-inobjet-name-mapping

  5. Select the row of a particular property and click AND or OR button. (For above example select the row of wndClass and click OR)
  6. select-property

  7. TestComplete will show a new row as in the screenshot below.
  8. new-row-OR-condition-added

  9. In this new row, select the cell in the Property column and click on the ellipse button.
  10. select-this-cell

  11. Our software test automation tool will invoke the Edit Property window. Select a Property from the Type combo box and click OK button. (From the above example select wndClass property)
  12. edit-property

  13. Select a condition type in the Condition column. (From the above example, select Equals)
  14. select-condition

  15. Select the cell in the ‘Value’ column and click on the ellipse button.
  16. select-value

  17. This will invoke the Edit Value window. Select or enter the appropriate values in each field and click the OK button. (From the above example, use the values as in the image below)
  18. adding-value-to-each-field

  19. In this example, we have added two wndClass values with the OR condition. Now this name mapping will work in XP and Windows 7.
  20. two-values-added-for-wndClass

  21. In the same way you can add multiple values for wndClass with the OR condition.
  22. windows-class-for-each-os

Now in the above example, you can use the same code in all the operating systems. You will not need to make any changes to your code to manage the different operating systems. Our software test automation tool will recognize the window in all the OS using the single mapped name.

So the conditional mode reduces our effort and increases the testing productivity. We can make our script more adaptable. And since we no longer need to make any changes in the script, maintenance of our code becomes simpler.

TestComplete Project Test Items

October 7th, 2013 by admin

In Testcomplete the Test Items page within your project is used to organize, manage & execute the test cases that you’ve automated. For example we might have developed test automation scripts for thousands of test cases. However, each time we want to create a software test automation run we may want to execute only a selection of the testcases. We may also want to execute some multiple times with different test data. The Test Items feature allows us to perform all of these tasks simply.

  1. Organise Testcases
  2. Execute only selected Testcases.
  3. Execute a testcase multiple times
  4. Executing a testcase with different test data

A blank Test Items page will look like this:

TestItems

So lets work with this and consider the following software automation script.

automation-test-script

This TestComplete project has keyword and script routines. Let us say each keyword test represents a different testcase. Also each method in Unit1 is a testcase. As shown in the image the script routine ‘Test4’ requires two parameters (name and age) in order to be executed.

If we add every method & keyword test as a Test Item, we can easily execute the required test cases alone. You can see this in the image below.

run-the scripts

If we click the Run button this will execute only the selected Items. We can add any type of Test items (Script routines, Keyword Test, Load Test, Low level script unit etc) here in order to execute the items in the desired order. Also, if we need to we can pass parameters between the items we’re executing.

Before we look at passing parameters lets see how we can add a Test Item.

  1. Open the Test Items page of the Project. To do this,
    • Double Click on Project Folder in the Project Explorer panel.
    • double-click-project-folder

    • It will open the project Editor window. Click on the Test Items option which is available at the bottom.
    • tes-project-folder-select

  2. Click on ‘New Test Item’ button. It will add a New Test Item row.
  3. New-Test-Item

  4. In the Name column of the New Test Item row, enter a name for this Test Item.
  5. enter-name-test-item

  6. In the Test column, select the Test item to be executed. A Test item may be a script routine or keyword test etc. To select a Test item do the following steps.
    • Click on the ellipse button in Test column.
    • select-test-column

    • It will open Select Test window. Here select a Script routine or Key word test and click OK button. (Here we select the script routine Test4)
    • Select-new-Test

    • Now in the Test column it will show the selected Test item.
    • selected-test-routine-displayed

  7. In the Count column enter the number of times the Test item is to be executed.For example If we enter 3, this Test item will be executed 3 times. For now let us keep the value as 1.
  8. enter-number0of0itens-test-execution

  9. The Timeout column shows the maximum execution time allowed for that particular Test Item. If we set this value as 20, after 20 minutes if the execution of the test item is not finished, it stops executing this test item and moves to next Test item.
  10. set-time-out

  11. In the Parameters column, you can set the values for the parameter of that Test item.
    • If the Test Item has no parameter, the value will be displayed as [none]
    • Parameters

    • If the Test Item has any parameters, we should pass values for those parameters. To pass values do the following.
      • Click on the ellipse button in parameters column.
      • Test-Parameters-window

      • It will open Test Parameters window. This window will show the list of parameters available for that Test Item.
      • test-Parameters-window1

      • For each parameter select the value Type and Enter (or select) the Value. Then Click OK button.
      • select-type-and-value-in-test-parameter

  12. In the Description column, enter a description for this Test Item.
  13. enter-description-value

Now we have added a Test Item. The Check box in the Name Column is used to enable or disable the Test Item. If it is not checked, the Test Item will not be executed.

enable-disable-test-item

With this, we can add the Test items we need and organise our test execution. All this without having to modify any of our coded scripts or our keyword tests. This approach to structuring your automation delivers a level of flexibility that makes organising your testing far simpler.

Let us consider a recorded test automation script for a scenario in an application. In that script, we have the test data which we entered into our application while recording the test. If you execute the script, it will use exactly the same test data. However, this approach isn’t scalable and forces you to use the same test data every time your run the script. So ideally we should create test scenarios with a range of different test data.

If your application has a scenario, which needs to be tested with different test data, then you can go with data-driven framework for automated testing. A Data-Driven framework is an excellent test automation framework, which gives good test coverage with minimal scripting.

Common Steps involved in Data driven Testing:

  • Create your test with a set of test data.
  • Replace your test data with some variables.
  • Keep multiple sets of test data in data storage (Excel or csv etc.)
  • Now write the script to read the first test of test data from the data storage and assign those values to those variables. While executing, the script will use the test data which are read from the data storage.
  • Write a loop statement, to perform the above step for all the sets of test data in the data storage.

In Testcomplete, we have different options to create a data driven test. In testcomplete we can easily access the data from data stores like excel, csv, Data base tables etc. For accessing data from these data stores we can use the DDT driver object, DB table variables, and Table variables. Also, in a keyword test we can use the ‘Data Driven Loop wizard‘ to create data driven testing.

We’re going to see how to create a data driven test for a small script using DB table variables. We will use an excel sheet as our data store.

  1. Let us take the following script. This script is used to perform login action in a login window and then it verifies that the welcome message is displayed.
  2. DBtablevariables

  3. Here the user name & password values are the test data. In the above script these values are hard coded. But we want to test this script with different sets of username & password, which are stored in an excel sheet as below. So we have to parametrize these two values.
  4. DB-table-variables1

  5. To access values from the excel sheet, first we need to create a DB table variable. To create a DB table variable complete following steps.
    • Open the Project variables window.
    • Projectvariables

    • Right click on Temporary Variables window and select New Item option.
    • Temporary-variables

    • Now you can see a new Project variable row. In which enter a Variable name & select the Type as ‘DB Table‘. In our example, the variable name is given as ‘Login_Data‘.
    • Temporary-variables-Login-Data

  6. Now, Click on the ‘Default Value‘ cell and click on the Ellipsis button.
  7. Temporary-variables-LoginDefault-value

  8. It will open ‘Edit DB Table variable‘ window, in which select the Data source type as ‘Excel worksheet‘ and click ‘Next‘ button.
  9. EditDBTableVariable

  10. Now click on the Ellipsis button in the ‘File Name‘ Textbox and select the excel file in which the test data are stored. Then click Next button.
  11. EditDBTableVariableValue

  12. Now, select the work sheet name of excel workbook, in which the test data are stored. Also ensure that, the ‘Treat the first row as column names‘ checkbox is checked. Now, click Finish button.
  13. select-worksheet

  14. Now we have created a DB table variable for the excel sheet object. Now to access a value from a cell, we have to use the following code. By default the variable pointer will be in the first row of the excel sheet. So now the following code will return you the values in first row.

    Project.Variables.Login_Data.Value(”Login Name”)
    (Returns value in the “Login name” column of first row)
    Project.Variables.Login_Data.Value(”Password”)
    (Returns value in the “Password” column of first row

  15. Now, in the script, replace the hard coded values with these two variables.
  16. hard-coded-values

  17. The above script will enter login details, which are read from the first row of excel sheet. Now if you want to execute this for all the rows, you have to move the variable pointer to each row of excel sheet and execute the script.
  18. execute-the-script

If your excel sheet has 10 rows, this test will be executed for ten times.

The Full Name of an object, which is defined by TestComplete, can be difficult to work with. For example if you have a long object name with special characters, typing and reading it can be time consuming and prone to typing mistakes.

Let us say a textbox in a web page has the following name.

Sys.Process(”iexplore”, 2).Page(”https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2&from=login”).Table(1).Cell(0, 1).Panel(”login”).Form(”gaia_loginform”).Panel(”gaia_loginbox”).Table(0).Cell(0, 0).Panel(0).Table(”gaia_table”).Cell(2, 1).Textbox(”Email”)

This is not a simple bit of text to work with. To overcome this issue we can use the NameMapping feature. In the above mentioned object, from the text “Sys” to “Textbox(“Email”)” we can create a Mapped name for every object and use it in our scripts.

If you want to learn more about the basics of how name mapping work see our post on How the Name Mapping works in Test Complete.

After creating Name Mapping for every object, we can refer to the object as follows.

NameMapping.Sys.IEProcess.Page.MainForm.CellMain.LoginPanel.Loginform.Loginbox.Login
Table.LoginCell.LoginPanel.LoginTableObj.CellObj.EmailTextbox

It’s clear that this is easier to read. Even though it is easy to read, still the name is too long. It will be difficult to remember all the Mapped names & their hierarchy. So you end up getting the full mapped name of the object by using the object spy. As a result productivity goes down because you have to go through several steps to pick out the name.

To resolve this problem, we can use Alias names. From the above mentioned mapped name, we can remove a few objects and create a short name. For example the Aliases name of the above object can be given as follows.

Aliases.IEProcess.Page.EmailTextbox

This becomes very easy to read and write. Also we can easily memorize the names of required objects alone and type them in our scripts (without the help of the object spy). As a result productivity goes up.

In this example, we will see how to write an automation script for a log-in action in Gmail using the NameMapping & Aliases concepts.

  1. Open a new project in testcomplete. Add ‘NameMapping’ project item (If it is not available) using the following steps.
    1. In Project Explorer, Right click on Project Name folder and select Add –> New Item option
    2. NameMapping

    3. In “Create Project Item” window, Select ‘NameMapping’ option and click OK.
    4. CreateProjectItem

    5. Now in Project explorer it will show the “NameMapping” Item.
    6. NameMapping1

  2. In Internet Explorer, open the www.gmail.com page. Now we are going to create, Mapped names for the objects on which we are going to perform actions. Here we are going perform actions on Username Textbox, Password Textbox, and Login Button. So we will Map these objects.
  3. First we will Map the Username Textbox.
  4. UsernameTextbox

  5. Click on ‘Map Object From Screen’ button in tescomplete toolbar.
  6. MapObjectFromScreen’

  7. It will open Map Object window. Drag the Finder tool to the Username Textbox and release the mouse button. Now the “Object” textbox will show you the Full Name of the Username Textbox. Click OK button.
  8. MapObject

  9. Now it will ask you to Map all the Parent objects of Username Textbox before mapping it.
  10. Parentobjects

  11. Click Yes in that window. Now you have to Map all the objects in the displayed window and finally it will show the Username Textbox. First it will show you the IE process object in Object Mapping window. I.e. Sys.Process(“iexplore”,2)
    1. Give a Mapped name. It should be a readable and clear name.
    2. Select some required properties from Available Column list for unique identification of
      object (if needed) or remove some unwanted properties from selected column list (if needed)
      and Click OK button.
  12. uniqueidentification

  13. Now it will ask you to Map the next parent object of Username Textbox. As mentioned above in Step-7 Map all the Parent & Username Textbox objects.
  14. Once you have mapped all the Objects, double click on the ‘NameMapping” project Item. It will show the Name Mapping window. In this window you can see the Mapped Objects in a tree format. You will also see the Alias names which are created by default (in the same hierarchy as the Name Mapping).
  15. NameMapping4

  16. If you use this default Aliases name, it will come to the same length as Full Mapped name. To remove the names of some unwanted higher level objects, do the following.
  17. In Mapped Objects window, select the object on which you are going to perform actions. Drag that object from Mapped object window to Aliases window and drop under an object. Once you’ve done this the name will become very simple with just the important objects at the top level.
      (Here we are going to perform action on UsernameTextbox. So drag it and drop it under theObject ‘Page’ in Aliases window).
  18. drag-and-drop-page-opject

  19. Now you can refer to the Username Textbox as follows
  20. Alisases-IEProcess

  21. Now Map the Password Textbox and Login button in the same way and drag them under the Page object. Once this is done, you should have the Aliases name as follows.
  22. Aliases

    Alisases.IEProcess.Page.UserNameTextbox

  23. So now you can use the following code to perform the Login action.
    1. function LoginGmail()
      {
      var pageObj = Aliases.IEProcess.Page
      pageObj.UserNameTextbox.SetText(”myUsername”)
      pageObj.PasswordTextbox.SetText(”passwordTb”)
      pageObj.LoginButton.Click()
      }

      NameMappingsAliases

    2. If you record the same action, without creating these NameMappings & Aliases you will get the following script. It goes without saying that this is very difficult to read and understand.
    3. NameMappingsAliases1

    In summary you can create Mapped names and Aliases for any object. You can then use those names while writing scripts to make working with Test Complete far easier.

    Copyright ©2014 - Traq Software Ltd - All Rights Reserved.