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.

_set not working

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

OS - WinXP SP3
Browser - IE8
Sahi version - 3.5

I want to assign a variable with return value of function call, but:

_set($DriveLetter_Global, GetSAHIRootDir());

is not working. The function GetSAHIRootDir() is returning "C" correctly. But if I print DriveLetter_Global, its showing "null". I tried changing the lines to:

_set($DriveLetter_Global, _call(GetSAHIRootDir()));

But this doesn't seems to work.
Can you please suggest any alternative?

Comments

  • Hi dust,

    Use $DriveLetter_Global in printing the value.
    If it still doesn't work, please also post your function GetSAHIRootDir.

    Cheers.
  • Hi

    did you try
    $DriveLetter_Global=GetSAHIRootDir();
    _alert($DriveLetter_Global);
    
  • dustdust Members
    lonely_girl01 and globalworming,

    I had tried, but not working. However now its working. I don't know waht could be the dependencies. I haven't changed anything.
  • dustdust Members
    Thanks anyway
  • dustdust Members
    Its not working again...

    I'm first checking whether sahi tool exist in the system
    I'm pasting the .sah file here(with output in comment):
    Due to _set() failing, IsSahi_tool_Exists() is being called with "null", and the code is exiting

    //****************************************************************************************************************
    // Checks the availability of the Sahi_tool package at the SystemRoot drive
    
    var $DriveLetter_Global = "";
    var $PackageExists = "";
    
    
    
    //_set($DriveLetter_Global, GetSAHIRootDir());  [b]//not working[/b]
    
    //_set($DriveLetter_Global, _call(GetSAHIRootDir()));  [b]//not working[/b]
    
    $DriveLetter_Global = GetSAHIRootDir(); // crashing with error (in logs) - ERROR ReferenceError: "GetSAHIRootDir" is not defined. at Apr 19, 2012 11:52:49 AM
    
    
    
    _alert("DriveLetter at line 59 : " + $DriveLetter_Global); [b]// printing "null"[/b]
    _set($PackageExists, _call(IsSahi_tool_Exists($DriveLetter_Global)));
    
    if(_condition($PackageExists != true))
    {
        $ErrorMsg = " ERROR : Sahi_tool package is not present at drive: " + $DriveLetter_Global + "... So Exiting ....\n";
        _debug($ErrorMsg + "\n        Please place the Sahi_tool package at Drive... \n" + $DriveLetter_Global);
        _alert("\n      Please place the Sahi_tool package appropriately at the Windows Drive (C/D/E/F/..)... \n"); [b] // printing [/b]
    
        _exit();
    }
    //****************************************************************************************************************
    //******************************************JAVASCRIPT API's*************************************************************************
    <browser>
    
    function GetSAHIRootDir()
    {
        //_alert("GetSAHIRootDir called\n"); // OK
        var DirLet = null;
        var wshshell = new ActiveXObject("WScript.Shell");
        var winPath = wshshell.ExpandEnvironmentStrings("%SystemDrive%");
        //var winPath = wshshell.ExpandEnvironmentStrings("%SAHI_TOOL%");
        if(wshshell == null) 
        {
            _alert("Function GetSAHIRootDir:wshshell is NULL");
        }
        else
        {
            _alert("Function GetSAHIRootDir:wshshell is NOT NULL"); [b]// OK[/b]
        }
        
        if(winPath != null) {
            DirLet = winPath.substring(0, winPath.indexOf(":"));
            _alert("[GetSAHIRootDir]:DirLet = " + DirLet); [b]// prnting - "C"[/b]
        }
    
        return DirLet;
    }
    
    function IsSahi_tool_Exists(DriveName)
    {
        _alert("[IsSahi_tool_Exists]:DriveName = " + DriveName);  [b]// printing - "null"[/b]
        var folderBool = false;
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        if(DriveName != null) {
            folderBool = fso.FolderExists(DriveName + ":\\Sahi_tool\\sahi");
            if(folderBool == true)
            {
                folderBool = fso.FolderExists(DriveName + ":\\Sahi_tool\\sahi\\bin");
            }
        }
        _alert("[IsSahi_tool_Exists] return : " + folderBool);  [b]// printing - "false"[/b]
        return folderBool;
    }
    
    </browser>
    
    //***********************************************************************************************************************************
    

    Please help me find what could be problem.
  • Hi dust,

    I think you should put GetSAHIRootDir() in _call(),
    _call(GetSAHIRootDir());
    
    since the function is inside the <browser> tag just like what you did in IsSahi_tool_Exists() when you called it,
    _set($PackageExists, _call(IsSahi_tool_Exists($DriveLetter_Global)));
    
    .
  • dustdust Members
    Hi lonely_girl01,

    Its not working...
Sign In or Register to comment.