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.

How can I get the PID of a browser window during a test?

jkbjkb Members
edited January 2013 in Sahi - Open Source
I am running Sahi in batch mode and my scripts are designed to take screenshots at certain points. When I use the Sahi takeScreenShot() function (even if I use focusWindow()) I am getting screenshots of the foremost test only. I have a program that can take screenshots of hidden windows if I have the PID, but I can't seem to figure out how to get the PID of a browser window mid-test. Does anyone know how to do this?

Answers

  • narayannarayan Administrators
    It should be possible to get it. Let me check. Which tool are you suggesting that takes screenshots from PIDs?
  • jkbjkb Members
    One of my friends developed a tool that can take background screenshots from a PID. It's just a small executable that can run in the command line and output to a file.
  • narayannarayan Administrators
    Wow, sounds very useful! Let me see how the PID can be exposed.
    Would he be willing to opensource it or share it?
    Thanks
  • sivasiva Members
    edited January 2013
    Hi Narayan,

    we can take screenshot of running browser in background even focus on another window, without using "_focuswindow " technique

    this feature i have seen in selenium, below is the code which i have seen in selenium

    any how selenium is open source, we can get the source code, by seeing that we can come to know how they have developed this technique

    if possible, pls implement the same technique

    
    public void captureScreen(WebDriver driver) {
    		
    	File tmpScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); 
    	try {
    		FileUtils.copyFile(tmpScreenshot, new File("C:\\imagename.jpg"));
    	} catch (IOException e) {
    		e.printStackTrace();
    	} 
    }
    
    
  • narayannarayan Administrators
    I believe the screenshot only works in Firefox for webdriver.
    Jkb's friend's solution sounds more interesting.
  • jkbjkb Members
    edited February 2013
    Any update on getting the PID of the browser window currently being tested? Not sure about opening it up since we're using it in-house for product testing, but I can check.
  • I think it will be difficult to find a solution that is platform independent.

    The following URL contains C# code to do something like this under windows:
    http://stackoverflow.com/questions/242570/copying-content-from-a-hidden-or-clipped-window-in-xp

    However, since it's C# code, and SAHI is built using java, you'd have to use java native interface to invoke it, so it's probably not what you're looking for.
Sign In or Register to comment.