Ing. Andrés Canavesi | Blog

CAT | Gwt

Selenium is a powerful and popular tool which can be used to test your SmartClient applications.
Selenium executes tests against your running application in a browser emulating user interaction and asserting various conditions.
Selenium provides a record/playback tool for authoring tests without learning a test scripting language. You must be familiar with
Selenium and use of Selenium IDE before proceeding. Refer to the documentation on the Selenium

site.

Use of Selenium with SmartClient applications is no different than using Selenium to write and run test cases with any other application with
the exception on on caveat. Selenium supports the concept of Locators
in order to specify the element you’d like a given Selenium command to operate on. For example Selenium supports XPath based locators, and DOM ID based locators.
XPath based locators are extremely fragile due to complexity of certain highly nested DOM elements you need access to combined with the fact that
XPath support varies across browsers and so your tests might not work across different browsers.

SmartClient occasionally renders a different DOM structure depending on the browser for performance for rendering the UI such that it appears identical across various browsers.
As a result using DOM ID or DOM XPath based locators with SmartClient applications is not advisable. Instead SmartClient supports a new Selenium
locator which is an xpath-like string used by Selenium to robustly identify DOM elements within a SmartClient application. SmartClient locators for Selenium
are prefixed by “scLocator=” and have a readable XPath like value even for cells in ListGrid’s or TreeGrids. Typically these locators will not be hand-written and
are generated by Selenium IDE, Selenium’s test recording tool.
One primary locator is based on the ID of the SmartClient widget and has the syntax ID=<Canvas ID>. This
simplifies the task of writing tests if you know the ID of the Canvas. For reference, the scLocator syntax for
ListGrid cells and DynamicForm FormItem"s can be found at the end of this document.

Setup Instructions

  • SmartClient ships with a Selenium user extension Javascript file : user-extensions.js. When running the Selenium tests make sure you place this file at the appropriate location.
    Refer to the Selenium Documentation for mode details.
  • In order to create tests, we suggest you use Selenium IDE. By default, Selenium looks for a file called “user-extensions.js”, and loads the javascript code found in that file.
    In the standard Selenium distribution, this file does not exist. You should place this file in this common location.
    Refer to the Selenium documentation if you need additional information. Once you have
    Selenium IDE installed, you will need to use the SmartClient user-extensions.js file with Selenium IDE. This is installed by
    putting the pathname to its location on your computer in the Selenium Core extensions field of Selenium-IDEÕs Options=>Options=>General tab.
    Additional Details on how this can be setup can be found here.
  • You will also need to configure Selenium IDE with a SmartClient provided Selenium IDE extensions javascript file : user-extensions-ide.js This is installed by
    putting the pathname to its location on your computer in the Selenium IDE extensions field of Selenium-IDEÕs Options=>Options=>General tab.

That’s it, we’re done configuring the environment.

Recording Selenium tests with Selenium IDE

Once you have your application running in Firefox, open Selenium IDE from the Tools ==> Selenium IDE menu option. If the Selenium IDE is in record mode,
then clicking or carrying out other operations like typing in a text field with automatically record the appropriate Selenium commands with the SmartClient locator.
There’s no need for you to manually enter the locator, the recorder does this for you! Sometimes users many want finder grain control of what Selenium command
is created instead of having the Selenium IDE recorder do this automatically. For example if you want to verify the value of a particular cell in a ListGrid.
Instead on typing in the command “verifyTable” and manually enter the SmartClient Locator (scLocator), you can simply right click on the table cell or any other
SmartClient widget and the most suitable Selenium commands will appear in the context menu along with the scLocator path for the clicked element. See image below.


Common scLocator syntax

List Grid cells

//ListGrid[ID="itemList"]/body/row[itemID=1996||itemName=Sugar White 1KG||SKU=85201400||1]/col[fieldName=SKU||1]

  • This assumes the ListGrid has an explicit ID
  • the ‘body’ part might be ‘frozenBody’ if the field in question was frozen
  • row[......] identifies the row (record)
  • itemID= – that’s the primary key field from the dataSource the grid is bound to
  • itemName= – that’s the title field value for the record
  • SKU=… – that’s the cell the user clicked’s value
  • 1 – that’s the index of the row (rowNum)
  • col[.....] – identifies the column in the grid
  • fieldName=… – field name for the field the user clicked
  • 1 – that’s the index of the column

Form Items

//DynamicForm[ID="autoTestForm"]/item[name=textField||title=textField||value=test||index=0||Class=TextItem]/element

This example is the data element (text entry box) for a text field

  • this form has an explicit ID
  • item[...] identifies the item
  • name (field name, if set)
  • title (title, if set)
  • value (current value if set)
  • index (index in the form items array)
  • Class (SC class of the item – in this case TextItem) after the “/” we identify the part of the item in question options here include:
  • “element” – the data element
  • “canvas” – for CanvasItems – points to the canvas embedded in the item
  • in this case the xpath might continue to contain, for example children of the canvas or elements within it (cells in a listGrid, etc)
  • “textbox” – the “text box” – this is the area where content is written out for items without a ‘data element’ – like header items
  • “[icon=<...>]” – the icon element — “<...>” would contain the “name”
    of the icon


Known Limitations

  • Support for multi-select for SelectItems with selection mode “grid” (non-default)
  • Support for Drag & Drop due to limitations in Selenium

, , , , Hide


Find it!

Theme Design by devolux.org