Tuesday, May 3, 2011

WebDriver PageFactory.initElements [Why we need]

GooglePage.java
 public class GooglePage extends MyDriver{    
      @FindBy(how = How.NAME, using = "q")  
       private WebElement searchtext;  
      public GooglePage() {  
             super();
             System.out.println("cool stuff!");  
      }  
       public void typeText(){  
           searchtext.sendKeys("abc"); 
      }  
 } 
Testcode:
public class TestCode{
public TestCode(){
GooglePage googlePage = PageFactory.initElements(driver, GooglePage.class); 
//We need to use PageFactory.initElements(driver, GooglePage.class) 
// instead of "new GooglePage() since the GooglePage defines the WebElement using @FindBy. 
    public void testCase1(){
   googlePage.typeText();
   .... 
  }
} 



No comments: