title: How to execute a page object programme in eclipse?
body: <p>I am basically trying to run a sample page object framework in java in Selenium .I have tried to run some sample classes given by some of the sites and forums. But for some reason, it doesnt seem to work. I dont know if I am missing out anything. Please help.  Thank You</p>
  
  <p>I have tried these examples - 
  <a href="https://weblogs.java.net/blog/johnsmart/archive/2010/08/09/selenium-2web-driver-land-where-page-objects-are-king" rel="nofollow">https://weblogs.java.net/blog/johnsmart/archive/2010/08/09/selenium-2web-driver-land-where-page-objects-are-king</a> </p>
  
  <p><a href="http://www.wakaleo.com/blog/selenium-2-webdriver-quick-tips-page-object-navigation-strategies" rel="nofollow">http://www.wakaleo.com/blog/selenium-2-webdriver-quick-tips-page-object-navigation-strategies</a></p>
  
  <pre><code>    package google;
  
      import org.junit.After;
      import org.junit.Before;
      import org.openqa.selenium.chrome.ChromeDriver;
      import org.openqa.selenium.support.PageFactory;
      import org.testng.annotations.Test;
  
      public class WhenAUserSearchesOnGoogle {
  
  private GoogleSearchPage page;
  
  @Before
  public void openTheBrowser() {
      page = PageFactory.initElements(new ChromeDriver(), GoogleSearchPage.class);
      page.open("http://google.co.nz/");
   }
  
  @After
  public void closeTheBrowser() {
      page.close();
  }
  
  @Test
  public void whenTheUserSearchesForCatsTheResultPageTitleShouldContainCats() {
      page.searchFor("cats");
      //assertThat(page.getTitle(), containsString("cats") );
  }   
      }
  </code></pre>
  
  <p>Above is the page factory class that I am using.</p>
  
  <p>Following is the Page object.</p>
  
  <pre><code>    package google;
      import org.openqa.selenium.WebDriver;
      import org.openqa.selenium.WebElement;
      //import org.openqa.selenium.firefox.FirefoxDriver;
  
  
  
      public class GoogleSearchPage {
  
  protected WebDriver driver;
  
  private WebElement q;   
  
  private WebElement btnG;
  
  public GoogleSearchPage(WebDriver driver) {
      this.driver = driver;
  }
  
  public void open(String url) {
      driver.get(url);
  }
  
  public void close() {
      driver.quit();
  }
  
  public String getTitle() {
      return driver.getTitle();
  }
  
  public void searchFor(String searchTerm) {
      q.sendKeys(searchTerm);
      btnG.click();
  }
  
  public void typeSearchTerm(String searchTerm) {
      q.sendKeys(searchTerm);
  }
  
  public void clickOnSearch() {
      btnG.click();
  }
      }
  </code></pre>
  
  <p>The stack trace says
  FAILED: whenTheUserSearchesForCatsTheResultPageTitleShouldContainCats</p>