One of the nice things that you can do while running your Coded UI tests, is capturing screenshots of the executed actions.
Doing this is easy, to capture a screenshot of the whole screen, execute the following code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BrowserWindow browserWindow = BrowserWindow.Launch("http://google.com"); | |
HtmlButton button = this.UIMap.UIGoogleWindowsInterneWindow.UIGoogleDocument.UIGoogleSearchButton; | |
button.Container = browserWindow; | |
Image MyImage = UITestControl.Desktop.CaptureImage(); | |
MyImage.Save(@"C:\desktopscreenshot.jpg",System.Drawing.Imaging.ImageFormat.Jpeg); | |
If you only want to take a screenshot of a specific UI element, call the CaptureImage method on the element:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BrowserWindow browserWindow = BrowserWindow.Launch("http://google.com"); | |
HtmlButton button = this.UIMap.UIGoogleWindowsInterneWindow.UIGoogleDocument.UIGoogleSearchButton; | |
button.Container = browserWindow; | |
Image MyImage = button.CaptureImage(); | |
MyImage.Save(@"C:\buttonscreenshot.jpg",System.Drawing.Imaging.ImageFormat.Jpeg); |