ATS : UI elements definition

Introduction

In order to find a UI element, we need to know some identification properties like ID, name, value etc.

The UI Engine supports two ways of providing these properties - using a map file or directly specifying the list of properties in the test code.

 


Using a map file

Here is an example of a so called map file:

<Map>
     <Section name="login">
          <Element mapID="userNameTB" type="Textbox" id="_a_user_name_"/>
          <Element mapID="userPasswordTB" type="Textbox" name="password"/>
          <Element mapID="loginB" type="Button" name="a_login_btn_name" value="Log in"/>
     </Section>
</Map>

We recommend to use some common naming convention for your map IDs.

For example userPasswordTB is a Text Box, while loginB is a Button etc.

 

And here is how you can use it in your tests:

engine.loadMapFile( "MyUiComponents.map", "login" );

engine.getTextBox( "userNameTB" ).setValue( "admin" );
engine.getTextBox( "userPasswordTB" ).setValue( "admin" );
engine.getButton( "loginB" ).click();

So basically you use a map file to describe the elements you will use in your tests. You put all the needed attributes and then refer to your elements in the test by its mapId only.

The benefits of using a map file are:

  • cleaner tests as each element is identified by its mapId only
  • central storage for all UI elements involved in the tests
  • more intuitive names are used for identifying an element. For example the developer may specify an id for a login button called "_this_is_some_gadget_doing_something", but you can still use "loginB" as identifier in your tests
  • changes in the application affect only the map file, once it is fixed the tests works again
  • multiple map files and multiple map sections are supported. Imagine you have 10 menus on your web application and you can have 10 map sections for each menu, thus you can use same mapIds for elements from different web pages

 


Using a list of properties in the java code

If you insist to not use a map file for some reason, you can directly provide the UI element properties using Java only:

// provide "id" of a button
UiElementProperties loginButtonProperties = new UiElementProperties().addProperty( "id", "a_login_btn_id" );
// or provide "name" and "value" of a button
UiElementProperties loginButtonProperties = new UiElementProperties().addProperty( "name", "a_login_btn_name" ).addProperty( "value", "Log in" );

// now construct the button and click it
engine.getButton( loginButtonProperties ).click();

Of course you can mix the usage of map files and java properties.

Maybe most of your UI elements will be defined in a map file and will be used multiple times in your test code. But few of UI elements will be defined in the java only because you use them just once.

 


Back to parent page

Go to Table of Contents