-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Java. Page Factory enhancement. #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java. Page Factory enhancement. #415
Conversation
Hi I made some similar change at selophane. How ever the last days I found a use case where it's necessary to have the webdriver. So I changed it back. The background is, that if you create something like a button it would be great if there was a wait till a click on the button is finished. Therefor you need a WebDriver. |
@opensource21 //excessive actions
WidgetObject wo = new WidgetObject(/*refToElement*/);
DefaultFieldDecorator dfd = new DefaultFieldDecorator(
new DefaultElementLocatorFactory(refToElement));
//excessive actions are finished
PageFactory.initElements(dfd, wo); This should be usefull for cases and apps/services like... Google (just for example). The search form is the page by itself and the widget inside some element at Drive or GMail page. So if it is not necessary to made up and implement users customized decorator then this widget object will be created and populated in one action. |
@TikhomirovSergey Yes you are right! Sorry for the trouble and thanks for the hints. |
706caca
to
38a1229
Compare
57b01a0
to
2e144a8
Compare
there appears to be an issue with this travis build. no ruby changes were detected, yet still failed. @lukeis? any idea |
I'm not sure why it ran in the first place, but it looks like I might have changed something in the specs. I'll take a look. |
4a314b8
to
c8a8e13
Compare
- Ability to use not only Webdriver to populate page object fields via method public static <T> T initElements(SearchContext context, Class<T> pageClassToProxy). This change was done in order to simplify page object instantiation and population when there is the necessity to implement something that describes widget or repeatable element set nested in a root element. - the additional checking of field modifiers before it will be populated. Field that is going to be filled should not be static and final. I found these issues some time ago. I tried to implement page object with final fields that weren't annotated by @findby's. Also I found that it tries to set proxy-WebElement as a value of a static WebElement-field. Actually I think that both issues are minor but it would be good if whey were fixed.
fb266f6
to
d079a12
Compare
…page_factory_enhancements Conflicts: java/client/src/org/openqa/selenium/support/pagefactory/internal/LocatingElementHandler.java
Also: - PageFactory: some redundant code was removed
@mykola-mokhnach @shs96c Also I don't know why tests are not passed |
if (!parameterClazz.isAssignableFrom(context.getClass())) | ||
continue; | ||
c.setAccessible(true); | ||
return (T) c.newInstance(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pageClassToProxy.cast should address unchecked class cast warning
} catch (NoSuchMethodException e) { | ||
return pageClassToProxy.newInstance(); | ||
Constructor<?>[] availableConstructors = pageClassToProxy.getDeclaredConstructors(); | ||
for (Constructor<?> c: availableConstructors){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a space is missing
|
||
Class<?>[] parameterTypes = c.getParameterTypes(); | ||
if (parameterTypes.length != 1) | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a good practice to always enclose condition block into curly brackets, even if there is only one operator
public Object invoke(Object object, Method method, Object[] objects) throws Throwable { | ||
|
||
if ("toString".equals(method.getName())) { | ||
return "Proxy element for: " + locator.toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.format might be a better choice here
- some code style issues were fixed out
@mykola-mokhnach @shs96c I made the update. Please look at this once again. |
Field[] fields = proxyIn.getDeclaredFields(); | ||
for (Field field : fields) { | ||
int modifiers = field.getModifiers(); | ||
if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curly brackets would be good here as well
continue; | ||
} | ||
c.setAccessible(true); | ||
return (T) c.newInstance(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did pageClassToProxy.cast fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. I can improve it later.
- some code style issues were fixed out
|
Apologies for the poor handling of this PR. In general, we are discouraging the use of |
This change was done in order to simplify page object instantiation and population when there is the necessity to implement something that describes widget or repeatable element set nested in a root element. So if there is a class with constructors like follows:
and there is no necessity to implement customized decorating engines then it is possible to populete its WebElement-fields this way (only one step):
Field that is going to be filled should not be static and final. I found these issues some time ago. I tried to implement page object with final fields that weren't annotated by @findby's. Also I found that it tries to set proxy-WebElement as a value of a static WebElement-field. In both cases I caught IllegalModifierException. Actually I think that both issues are minor but it would be good if whey were fixed.
This change is