how to use AjaxElementLocatorFactory with page objects and PageFactory

6749 views
Skip to first unread message

urbanblock

unread,
Jun 11, 2010, 4:27:10 AM6/11/10
to webdriver
Hi
Is anyone able to provide an example of a Test and PageObject using
the AjaxElementLocatorFactory with the PageFactory. I have checked out
the various posts on AjaxElementLocatorFactory, but I haven't been
able to get it working, as the examples have been too brief for me.

Regards,
Dylan
Message has been deleted

sqa tester

unread,
Jun 14, 2010, 1:49:20 PM6/14/10
to webdriver
In my case, I only use the AjaxElementLocatorFactory in the
constructor of my page objects.

Please see example below. Hopefully it will give you some idea of the
usage.

/***
* This is the parent class where shared services are available.
***/
public abstract class AbstractParentPage {

public int DRIVER_WAIT = 30; // 30 seconds
/***
* Constructor
* @param driver an instance of WebDriver
*/
public AbstractAIPage(WebDriver driver){
ElementLocatorFactory finder = new
AjaxElementLocatorFactory(driver,
DRIVER_WAIT);
PageFactory.initElements(finder, this);
this.driver = driver;
}

------ Add services accessible to all pages here ----

}

/***
* This is the login page
***/
public class LoginPage extends AbstractParentPage{
@FindBy(id = "username")
private WebElement usernameTextBox;
@FindBy(id = "password")
private WebElement passwordTextBox;
/***
* constructor
* @param driver an instance of WebDriver
*/
public LoginPage(WebDriver driver) {
super(driver);
ElementLocatorFactory finder = new
AjaxElementLocatorFactory(driver, DRIVER_WAIT);
PageFactory.initElements(finder, this);
this.driver = driver;
}

public HomePage login(String username, String password){
usernameTextBox.clear();
usernameTextBox.sendKeys(username);
passwordTextBox.clear();
passwordTextBox.sendKeys(password);
passwordTextBox.submit();
return new HomePage(driver);

}

}

------------------------------------------------------------------

Test Code:

WebDriver driver = new FirefoxDriver();
LoginPage loginPage = new LoginPage(driver);
HomePage homePage = loginPage.login("username","password");

In test code, only services in page objects are accessed. With the use
of AjaxElementLocatorFactory in page object constructor, webdriver
waits for a web element the specified time in DRIVER_WAIT (30 seconds
in the example above) before timing out and throwing No Such Element
Found exception.

urbanblock

unread,
Jun 17, 2010, 2:21:52 AM6/17/10
to webdriver
Hi
Thanks, that is great. It has made it very clear for me.

Regards,
Dylan



On Jun 15, 5:49 am, sqa tester <thesqates...@gmail.com> wrote:
> In my case, I only use theAjaxElementLocatorFactoryin the
>                 ElementLocatorFactory finder =  newAjaxElementLocatorFactory(driver, DRIVER_WAIT);
>             PageFactory.initElements(finder, this);
>             this.driver = driver;
>         }
>
>         public HomePage login(String username, String password){
>              usernameTextBox.clear();
>              usernameTextBox.sendKeys(username);
>              passwordTextBox.clear();
>              passwordTextBox.sendKeys(password);
>              passwordTextBox.submit();
>              return new HomePage(driver);
>
>         }
>
> }
>
> ------------------------------------------------------------------
>
> Test Code:
>
> WebDriver driver = new FirefoxDriver();
> LoginPage loginPage = new LoginPage(driver);
> HomePage homePage = loginPage.login("username","password");
>
> In test code, only services in page objects are accessed. With the use
> ofAjaxElementLocatorFactoryin page object constructor, webdriver
> waits for a web element the specified time in DRIVER_WAIT (30 seconds
> in the example above) before timing out and throwing No Such Element
> Found exception.
>
> On Jun 11, 1:27 am, urbanblock <dylan.hazlehu...@gmail.com> wrote:
>
>
>
> > Hi
> > Is anyone able to provide an example of a Test and PageObject using
> > theAjaxElementLocatorFactorywith the PageFactory. I have checked out
> > the various posts onAjaxElementLocatorFactory, but I haven't been
Reply all
Reply to author
Forward
0 new messages