title: Mocking complex objects like selenium webdriver with Moq
body: <p>I'm trying to Mock the selenium web driver.  I use the following code:</p>
  
  <pre><code>    public  IWebDriver GetMockDriver()
      {
          this.Mock = new Mock&lt;IWebDriver&gt;();
          return (IWebDriver)this.Mock.Object;            
      }
  </code></pre>
  
  <p>If I'm just accessing driver properties, everything is fine, but when I try to access an object that is part of Driver, eg:</p>
  
  <pre><code>             driver.Manage().Window.Maximize();
  </code></pre>
  
  <p>I get back a System.NullReferenceException.</p>
  
  <p>I don't really want/need to track calls that were made to the Mock object, it's more that I want something that implements iWebDriver so I can write my selenium tests using TDD and not having to actually create an instance of a real web driver each time.</p>