Product Update
May 9, 2010

Sahi API _under added

Continuing with our tradition of innovation for simplicity, Tyto adds another wonderful API to Sahi.

NOTE: _under will be available in Sahi's next release

The problem:

Let us take the example of a dynamically generated grid. The example we use here is available at http://www.zkoss.org/zkdemo/userguide/#g7

We wish to assert the value of "Received" column for "Style Guide for ZK 3.5 released". If we bring up the controller and CTRL-hover over that element, what we see is

_div("2008/11/14 13:23:07")
which is not useful as a finder.

Looking at the alternatives listed, we notice that none of them can really help.

To fix this, we shall try using _near.

1) We put

_div(0, _near(_div("Style Guide for ZK 3.5 released")))

into the Evaluate Expression box, and click Highlight. This highlights the "Style Guide" element itself.

2) We experiment with the index passed as the first parameter and using Highlight, pinpoint on the correct accessor as_div(4, _near(_div("Style Guide for ZK 3.5 released")))

But this will not make a good accessor.
Why?
Because this uses an index which seems like it would change when another column is added before the Received column.

What we really want, is that element, which is UNDER _div("Received").

Introducing the _under API _under(element):

_under is a POSITIONAL marker. What it means is that it checks for coordinate based alignment under a particular element within a specific threshold.
So, in our case, it will look for a div which is roughly positioned underneath _div("Received")
Here is the final accessor:

_div(0, _near(_div("Style Guide for ZK 3.5 released")), _under(_div("Received")))

Note how this accessor is independent of the order of the rows and the columns.

And then the testers lived happily ever after...

Notes:
This grid is not a simple table but actually composed of 2 tables, one for the header and one for the contents. So we could have approached this problem using _cell(_table(2), "Style Guide for ZK 3.5 released", 4), but again the 4 would trip us later if the order/number of columns changes.
_under(el) can be passed as the last parameter to any Sahi API.
NOTE: _under will be available in Sahi's next release

Continue reading