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.

_takeScreenShot() works great, except that it only works on single screen setup...

OrrinOrrin Members
edited May 2013 in Sahi Pro
I use dual monitors and all the tests automatically execute on the secondary screen (as I want it to), but _takeScreenShot() hits the primary screen. Is there a way to handle this?

Best Answer

  • Answer ✓
    I'm using Sahi Open Source, so I don 't believe _takeScreenShot() is available to me. I use a Java function instead. This takes a screenshot of BOTH monitors.

    //


    function takeErrorSnapShotDualRight(){

    var $fileName = "R_Error_";
    var robot = new java.awt.Robot();
    var toolkit = new java.awt.Toolkit.getDefaultToolkit();
    var screenSize = toolkit.getScreenSize();
    var screenRect = new java.awt.Rectangle(1919, 0, screenSize.width / 2, screenSize.height);
    var image = robot.createScreenCapture(screenRect);
    d = new Date();
    var tm = d.toString('HH:mm:ss');
    printAnyThroughJava("The Time is "+tm);
    ctr++;
    var file = new java.io.File($screenShotPath +$funcName +$fileName +"Screenshot_" + tm + "_" + ctr + ".png");
    javax.imageio.ImageIO.write(image, "png", file);
    }

    //

    function takeErrorSnapShotDualLeft(){

    var $fileName = "L_Error_";
    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 / 2, screenSize.height);
    var image = robot.createScreenCapture(screenRect);
    d = new Date();
    var tm = d.toString('HH:mm:ss');
    ctr++;
    var file = new java.io.File($screenShotPath +$funcName +$fileName +"Screenshot_" + tm + "_" + ctr + ".png");
    javax.imageio.ImageIO.write(image, "png", file);

    }

Answers

  • OrrinOrrin Members
    Very Nice.
    Although, the final environment is headless in my case. the screenshots is only for debugging.

    I make use of a small function:

    function $ScreenGrab(){
    _set($dt, document.title); // this will take window title
    _focusWindow($dt); // this will set the focus on window
    _takeScreenShot(); // this will take the snapshot
    };

    Think Ill give it a go. Thanx
  • JoshJosh Members
    I just encountered the exact same issue. It's just an annoyance, but a solution would be very welcome.
Sign In or Register to comment.