Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

how to change screenshot folder but keep the default file name?

Does anyone know how to keep the default file name for a screenshot while still using the $fileSysPath variable used here (for a different folder):
http://sahipro.com/docs/sahi-apis/screenshot-apis.html#_takePageScreenShot

Comments

  • edited September 2016 Members
    A solution:
    create a timestamp function.

    function _getTimeStamp(){
    //format: 2016-01-01_05.15.59MDT_myScript_chrome.png
    var $date = new Date().toISOString(); //standard ISO format: 2016-09-12T11:21:22.326Z
    var $time = new Date().toString(); //standard format: Mon Sep 1 2015 05:33:53 GMT-0600 (MDT)
    $date = $date.replace(/(.*)T.*/,'$1'); //get the date: 2016-09-12
    $time = $time.replace(/.*(........ GMT.*)/,'$1'); //get the timestamp: 05:44:58 GMT-0600 (MDT)
    $time = $time.replace(/(.*) GMT.*[(](.*)/,'$1'+'$2'); //remove " GMT-0600 ("
    $time = $time.replace(")",""); //remove the ")"
    $time = $time.replace(/:/g,"."); //make it suitable for a file name, replacing : with .
    var $filename= _scriptName(); //ex. myScript.sah
    $filename = $filename.substring(0,$filename.lastIndexOf(".")); //remove file extension
    var $browserName =_detectBrowser();
    var $timeStamp = [$date,$time,$filename,$browserName].join("_");
    return $timeStamp;
    }

    function _detectBrowser(){
    _set($userAgent, _userAgent());
    var $browserName =
    ($userAgent.match("Firefox")) ? "firefox" :
    ($userAgent.match("OPR")) ? "opera" :
    ($userAgent.match("Chrome")) ? "chrome" :
    ($userAgent.match("Safari")) ? "safari" :
    ($userAgent.match("Trident")) ? "IE" :
    "browser-unknown" ;
    return $browserName;
    //if version is needed: http://stackoverflow.com/questions/5916900/how-can-you-detect-the-version-of-a-browser
    }
Sign In or Register to comment.