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.

Calling functions from an Excel sheet

JaoBrJaoBr Members
edited March 2010 in Sahi - Open Source
Hi guys.

I have a little question here:

I have an Excel sheet, with two columns:

id function
1 login
2 new item
3 save
4 exit

I've written my Sahi Script to load this sheet and with a LOT OF 'if', to call the function that the Excel sheet told to Sahi.

Example:
var $rs = db.select("select * from [sistema$]");
for(var $i = 0; $i < $rs.length; $i++){
        if($rs[$i]["function"] == "login"){
            login();
        }
        else if($rs[$i]["function"] == "new item"){
            newItem();
        }
        else if($rs[$i]["function"] == "save"){
            save();
        }
        else if($rs[$i]["function"] == "exit"){
            exit();
        }
}

As you can see, Sahi will execute the function in the order that I put it in the Excel sheet, even if in the wrong way. If I write in the Excel sheet only:

id function
1 login
2 exit

Sahi will only login in the system and exit it.

The question that I have is, is there anyway to make Sahi to execute the functions that I put in the Excel sheet without using 'if ~ else if' or 'switch case'?

Comments

  • narayannarayan Administrators
    Hi JaoBr,

    Have a look at javascript eval.

    Here is an example:
    function getFunctionName($s){
      // removing all spaces. you can make it better to return 
      // "newItem" if input is "new item". 
      return $s.replace(/ /g, '');
    }
    
    
    var $rs = db.select("select * from [sistema$]");
    for(var $i = 0; $i < $rs.length; $i++){
      var $fnName = getFunctionName($rs[$i]["function"]);
      eval($fnName+ "()");
    }
    

    Hope that helps.

    Regards,
    Narayan
  • JaoBrJaoBr Members
    Works perfectly, thanks!!!
This discussion has been closed.