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.
_takeSnapShot not working
Hi,
I need to take a snapshot of two pages and cannot seem to get _takeSnapShot (Sahi Pro) to work. Eg. if I have code...
_click(_link("Dashboard"));
_takeSnapShot();
My expectation is that Sahi will take a snap shot of my dashboard and display it in the log... but it does nothing. The log does not show an image nor does it list _takeSnapShot as being called. Bug? User err? Does it have arguments?
I'd also like to be able to assert the snap shots and from the demo I see:
_assertSnapShot("name.png", 20, true);
But I don't see the arguments documented anywhere, don't know what they do and it fails.
Anyone know how this _takeSnapShot works?
Thanks,
Brian
I need to take a snapshot of two pages and cannot seem to get _takeSnapShot (Sahi Pro) to work. Eg. if I have code...
_click(_link("Dashboard"));
_takeSnapShot();
My expectation is that Sahi will take a snap shot of my dashboard and display it in the log... but it does nothing. The log does not show an image nor does it list _takeSnapShot as being called. Bug? User err? Does it have arguments?
I'd also like to be able to assert the snap shots and from the demo I see:
_assertSnapShot("name.png", 20, true);
But I don't see the arguments documented anywhere, don't know what they do and it fails.
Anyone know how this _takeSnapShot works?
Thanks,
Brian
This discussion has been closed.
Comments
_set($dt, document.title);
_focusWindow($dt);
_takeScreenShot();
_takeSnapShot and _assertSnapShot are experimental. It needs some configuration to make it work.
As Sumeet mentions, use _takeScreenShot().
Sumeet, you need not do the _set.
Sahi automatically focuses on the window by changing the title and changing it back.
_focusWindow();
_takeScreenShot();
should be enough.
_focusWindow() seems to have a problem on IE, but _takeScreenShot() itself works correctly.
Hope that helps.
Regards,
Narayan
function TakeSnapShot($pathHTMLIma){
/*OAC - 2012-08-13
TakeSnapShot = Función toma imagen
Parametros:
$pathHTMLIma= Ruta donde se almacena la imagen
*/
try {
var formato = new java.text.SimpleDateFormat("yyyyMMdd-hh_mm_ss");
var robot = new java.awt.Robot();
var toolkit = new java.awt.Toolkit.getDefaultToolkit();
var screenSize = toolkit.getScreenSize();
var screenRect = new java.awt.Rectangle(0, 0, screenSize.width, screenSize.height);
var image = robot.createScreenCapture(screenRect);
var fecha = new Date();
var $fecha1 = formato.format(fecha);
var $ruta=$pathHTMLIma+"_"+$fecha1+".jpg"
var file = new java.io.File($ruta);
javax.imageio.ImageIO.write(image, "jpg", file);
return $ruta;
} catch (e) {
_logExceptionAsFailure(e);
}
}
good luck
Oscar C
_takeScreenShot() works great.
Brian