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.
taking snapshots of browser windows
Hi,
i wanted to share what i just set up.
There's another thread about how to get browser windows to execute in the foreground.
Gerhard
i wanted to share what i just set up.
function takeShapshot() {
var $scriptPath = ('' + ScriptRunner.getScript().getFilePath());
if ($scriptPath.search(/\\/)) { // Windows
var $arrScriptPath = $scriptPath.split(/\\/);
} else {
var $arrScriptPath = $scriptPath.split(/\//);
}
var $testScript = $arrScriptPath.pop().replace(/\.sah/,'');
var $now = new Date();
var $snapfile = $testScript + '_' +
$now.getFullYear() + '_' +
String("0" + $now.getMonth() + 1).slice(-2) + '_' +
String("0" + $now.getDay()).slice(-2) + '__' +
String("0" + $now.getHours()).slice(-2) + '_' +
String("0" + $now.getMinutes()).slice(-2) + '_' +
String("0" + $now.getSeconds()).slice(-2) + '.jpg';
// this gives you a filename like <scriptname>_2009_04_09__14_59_12.jpg
// the date/time would ideally be the same as the protocol file
// first i wanted to use this:
//var $snapfilefile = _callServer("net.sf.sahi.util.Utils.createLogFileName") + '.jpg';
// but i didn't manage it to work
_execute('\"C:/Program Files/IrfanView/i_view32.exe\" /capture=2 ' + '/convert=C:\\\\Users\\nagios\\\\sahi\\\\snapshots\\\\' + $snapfile);
}
You need the excellent image processing tool from www.irfanview.com for this. Now when you call snapshot() in your tests, you'll find a picture of the failed page in your snapshots/ directory.There's another thread about how to get browser windows to execute in the foreground.
Gerhard
Comments
Regards,
Narayan
Gerhard
Also, is it possible that this code would work even if:
1. The browser window is minimized
2. There are multiple instances of the browser open.
Would it capture the exact screen where the error was caused.
Thanks,
Ajay
Have a look at : http://sahi.co.in/forums/viewtopic.php?id=1200
Also, there is a API called
_takeSnapShot(); and
_takeSnapShots(toggle); which will take snapshot and show it on the log reports.This is available only in Sahi Pro version.
Regards
Sumitra
import java.io.IOException;
import net.sf.sahi.test.TestRunner;
public class SahiScriptLauncher {
public static void main(String[] args) throws IOException, InterruptedException {
// TODO Auto-generated method stub
final String suiteName = "path_to / abcd.sah"; //consider here a path to file
final String browserType = "chrome";
String base = "url"; //consider an actual url here
String threads = "1";
TestRunner testRunner = new TestRunner(suiteName, browserType, base, threads);
String status = testRunner.execute();
}
}