title: how to decorate the selenium WebDriver class?
body: <p>I want to add some functionality to the WebDriver class. I've tried to use the pattern decorator. I think it's the best in this situation for add functionalities to WebDriver class without change it.</p>
  
  <p>This my code : </p>
  
  <pre><code>public abstract class DriverExtends extends RemoteWebDriver {
  
     protected Log logger = LogFactory.getLog(getClass());
     protected RemoteWebDriver rwd;
     protected final int SLEEP = 10;
  
     public DriverExtends(RemoteWebDriver driver) {
           rwd = driver;
     }
  
     /**
     * Determines whether an element is present on the page.
     * @param by The search item.
     * @param log if true, logs a message in the log in the absence of the element. False otherwise.
     * @return true if the element is present, false otherwise.
     */
     public boolean isElementPresent(By by, boolean log) {
           try{
                  (new WebDriverWait(rwd, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(by));
                  return true;
           } catch(NoSuchElementException e) {
                  if(log) {
                         logger.warn("L'élément est absent : "+ e.getMessage());
                  }
                  return false;
           }
     }
  
     /**
     * Allows click on a submenu hide default.
     * @param by The link to click. Example (By.linkText ("Search"));
     */
     public void loadMenu(By by) {
           rwd.findElement(By.id("bouton_menu")).click();
           ((JavascriptExecutor)rwd).executeScript("$(\".menu2\").show()");
           rwd.findElement(by).click();
     }
  }
  </code></pre>
  
  <p>FirefoxDriverExtends.class</p>
  
  <pre><code>public class FirefoxDriverExtends extends DriverExtends {
  
         public FirefoxDriverExtends (FirefoxDriver driver) {
               super(driver);
         }
  
  }
  </code></pre>
  
  <p>My test case : </p>
  
  <pre><code>public class CreatePeople extends DefaultTestCaseWithParam&lt;PersonLoaded&gt; {
  
     @Override
     public boolean test(DriverExtends driver, PersonLoaded p) throws InterruptedException, TimeoutException {
           System.out.println("CreatePeople.test() - " + p);
           driver.loadMenu(By.linkText("Recherche"));
           (new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("idform:nom_input"))).sendKeys(p.getPrenom());
           driver.findElement(By.id("idform:datenaiss_input")).sendKeys(p.getDateNaiss());
           new Select(driver.findElement(By.id("idform:paysRR"))).selectByValue("Danemark");
           (new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.elementToBeClickable(By.id("idform:villeRR"))).sendKeys("COPENHAGUE");
           driver.findElement(By.id("idform:rechercherRes")).click();
           (new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("idform:creerRes"))).click();
           new Select((new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("People:selecGestio")))).selectByVisibleText("SELENIUM-UN SELENIUM");
           driver.findElement(By.id("People:adresse")).sendKeys("01 rue du test");
           driver.findElement(By.id("People:telT")).sendKeys("0102030405");
           new Select(driver.findElement(By.id("People:posS"))).selectByVisibleText("someText");
           new Select((new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("People:categAD")))).selectByVisibleText("someText");
           new Select(driver.findElement(By.id("People:autoEmploi"))).selectByVisibleText("Armée de l'air");
           new Select((new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("People:categP")))).selectByVisibleText("someText");
           new Select(driver.findElement(By.id("People:precMili"))).selectByVisibleText("De carrière");
           new Select((new WebDriverWait(driver, SLEEP)).until(ExpectedConditions.presenceOfElementLocated(By.id("People:categH")))).selectByVisibleText("someText");
           driver.findElement(By.id("id=People:date_debut-service_input")).click();
           driver.findElement(By.linkText("1")).click();
           return true;
     }
  }
  </code></pre>
  
  <p>And this the error i get : </p>
  
  <pre><code>uild info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
  System info: host: 'UCFC4DD43D730B', ip: '36.138.1.237', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
  Driver info: driver.version: RemoteWebDriver
  org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
  Build info: version: '2.41.0', revision: '3192d8a6c4449dc285928ba024779344f5423c58', time: '2014-03-27 11:29:39'
  System info: host: 'UCFC4DD43D730B', ip: '36.138.1.237', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_25'
  Driver info: driver.version: RemoteWebDriver
         at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:589)
  -Start of the timer for "Test 4 - selenium.tests.testsuites.TestSuitePeople.testCreatePeople"
  09/04/2014 15:10:00 (DbUnit.java:173)  [INFO ]: Désactivation des contraintes
         at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:610)
         at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:320)
         at selenium.utils.jUnit.SeleniumTestWatcher.failed(SeleniumTestWatcher.java:68)
         at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:51)
         at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
         at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
         at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
         at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
         at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
         at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
         at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
         at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  Caused by: java.lang.NullPointerException
         at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:568)
         ... 22 more
  </code></pre>
  
  <p>It's the first time i use the decorator pattern. So what i've missed? :)</p>