locked
how can i take a screenshot from coded ui while it is running? RRS feed

  • General discussion

  • Hi,

    i am doing a coded ui for  regristration process which is like 7 steps. while playing back my coded ui i need to take an image/screenshot for step4 and tehn continue running to all steps. how can i hand code this case?

    Thanks in advance,

    Kp

    Wednesday, August 15, 2012 9:22 AM

All replies

  • Please refer to CaptureImage API http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.uitesting.uitestcontrol.captureimage.aspx

    If you want to take screenShot you can use UITestControl.Desktop.CaptureImage() to capture image of complete Desktop window

    Thanks


    Aditya Kumar Agrawal (MSFT)

    Wednesday, August 15, 2012 10:45 AM
  • Hi  Aditya,

    Thanks for your reply.

    I have just added the code and my test is passed. When the screenshot will be stored?

    Thanks,

    kp

    Wednesday, August 15, 2012 11:58 AM
  • Hi Adithya,

    Sooper..... Thanks a lot for your help. That really helps. The only hting i am not sure how can i change the location to save my images?

    Thanks,

    Kp

    Wednesday, August 15, 2012 12:11 PM
  • Hi,

    Here is a small piece of code that captures the image of Google Search button. The serach properties of the button object are not mentioned here as they are coming from my UIMap. You can add the search properties to test the code.

            [TestMethod]
            public void CodedUITestMethod1()
            {
                BrowserWindow bWindow = BrowserWindow.Launch("http://google.com");
                HtmlButton button = this.UIMap.UIGoogleWindowsInterneWindow.UIGoogleDocument.UIGoogleSearchButton;
                button.Container = bWindow;
                Image MyImage = button.CaptureImage();
                MyImage.Save(@"C:\MyImageName.bmp");
            }

    As an argument to the Save method you can give the complete path where you want to store the image.

    You can also save it in the desired format (bmp would be quite heavy) by using the ImageFormat property of the Imaging classes as:

    MyImage.Save(@"C:\MyImageName.bmp",  System.Drawing.Imaging.ImageFormat.Jpeg);

    Other formats are also supported.

    Regards,

    Pankaj


    Utility to run CUIT Ordered Tests for multiple iterations (Now with automated result mailing) @ http://cuitbatchrunner.codeplex.com/

    Thursday, August 16, 2012 1:14 AM
  • Hi Pankaj,

    This workd fine for me and it is what i wanted. Thanks for your help.

    Thanks,

    Kp

    Thursday, August 16, 2012 10:44 AM
  • Glad that helped :-)

    Utility to run CUIT Ordered Tests for multiple iterations (Now with automated result mailing) @ http://cuitbatchrunner.codeplex.com/

    Friday, August 17, 2012 1:01 AM