Road to screen recording in webdriver with C#

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.
using Microsoft.Expression.Encoder.ScreenCapture;
5. Create object of ScreenCaptureJob in your test.
ScreenCaptureJob scj = new ScreenCaptureJob();
6. Sample code for screen capturing
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();
       }

   }
      
}
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

8 comments:

  1. similar post in webdriver java for screen recording

    http://roadtoautomation.blogspot.in/2013/03/screen-recording-video-of-java-webdiver.html

    ReplyDelete
  2. Great post. I have a question about the format in which the movie is saved. It is said that it is .wmv. but Windows Media Player can't open the movie as the codec missing message is appearing. The other player is throwing the following error:
    No such interface supported [0x80004002]

    [FileInfo]
    FileExtension=.wmv
    FileSize=581128
    FourCC=MTS2
    AudioTag=0000

    [FilterRenderError]
    CLSID="{187463A0-5BB7-11D3-ACBE-0080C75E246E}"
    Filter="C:\Users\xxxxxxxxx\Desktop\Recording - 27-01-2016-11-53-46.wmv"
    Pin="Raw Video 0"
    Major Type: Video - Sub Type: Unknown Format: VideoInfo MTS2 1920X1080, 24

    Could you please help with this?

    ReplyDelete
  3. @Mat z: try to save as a *.xesc file instead, that did the trick for me.

    ReplyDelete
  4. @Mat z

    Use *.xesc extension instead: this did the trick for me.

    ReplyDelete
  5. GUys , I set everything , and I am not getting any error , or anything else. everything is working smoothly but there is no Recorded file in path , or anywhere else. Does anyone has any idea about my problem?

    ReplyDelete
  6. Thanks for the post, how do you make it record the focused screen when you have multiple monitors?

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution