18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Validating list order solution, bug (?)

KeithMKeithM Members
edited November -1 in Sahi - Open Source
Hello. I've been using Sahi (build 2011-07-19 on Windows 7 with IE 8) for a few months now and it's been great, but I've gotten stuck on this one particular area until now (maybe).

We have several popup menus that we want to validate the visibility and order of. After searching the forums and a lot of mix and matching of the APIs, I think I've got a solution.

For this menu of links...

Item 1
Item 2
Item 3
Item 4

...I have this code...

_assertNotTrue(_isVisible(_listItem("Item 1", _under(_listItem("/.*/")))));
_assertEqual("Item 2", _getText(_listItem(0, _under(_listItem("Item 1")))));
_assertEqual("Item 3", _getText(_listItem(0, _under(_listItem("Item 2")))));
_assertEqual("Item 4", _getText(_listItem(0, _under(_listItem("Item 3")))));
_assertNotTrue(_isVisible(_listItem("/.*/", _under(_listItem("Item 4")))));

I'm assuming that the validation of the visibility is implied. In other words, if Item 3 was not there or renamed, the script would fail. Similarly, if a new/unexpected item appeared between Item 2 and Item 3, the 3rd line above would fail.

I used the 0 to identify/assert that one item appears after the other which seems to give me order validation.

To validate that there are no other items after Item 4, I've used the /.*/ wildcard and it breaks as expected if there's another item under it. However, I'm not getting the expected result for the wildcard in the first line (bug or my mistake?) which is trying to validate that Item 1 is not preceded by any other items.

If you see any holes in this logic, or have found a better way to handle non-table sort/order, please reply.

Thanks

Comments

  • Hi KeithM,

    Here is a better way which you could use:
    <browser>
    function listElements() {
       var $items= new Array();
       $items = _list(0).children;
       var $textElements = new Array();
       for(var $i=0; $i<$items.length; $i++){
           $textElements[$i] = _getText($items[$i]);
       }
    return $textElements;
    }
    </browser>
    var $expected = new Array("Item 1","Item 2", "Item 3", "Item 4");
    _set($elements, listElements());
    _assertEqual($expected, $elements);
    

    Regards
    Sumitra
  • Thanks Sumitra. Your solution would work except that with the way these pages/menus on our website are coded, Sahi sees the array as having 35 items (all possible menu items) instead of the 4 visible ones in my example. I tried using _setStrictVisibilityCheck around your code, but that didn't help.

    Is there any logical reason that

    _assertNotTrue(_isVisible(_listItem("Item 1", _under(_listItem("/.*/")))));

    doesn't work for the first item, but seems to work for the last item?
  • Hi KeithM,
    In your case, _assertNotTrue() just checks if Item1 is under ANY listitem and if item1 is visible it will return true. Instead you should just verify if the element above item1 is not visible.

    I have modified my earlier code:
    The HTML code for the list items is:
    <ul>
    <li style="display:none">Item 0</li>
    <li>Item 1</li>
    <li>Item 2</li>
    <li style="display:none">Item 2.5</li>
    <li>Item 3</li>
    <li>Item 4</li>
    <li style="display:none">Item 5</li>
    </ul>
    

    The script for this would be:
    <browser>
    function listElements() {
       var $items= new Array();
       $items = _list(0).children;
       var $textElements = new Array();
       for(var $i=0; $i<$items.length; $i++){
      if(_isVisible($items[$i]))
           $textElements.push(_getText($items[$i]));
       }
    return $textElements;
    }
    </browser>
    
    

    Regards
    Sumitra
  • Unfortunately, modifying the HTML with a 'ghost' Item 0 to make some automation script work isn't an option in my environment. Thanks again for the help, though. Maybe an _over API could be considered in the future?
Sign In or Register to comment.