下面列出了怎么用org.openqa.selenium.support.pagefactory.FieldDecorator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Similar to the other "initElements" methods, but takes an {@link FieldDecorator} which is used
* for decorating each of the fields.
*
* @param decorator the decorator to use
* @param page The object to decorate the fields of
*/
public static void initElements(FieldDecorator decorator, Object page) {
Class<?> proxyIn = page.getClass();
while (proxyIn != Object.class) {
proxyFields(decorator, page, proxyIn);
proxyIn = proxyIn.getSuperclass();
}
}
private static void proxyFields(FieldDecorator decorator, Object page, Class<?> proxyIn) {
Field[] fields = proxyIn.getDeclaredFields();
for (Field field : fields) {
Object value = decorator.decorate(page.getClass().getClassLoader(), field);
if (value != null) {
try {
field.setAccessible(true);
field.set(page, value);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}