Taking Screen Shot of a page By using selenium Webdriver With NUnit and C#.Net in Visual Studio-2012.
- create / select a Unit Test project from existing template under test option.
- Remove the name space - using Microsoft.VisualStudio.TestTools.UnitTesting; from your class/test.
- Add the name space in your test/class using NUnit.Framework;
- Add the name space in your test/class using OpenQA.Selenium;
- Add the name space in your test/class using OpenQA.Selenium.Chrome;
- Add the name space in your test/class using OpenQA.Selenium.Support.UI;
- Add the reference of System.Drawing by right click on References of your project.
- Add the name space in your test/class using OpenQA.Selenium;s
Below is the code to take the screen shot of Facebook Home page.
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;
using System.IO;
using System.Collections;
using System.Drawing.Imaging;
namespace FacebookRegistrationUsingC_Sharp
{
[TestFixture]
public class ScreenShot
{
IWebDriver driver = null;
IWebElement element = null;
[SetUp]
public void SetUp()
{
driver = new ChromeDriver("G:\\Selenium_Csharp\\Jar\\chromedriver_win32");
driver.Navigate().GoToUrl("https://www.Facebook.com");
driver.Manage().Window.Maximize();
}
[Test]
public void TestScreenShot()
{
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile("e:\\AvinashPande.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
[TearDown]
public void TearDown()
{
driver = null;
element = null;
}
}
}
Here the chance to get an error: A generic error occurred in GDI+.
following Precaution to needs to be taken:
- You should not store the file on a drive on which operating system has been already installed.
- you should give the name other than the file which has been present already in that folder in which current file in storing .
See Also Below Links:
click
No comments:
Post a Comment