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.

Operating system detection

zawistolzawistol Members
edited November -1 in Sahi - Open Source
Hi,
I have added 2 sahi functions to concat.js and normal_functions.txt
Sahi.prototype._isLinux = function () {return /Linux/.test(navigator.userAgent);};
Sahi.prototype._isWindows = function () {return /Windows/.test(navigator.userAgent);};
When I run them, they both return true.
My User Agent variable is following
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6
What am I doing wrong ??
Lech

(I am on sahi 2010_03_21, FF 3.6 and Windows 7,
I have tested user agent with following
http://www.docsteve.com/DocSteve/Samples/JS/javascript_env.html)

Comments

  • Hi zawistol,

    Please use this:
    Sahi.prototype._isLinux = function () {return /Linux/.test(this.navigator.userAgent);};
    Sahi.prototype._isWindows = function () {return /Windows/.test(this.navigator.userAgent);};
    

    Also, I would recommend that you use the latest version of Sahi. (Build:2011-07-19).

    Regards
    Sumitra
  • Sumitra,
    I have tried 2011-07-19 and adding "this.", but still the same result.
    There must be some ADDITIONAL MAGIC to be done when adding a new function.
    The additional line is generated for isIE (which is not generated for my functions)
    _sahi.setServerVar('___lastValue___1325675607155', _isIE()); at Jan 4, 2012 12:13:27
    What do I need to add to make functions work exactly as isIE() ?
    _log("User Agent" + _userAgent(),"custom");
    if (_isWindows()){    
        _log("win","custom");
    }
    if (_isLinux()){    
        _log("Linux","custom");
    }
    if (_isIE()){    
        _log("IE","custom");
    }
    

    Please see the result
    Starting script
    User AgentMozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 at Jan 4, 2012 12:13:26 PM
    _log("User Agent" + _userAgent(),"custom"); at Jan 4, 2012 12:13:26 PM
    win at Jan 4, 2012 12:13:26 PM
    _log("win","custom"); at Jan 4, 2012 12:13:26 PM
    Linux at Jan 4, 2012 12:13:27 PM
    _log("Linux","custom"); at Jan 4, 2012 12:13:27 PM
    _sahi.setServerVar('___lastValue___1325675607155', _isIE()); at Jan 4, 2012 12:13:27 
    
  • Hi zawistol,

    Could you try using:
    if (_condition(_isWindows())){    
        _log("win","custom");
    }
    if (_condition(_isLinux())){    
        _log("Linux","custom");
    }
    

    Regards
    Sumitra
  • Big heavens!
    It works for sahi_20110719 !!
    Is there a way Sumitra I can invite you for a beer (cola) ? :)
    Lech
Sign In or Register to comment.