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.

peculiar issue with certain function names

hari19hari19 Members
edited November -1 in Sahi - Open Source
I have the following piece of code which I _include in my test scripts :
// Variables
var $testsuite_properties;

// Function Definition
function read_properties_file($file)
{
    var $props = new java.util.Properties();
    var $f = new java.io.File(get_base_dir(),$file);
    $props.load(new java.io.FileInputStream($f));
    return $props
}

The result html reports the following error when I run a script with this code:
Starting script
JSERROR missing ( before function parameters. at Jul 29, 2009 6:22:40 PM
Stopping script

The link is to line 32 from sahi.log snippet pasted below is
function read_properties_sahi._file($file)

I looked at sahi.log and saw that this had been changed to
// Variables
var $testsuite_properties;
// Function Definition
function read_properties_sahi._file($file)
{
var $props = new java.util.Properties();
var $f = new java.io.File(get_base_dir(),$file);
$props.load(new java.io.FileInputStream($f));
return $props
}

I tried changing the function name as follows :
// Variables
var $testsuite_properties;

// Function Definition
function read_propertiesFile($file)
{
    var $props = new java.util.Properties();
    var $f = new java.io.File(get_base_dir(),$file);
    $props.load(new java.io.FileInputStream($f));
    return $props
}


the script runs fine and I see the following in sahi.log
// Variables
var $testsuite_properties;
// Function Definition
function read_propertiesFile($file)
{
var $props = new java.util.Properties();
var $f = new java.io.File(get_base_dir(),$file);
$props.load(new java.io.FileInputStream($f));
return $props
}

Please note the following :

With original function name : function read_properties_file($file) => function read_properties_sahi._file($file)
With changed function name : function read_propertiesFile($file) => function read_propertiesFile($file)

From looking at sahi.log I can see that when Sahi runs a test script it does some sort of pre-processing and creates one script whose contents are the actual test script and all included files. The sahi.log snippets pasted above are from the complete script which is logged in sahi.log. Looks in certain conditions ( I don't know which or why since other functions are not affected) the pre-processing introduces these errors.

Comments

  • narayannarayan Administrators
    Hari, you are right, and thanks for pointing it out.
    _file is one of Sahi's accessor functions and Sahi modifies it to _sahi._file.
    There needs to be a check to see if it is part of another word.

    Thanks,
    Narayan
  • nickleusnickleus Members
    edited March 2013
    is there a list of function name restrictions somewhere i can look at?

    so far i've noticed that function names can't end in:
    _password
    _list
    _file

    any more than these?

    UPDATE: is this the list?
    sahi/config/normal_functions.txt
Sign In or Register to comment.