Closed mihaibuba closed 2 years ago
Hi,
These would more be questions for the Google Groups (as it is not an actionable defect).
If you have several identical objects, can you not find them using nested searches?
Hello,
Well, of course it would be possible, but I was hoping to avoid that. Because the DOM is very complex I was hoping to be able to split into sections, and still be able to use @FindBy to declare objects that implement the WebElementFacade and/or extend WebElementImpl, and which wrap the behaviour of each component: https://material.angular.io/components
Edit: I applied to join the following google group, I will try asking the question again there, so you can close this if you wish. Thank you. https://groups.google.com/forum/#!forum/thucydides-users
@mihaibuba Looks like you are looking for Panel (Block) implementation. And as I know Serenity doesn't support these feature out of the box.
So you may implement it by our own or use ready libraries, for example http://htmlelements.qatools.ru
Htmlelements allows you to add panels (blocks) support as well as save backward compatibility with your custom logic around native selenium @FindBy
. To integrate all these stuff to Serenity I suppose it will be enough to pass HtmlElementDecorator
into PageFactory
in subclass of Serenity PageObject
.
There is a drawback related to described solution. You will lose some Serenity functionality. For example jQuery selectors or WebElementFacade
won't be usable, use native WebElement
instead.
@Invictum Thank you for providing me the link, that actually looks very nice, unfortunately it doesn't work. So the problem is I cannot do this: public SearchPage(WebDriver driver) { PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this); } But because Serenity is loading the objects eagerly, it means that it's actually attempting to initialize the elements before the page has loaded, specifically before I get to call the page.open() and have it actually get WebDriver to get the page.
Edit: BTW, your answer was exactly right, that is what I was searching for, just that it doesn't work. I am using something similar to your elements (https://github.com/yandex-qatools/htmlelements/tree/master/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element), but this looks much nicer. I am currently using https://github.com/elisarver/selophane, but it's cumbersome, as it requires an @ImplementBy annotation.
Edit: @wakaleo so as an actionable defect aka, feature request: Would it be possible to use Serenity with a custom Object Factory such as the ones described above?
@mihaibuba
Well, actually Htmlelement inits wrapped elements as lazy proxies the same as Serenity and native Selenium do. So it is possible to invoke open()
method and page elements will be inited on first attempt to invoke their methods.
However, to use Serenity open page facility, page should be constructed as in PageObject
class. So in one hand we need to construct pages in Serenity style, but in other hand we need inject htmlelements factory. It is possible to achieve it via
public SearchPage(WebDriver driver) {
super(driver);
PageFactory.initElements(new HtmlElementDecorator(new HtmlElementLocatorFactory(driver)), this);
}
But unfortunately, Serenity and Htmlelements factories are unable to work together. It is because different init mechanics they try to apply to the same elements inside page.
Hello,
I am looking into using implementing the Serenity Framework into our project, and so far I find it awesome. One think I could not figure out is how to set a search context for the ElementLocatorFactory.
Looking trough the code, I did find in ElementLocaltorFacotrySelector.java this piece of code, but it appears to be called from only one place as: return this.getLocatorFor(driver, driver); public ElementLocatorFactory getLocatorFor(SearchContext searchContext, WebDriver driver)
I would really need it, as we have several identical objects in the same object, in different sections of the page. Additionally would it be possible to use a "custom" element factory, as we have several extensions to the default ones?
Thank you.