18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
Hash Table not working in Sahi
Hi,
I have a Class to have a Hash table as mentioned below in Hash.js. I included this library to my sahi script using _include("Hash.js"). But while calling the methods from the class getting the error in logs like Type Error Function not found in Object.
Tried accessing the code like
var $hash = new HashTable();
$hash.setItems($key,$value); // error at this line of code. Any help will be appreciated.
function HashTable($obj)
{
this.length = 0;
this.items = {};
for (var $p in $obj) {
if ($obj.hasOwnProperty($p)) {
this.items[$p] = obj[$p];
this.length++;
}
}
this.setItem = function ($key,$value) {
_alert("in");
var $previous = "undefined";
if (this.hasItem($key)) {
$previous = this.items[$key];
}
else {
this.length++;
}
this.items[$key] = $value;
return $previous;
};
this.getItem = function($key) {
return this.hasItem($key) ? this.items[$key] : "undefined";
}
this.hasItem = function($key)
{
return this.items.hasOwnProperty($key);
}
this.removeItem = function($key)
{
if (this.hasItem($key)) {
$previous = this.items[$key];
this.length--;
delete this.items[$key];
return $previous;
}
else {
return "undefined";
}
}
this.keys = function()
{
var $keys = [];
for (var $k in this.items) {
if (this.hasItem($k)) {
$keys.push($k);
}
}
return $keys;
}
this.values = function()
{
var $values = [];
for (var $k in this.items) {
if (this.hasItem($k)) {
$values.push(this.items[$k]);
}
}
return $values;
}
this.each = function(fn) {
for (var $k in this.items) {
if (this.hasItem($k)) {
fn($k, this.items[$k]);
}
}
}
this.clear = function()
{
this.items = {}
this.length = 0;
}
}
I have a Class to have a Hash table as mentioned below in Hash.js. I included this library to my sahi script using _include("Hash.js"). But while calling the methods from the class getting the error in logs like Type Error Function not found in Object.
Tried accessing the code like
var $hash = new HashTable();
$hash.setItems($key,$value); // error at this line of code. Any help will be appreciated.
function HashTable($obj)
{
this.length = 0;
this.items = {};
for (var $p in $obj) {
if ($obj.hasOwnProperty($p)) {
this.items[$p] = obj[$p];
this.length++;
}
}
this.setItem = function ($key,$value) {
_alert("in");
var $previous = "undefined";
if (this.hasItem($key)) {
$previous = this.items[$key];
}
else {
this.length++;
}
this.items[$key] = $value;
return $previous;
};
this.getItem = function($key) {
return this.hasItem($key) ? this.items[$key] : "undefined";
}
this.hasItem = function($key)
{
return this.items.hasOwnProperty($key);
}
this.removeItem = function($key)
{
if (this.hasItem($key)) {
$previous = this.items[$key];
this.length--;
delete this.items[$key];
return $previous;
}
else {
return "undefined";
}
}
this.keys = function()
{
var $keys = [];
for (var $k in this.items) {
if (this.hasItem($k)) {
$keys.push($k);
}
}
return $keys;
}
this.values = function()
{
var $values = [];
for (var $k in this.items) {
if (this.hasItem($k)) {
$values.push(this.items[$k]);
}
}
return $values;
}
this.each = function(fn) {
for (var $k in this.items) {
if (this.hasItem($k)) {
fn($k, this.items[$k]);
}
}
}
this.clear = function()
{
this.items = {}
this.length = 0;
}
}
Answers
var Hash = function(){
this.length = 0;
this.items = new Array();
this.getItem = function(in_key) {
return this.items[in_key];
}
this.setItem = function(in_key, in_value)
{
if (typeof(in_value) != 'undefined') {
if (typeof(this.items[in_key]) == 'undefined') {
this.length++;
}
this.items[in_key] = in_value;
}
return in_value;
}
this.hasItem = function(in_key)
{
return typeof(this.items[in_key]) != 'undefined';
}
}
and the hash can be created by
var $myHash = new Hash();
$myHash.setItem("One",1);
worked perfectly.