|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.openqa.selenium.support.PageFactory
public class PageFactory
Factory class to make using Page Objects simpler and easier.
http://code.google.com/p/webdriver/wiki/PageObjects
Constructor Summary | |
---|---|
PageFactory()
|
Method Summary | ||
---|---|---|
static void |
initElements(ElementLocatorFactory factory,
java.lang.Object page)
Similar to the other "initElements" methods, but takes an ElementLocatorFactory which is used for providing the
mechanism for fniding elements. |
|
static void |
initElements(FieldDecorator decorator,
java.lang.Object page)
Similar to the other "initElements" methods, but takes an FieldDecorator which is used for decorating each of the fields. |
|
static
|
initElements(WebDriver driver,
java.lang.Class<T> pageClassToProxy)
Instantiate an instance of the given class, and set a lazy proxy for each of the WebElement fields that have been declared, assuming that the field name is also the HTML element's "id" or "name". |
|
static void |
initElements(WebDriver driver,
java.lang.Object page)
As initElements(org.openqa.selenium.WebDriver, Class)
but will only replace the fields of an already instantiated Page Object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PageFactory()
Method Detail |
---|
public static <T> T initElements(WebDriver driver, java.lang.Class<T> pageClassToProxy)
public class Page {
private WebElement submit;
}
there will be an element that can be located using the xpath expression
"//*[@id='submit']" or "//*[@name='submit']"
Any WebElement in the class will be proxied as a WebElement. You will
not be able to cast this as a RenderedWebElement. If you want to access
the field as a RenderedWebElement, you should declare the field as a
RenderedWebElement, i.e.
public class Page {
private RenderedWebElement submit;
}
By default, the element is looked up each and every time a method is called
upon it. To change this behaviour, simply annnotate the field with the
@org.openqa.selenium.support.CacheLookup
. To change how the
element is located, use the @org.openqa.selenium.support.FindBy
annotation.
This method will attempt to instantiate the class given to it, preferably
using a constructor which takes a WebDriver instance as its only argument
or falling back on a no-arg constructor. An exception will be thrown if
the class cannot be instantiated.
driver
- The driver that will be used to look up the elementspageClassToProxy
- A class which will be initialised.
@org.openqa.selenium.support.FindBy
,
@org.openqa.selenium.support.CacheLookup
public static void initElements(WebDriver driver, java.lang.Object page)
initElements(org.openqa.selenium.WebDriver, Class)
but will only replace the fields of an already instantiated Page Object.
driver
- The driver that will be used to look up the elementspage
- The object with WebElement fields that should be proxied.public static void initElements(ElementLocatorFactory factory, java.lang.Object page)
ElementLocatorFactory
which is used for providing the
mechanism for fniding elements. If the ElementLocatorFactory returns
null then the field won't be decorated.
factory
- The factory to usepage
- The object to decorate the fields ofpublic static void initElements(FieldDecorator decorator, java.lang.Object page)
FieldDecorator
which is used for decorating each of the fields.
decorator
- the decorator to usepage
- The object to decorate the fields of
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |