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.

good practices to test soring features

mmirskimmirski Members
edited November -1 in Sahi - Open Source
Hi,

I am trying to find some good way to test sorting features of data grid (table html element).

Do you have any recommendations where to start?

For the beginning I was thinking about comparing 2 first elements from every column but how does it work with strings?

Thanks,

Maciej

Comments

  • narayannarayan Administrators
    You can just assert string1<string2 in javascript.

    Type the following in the Expression Evaluator in the Sahi controller, and verify behavior:
    _assert("a"<"b");
    _assert("b"<"a");
    _assert("axyz"<"b");
    
    -Narayan
  • Narayan,

    Have you think about adding some wrapper layer over Sahi functions, like e.g. one function for verifying sorting in whole table.

    That would be kind of framework closer to actual needs, and faster for implementation.

    I started thinking about starting some work on such.

    One thing is that I have big system to script and not too much time.

    Another reason for that - I have thesis to write for my studies and this sounds like good project :)
  • narayannarayan Administrators
    Maciej,

    Do let us know what functions you think will make Sahi better. Happy for any input!
    Feel free to add useful functions to Sahi and share it on the forum.


    To get you started on the path, here is how I would proceed on your sorting example.

    Approach 1:
    <browser>
    isColumnSorted = function(tableEl, columnNo, isSortAsc){
       var rows = tableEl.rows;
       for (var i=0; i<rows.length-1; i++){
          if (isSortAsc && rows[i].cells[columnNo] > rows[i+1].cells[columnNo]) return false;
          if (!isSortAsc && rows[i].cells[columnNo] < rows[i+1].cells[columnNo]) return false;
       }
       return true;
    }
    </browser>
    
    _assert(isColumnSorted(_table("id"), 2, true));
    
    Approach 2:
    If I wanted to make _isColumnSorted a standard Sahi function, I would define the function as
    Sahi.prototype._isColumnSorted = function(tableEl, columnNo, isSortAsc){
       ...
    }
    
    in sahi/htdocs/spr/concat.js
    and add _isColumnSorted in sahi/config/normal_functions.txt
    If I do the above, I can do the same assert as
    _assert(_isColumnSorted(_table("id"), 2, true));
    
    Approach 3:
    If I wanted to add an _assertColumnSorted, then I can add to approach 2, and define another function
    Sahi.prototype._assertColumnSorted = function(tableEl, columnNo, isSortAsc))){
          if (!this. _isColumnSorted(tableEl, columnNo, isSortAsc)) throw new SahiAssertionException(10, "Column not sorted");
          return true;
    }
    
    and add _assertColumnSorted to sahi/config/scheduler_functions.txt

    It is 1:30 in the night now and this may have mistakes. I will have a look again in the morning.

    -Narayan
Sign In or Register to comment.