Last couple of days, I am searching screen recording by using webdriver with C# similar to “Monte Media Library” in java and finally I got the solution. Here, I am posting my finding so that it can help others.
For screen capturing Microsoft provide” Microsoft Expression Encoder 4” which can be download and install from link “http://www.microsoft.com/en-in/download/confirmation.aspx?id=27870”
Default installation directory is “C:\Program Files\Microsoft Expression”.
Steps to create and run webdriver test.
1. You need to make sure that you have setup all required dll for of webdriver and Nunit.
2. Download and install”Microsoft Expression Encoder 4” from above mentioned url.
3. Add “Microsoft.Expression.Encoder.dll” from “C:\Program Files\Microsoft Expression\Encoder 4\SDK” folder to your webdriver project.
4. You need to add import below class in your test.
5. Create object of ScreenCaptureJob in your test.
6. Sample code for screen capturing
7. Set file name and path in “scj.OutputScreenCaptureFileName = @"C:\ScreenRecording.wmv"; “
8. Build and run above code using Nunit , after execution a video file will generate at mentioned location and file
Default installation directory is “C:\Program Files\Microsoft Expression”.
Steps to create and run webdriver test.
1. You need to make sure that you have setup all required dll for of webdriver and Nunit.
2. Download and install”Microsoft Expression Encoder 4” from above mentioned url.
3. Add “Microsoft.Expression.Encoder.dll” from “C:\Program Files\Microsoft Expression\Encoder 4\SDK” folder to your webdriver project.
4. You need to add import below class in your test.
using Microsoft.Expression.Encoder.ScreenCapture;
ScreenCaptureJob scj = new ScreenCaptureJob();
using NUnit.Framework;
using OpenQA.Selenium;
using Microsoft.Expression.Encoder.ScreenCapture;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace ScreenRecording.TestScript
{
[TestFixture]
public class ScreenRecording
{
IWebDriver driver;
ScreenCaptureJob scj;
[SetUp]
public void TestSetup()
{
// Create a instance of ScreenCaptureJob
scj = new ScreenCaptureJob();
// Specify the path & file name in which you want to save
scj.OutputScreenCaptureFileName = @"C:\ScreenRecording.wmv";
// Start the Screen Capture Job
scj.Start();
driver = new FirefoxDriver();
}
[TestCase]
public void TestGoogleSearch()
{
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("testing");
Assert.AreEqual("testing - Google Search", driver.Title);
}
[TearDown]
public void TestCleanUp()
{
//Close the Browser
driver.Close();
//Stop the Screen Captureing
scj.Stop();
}
}
}
8. Build and run above code using Nunit , after execution a video file will generate at mentioned location and file


0 comments:
Post a Comment
Note: only a member of this blog may post a comment.