Below code will help to take entire screen screenshot-

Image MyScreenshot;
BrowserWindow driver;

[TestMethod]
public void CaptureScreenshot()
{

driver = BrowserWindow.Launch(new System.Uri(“https://www.facebook.com”));
driver.TechnologyName = “Web”;
driver.CloseOnPlaybackCleanup = false;
driver.Maximized = true;
MyScreenshot = driver.CaptureImage();
MyScreenshot.Save(@”D:\Windowscreenshot.png”, System.Drawing.Imaging.ImageFormat.Png);

}

If we need to take screenshot of any particular UI object then we can use below code-

Image MyScreenshot;
BrowserWindow driver;

[TestMethod]
public void CaptureScreenshot()
{

driver = BrowserWindow.Launch(new System.Uri(“https://www.facebook.com”));
driver.TechnologyName = “Web”;
driver.CloseOnPlaybackCleanup = false;
driver.Maximized = true;
MyScreenshot = driver.CaptureImage();
MyScreenshot.Save(@”D:\Windowscreenshot.png”, System.Drawing.Imaging.ImageFormat.Png);

HtmlLabel Login = new HtmlLabel(driver);
Login.SearchProperties.Add(“id”, “loginbutton”);

MyScreenshot = Login.CaptureImage();
MyScreenshot.Save(@”D:\Buttoncreenshot.png”, System.Drawing.Imaging.ImageFormat.Png);

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s