1

I am automating tests of a GUI application similar to calculator. I am using Java and AutoIt for implementing the test cases. I need to take screenshot on failure.

I have tried taking screenshot using BufferedImage, but it takes the screenshot of the complete page. I need to take the screenshot of the application excluding the background. For Ex:- like taking snapshot using WebDriver. Is is possible to achieve this?

  • I removed the Selenium tags, because your question states you are not using it and Selenium cannot take screenshots of the full application. Are you also using Selenium and are you testing a web-application? Its not very clear what you are doing and why you want to take a screenshot of the windows. Adding this information might help get you better answers. – Niels van Reijmersdal Mar 25 '16 at 8:53
0

Since you are using AutoIt you can use the _ScreenCapture_CaptureWnd function to take a screenshot of a single window, example code can be found here: https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_CaptureWnd.htm

Since you are using Java you can also use Robot to take a screenshot of a part of the screen, but you need to specify the area manual. For some code example look here: https://stackoverflow.com/questions/58305/is-there-a-way-to-take-a-screenshot-using-java-and-save-it-to-some-sort-of-image

0

Yes, this is simple:

public void getscreenshot() throws Exception 
{
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    //The below method will save the screen shot in d drive with name "screenshot.png"
    FileUtils.copyFile(scrFile, new File("D:\\screenshot.png"));
} 

Use this method for taking a screenshot.

  • This will screenshot the entire page. Not a good answer. – FDM Feb 24 '16 at 7:33
0

Another option would be to augment the RemoteWebDriver to give it all of the interfaces its proxied driver implements:

WebDriver driver = new RemoteWebDriver(
    new URL("http://localhost:4444/wd/hub"), 
    DesiredCapabilities.firefox());

WebDriver augmentedDriver = new Augmenter().augment(driver); 
((TakesScreenshot)augmentedDriver).getScreenshotAs(...);
  • This will screenshot the entire page. Not a good answer. – FDM Feb 24 '16 at 7:33
  • it will take the screenshot for entire page and also its applicable only for web based applications. The scenario here is the GUI application – Ajmal Feb 24 '16 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.